Freelance Expert Technique Magento - Magento : Dupliquer promotion catalogue ou panier

CONTACT
RSS

Magento : Dupliquer promotion catalogue ou panier

Dupliquer règle catalogue Magento

Je vous propose ici un petit module permettant de dupliquer aisément des règles de promotions catalogue ou panier sous Magento.

Pour ceux qui chercheraient juste le code permettant de dupliquer une règle depuis une autre, je vous le livre dans la suite de ce post.

NB : Je vous livre ici les actions ayant vocation a recevoir en post les datas de l’entité à dupliquer.

1) Pour une règle de promotion Panier

public function duplicatequoteAction($data = null) {
        if ($this->getRequest()->getPost()) {
            try {
                $model = Mage::getModel('salesrule/rule');
                Mage::dispatchEvent('adminhtml_controller_salesrule_prepare_save', array('request' => $this->getRequest()));
                $data = $this->getRequest()->getPost();
                unset($data['rule_id']);
                if (isset($data['coupon_code'])) {
                    $data['coupon_code'] = "AUTOGEN_" . time();
                }
                $data = $this->_filterDates($data, array('from_date', 'to_date'));

                /* $id = $this->getRequest()->getParam('rule_id');
                  print('<pre>');
                  /*$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);
                    $_url = str_replace('aaa', 'a', Mage::getModel('adminhtml/url')->getUrl('aaadmin/promo_quote/edit', array('id' => $model->getId())));
                    Mage::app()->getResponse()->setRedirect($_url);
                    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);

                $session->setPageData($model->getData());

                $model->save();
                $session->addSuccess(Mage::helper('salesrule')->__('The rule has been duplicated. You are in the copy.'));
                $session->setPageData(false);

                $_url = str_replace('aaa', 'a', Mage::getModel('adminhtml/url')->getUrl('aaadmin/promo_quote/edit', array('id' => $model->getId())));
                Mage::app()->getResponse()->setRedirect($_url);
                return;
            } catch (Mage_Core_Exception $e) {
                $this->_getSession()->addError($e->getMessage());
                $_url = Mage::helper('adminhtml')->getUrl('admin/admin/promo_quote');
                Mage::app()->getResponse()->setRedirect($_url);
            } 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);

                $_url = str_replace('aaa', 'a', Mage::getModel('adminhtml/url')->getUrl('aaadmin/promo_quote'));
                Mage::app()->getResponse()->setRedirect($_url);
                return;
            }
        }
        $_url = str_replace('aaa', 'a', Mage::getModel('adminhtml/url')->getUrl('aaadmin/promo_quote'));
        Mage::app()->getResponse()->setRedirect($_url);
        return;
    }

2) Pour une règle de promotion Catalogue

public function duplicatecatalogAction($data) {
        if ($this->getRequest()->getPost()) {
            try {
                $model = Mage::getModel('catalogrule/rule');
                Mage::dispatchEvent('adminhtml_controller_catalogrule_prepare_save', array('request' => $this->getRequest()));
                $data = $this->getRequest()->getPost();
                unset($data['rule_id']);

                $data = $this->_filterDates($data, array('from_date', 'to_date'));
                /*if ($id = $this->getRequest()->getParam('rule_id')) {
                    $model->load($id);
                    if ($id != $model->getId()) {
                        Mage::throwException(Mage::helper('catalogrule')->__('Wrong rule specified.'));
                    }
                }*/

                $validateResult = $model->validateData(new Varien_Object($data));
                if ($validateResult !== true) {
                    foreach($validateResult as $errorMessage) {
                        $this->_getSession()->addError($errorMessage);
                    }
                    $this->_getSession()->setPageData($data);
                    $_url = str_replace('aaa','a',Mage::getModel('adminhtml/url')->getUrl('aaadmin/promo_catalog/edit', array('id' => $model->getId())));
                    Mage::app()->getResponse()->setRedirect($_url);
                    return;
                }

                $data['conditions'] = $data['rule']['conditions'];
                unset($data['rule']);

                if (!empty($data['auto_apply'])) {
                    $autoApply = true;
                    unset($data['auto_apply']);
                } else {
                    $autoApply = false;
                }

                $model->loadPost($data);

                Mage::getSingleton('adminhtml/session')->setPageData($model->getData());

                $model->save();

                Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('catalogrule')->__('The rule has been duplicated. You are in the copy'));
                Mage::getSingleton('adminhtml/session')->setPageData(false);

                $_url = str_replace('aaa','a',Mage::getModel('adminhtml/url')->getUrl('aaadmin/promo_catalog/edit', array('id' => $model->getId())));
                Mage::app()->getResponse()->setRedirect($_url);
                return;
            } catch (Mage_Core_Exception $e) {
                $this->_getSession()->addError($e->getMessage());
            } 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);
                $_url = str_replace('aaa','a',Mage::getModel('adminhtml/url')->getUrl('aaadmin/promo_catalog/edit', array('id' => $this->getRequest()->getParam('rule_id'))));
                Mage::app()->getResponse()->setRedirect($_url);
                return;
            }
        }
        $this->_redirect('*/*/');
    }
CATÉGORIES :

Magento

  1. Hiya great web page! Guy. Wonderful. Amazing. I most certainly will save your website and also grab the feeds likewise? I’m just thrilled to discover plenty of handy info the following inside the write-up, we need build more approaches on this respect, thanks for expressing.

  2. It is also very good to note that not all escorts in France provide sexual services, so you need to agree with your escort on the expectations to keep away from issues later on.

  3. No matter where they work, PAs are focused on patient wellness and are integral in managing patient care and supporting health and well-being.
    The Associated Press contributed to this report.
    Login Sign Up 5:30 am – 6:00 pm PST, 7:00 am – 3:30 pm SAT Call Toll Free 1.

    kamagra jelly

  1. No trackbacks yet.