getRequest()->getPost()) { try { /** @var $model Mage_SalesRule_Model_Rule */ $model = Mage::getModel('salesrule/rule'); Mage::dispatchEvent( 'adminhtml_controller_salesrule_prepare_save', array('request' => $this->getRequest())); $data = $this->getRequest()->getPost(); $data = $this->_filterDates($data, array('from_date', 'to_date')); $id = $this->getRequest()->getParam('rule_id'); if ($id) { $model->load($id); if ($id != $model->getId()) { Mage::throwException(Mage::helper('salesrule')->__('Wrong rule specified.')); } } $session = Mage::getSingleton('adminhtml/session'); $validateResult = $model->validateData(new Varien_Object($data)); if ($validateResult !== true) { foreach($validateResult as $errorMessage) { $session->addError($errorMessage); } $session->setPageData($data); $this->_redirect('*/*/edit', array('id'=>$model->getId())); return; } if (isset($data['simple_action']) && $data['simple_action'] == 'by_percent' && isset($data['discount_amount'])) { $data['discount_amount'] = min(100,$data['discount_amount']); } if (isset($data['rule']['conditions'])) { $data['conditions'] = $data['rule']['conditions']; } if (isset($data['rule']['actions'])) { $data['actions'] = $data['rule']['actions']; } unset($data['rule']); $model->loadPost($data); $useAutoGeneration = (int)!empty($data['use_auto_generation']); $model->setUseAutoGeneration($useAutoGeneration); $session->setPageData($model->getData()); $model->save(); /* Accumulative update */ if ($data['simple_action'] == 'Accumulative Promotion') { $this->saveAccumulative($model, $data); } /****/ $session->addSuccess(Mage::helper('salesrule')->__('The rule has been saved.')); $session->setPageData(false); if ($this->getRequest()->getParam('back')) { $this->_redirect('*/*/edit', array('id' => $model->getId())); return; } $this->_redirect('*/*/'); return; } catch (Mage_Core_Exception $e) { $this->_getSession()->addError($e->getMessage()); $id = (int)$this->getRequest()->getParam('rule_id'); if (!empty($id)) { $this->_redirect('*/*/edit', array('id' => $id)); } else { $this->_redirect('*/*/new'); } return; } catch (Exception $e) { $this->_getSession()->addError( Mage::helper('catalogrule')->__('An error occurred while saving the rule data. Please review the log and try again.')); Mage::logException($e); Mage::getSingleton('adminhtml/session')->setPageData($data); $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('rule_id'))); return; } } $this->_redirect('*/*/'); } public function deleteAction() { if ($id = $this->getRequest()->getParam('id')) { try { $model = Mage::getModel('salesrule/rule'); $model->load($id); $model->delete(); /* Accumulative update */ $this->deleteAccumulative($id); /* Accumulative update */ Mage::getSingleton('adminhtml/session')->addSuccess( Mage::helper('salesrule')->__('The rule has been deleted.')); $this->_redirect('*/*/'); return; } catch (Mage_Core_Exception $e) { $this->_getSession()->addError($e->getMessage()); } catch (Exception $e) { $this->_getSession()->addError( Mage::helper('catalogrule')->__('An error occurred while deleting the rule. Please review the log and try again.')); Mage::logException($e); $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id'))); return; } } Mage::getSingleton('adminhtml/session')->addError( Mage::helper('salesrule')->__('Unable to find a rule to delete.')); $this->_redirect('*/*/'); } /** * @param $model * @param $data */ public function saveAccumulative($model, $data) { $accumulativeModel = Mage::getModel('orange35_accumulativepromo/accumulativepromo'); $items = array( 'promo_id' => $model->getId(), 'orders_period' => $data['orders_period'], 'orders_total_start' => $data['orders_total_start'], 'orders_total_end' => $data['orders_total_end'], ); $accumulativeModel->addData($items); $accumulativeModel->save(); } /** * @param $id */ public function deleteAccumulative($id) { $accumulativeModel = Mage::getModel('orange35_accumulativepromo/accumulativepromo'); $accumulativeModel->load($id); $accumulativeModel->delete(); } }