getData('product')) { $matches = $this->_getMatchesHelper()->findByProductId($product->getId()); /** @var $match Orange35_ImageConstructor_Model_Matches */ foreach ($matches as $match) { $match->delete(); } } $this->_getImageHelper()->flushImagesCache(); return $this; } public function addCustomLayoutConfigHandle(Varien_Event_Observer $observer) { if(!Mage::getStoreConfig("colorpicker_section/image_constructor_tools/module_enable")){ return false; } /** @var $layout Mage_Core_Model_Layout */ $event = $observer->getEvent(); $controllerAction = $event->getAction(); $layout = $event->getLayout(); if ($controllerAction && $layout && $controllerAction instanceof Mage_Adminhtml_System_ConfigController) { if ($controllerAction->getRequest()->getParam('section') == 'colorpicker_section') { $layout->getUpdate()->addHandle('adminhtml_system_config_edit_orange35_imageconstructor'); } } return $this; } protected function _upload($storeDir, $fieldName, $valueId) { return $this->_getImageHelper()->upload($storeDir, $fieldName, $valueId); } public function onSaveProduct(Varien_Event_Observer $observer) { if(!Mage::getStoreConfig("colorpicker_section/image_constructor_tools/module_enable")){ return false; } if ($product = $observer->getData('product')) { $productId = $product->getId(); $post = $this->_getRequest()->getPost('delete_image'); $matches = $this->_getMatchesHelper()->getImagesUrlByProductId($product->getId()); $matches = $matches['matches']; if (isset($post)){ $this->_getMatchesHelper()->deleteImages($post); } $customOptions = $product->getOptions(); $this->_getImageHelper()->flushImagesCache(); foreach ($customOptions as $option) { foreach ($option->getValues() as $value) { $image = $this->_upload( DS . $productId . DS . $option->getId(), 'option_file_' . $productId . '_' . $option->getId() . '_' . $value->getId(), $value->getId() ); if ($image != false) { $match = $this->_getMatchesModel(); if(isset($matches[$option->getId()][$value->getId()])){ $match->load($matches[$option->getId()][$value->getId()]) ->delete(); } $match->setData(array( 'value_id' => $value->getId(), 'option_id' => $option->getId(), 'product_id' => $productId, 'image' => $image['name'], )) ->save(); } } } } return $this; } protected function _getRequest() { return Mage::app()->getRequest(); } }