Magento Rule Model Overrides

I have a little problem overriding the main Magento class: Core / Rule / Model / Rule.php. I think I'm doing everything right, but the code just doesn't work (nothing changes).

My [namespace] /Rule/etc/config.xml:

 <?xml version="1.0"?>
<config>
 <modules>
  <[namespace]_Rule>
   <version>0.1.0</version>
  </[namespace]_Rule>
 </modules>
    <global>
        <models>
            <rule>
                <rewrite>
                    <rule>[namespace]_Rule_Model_Rule</rule>
    </rewrite>
            </rule>
        </models>
    </global>
</config>

My [namespace] /Rule/Model/Rule.php:

class [namespace]_Rule_Model_Rule extends Mage_Rule_Model_Rule
{

  protected function _beforeSave()
    { 

        if ($this->getConditions()) {
            $this->setConditionsSerialized(serialize($this->getConditions()->asArray()));
            $this->unsConditions();
        }
        if ($this->getActions()) {
            $this->setActionsSerialized(serialize($this->getActions()->asArray()));
            $this->unsActions();
        }

        $this->_prepareWebsiteIds();

        if (is_array($this->getCustomerGroupIds())) {
            $this->setCustomerGroupIds(join(',', $this->getCustomerGroupIds()));
        }
        parent::_beforeSave();
    }

My application / etc / [namespace] _All.xml:

<?xml version="1.0"?>
<config>
    <modules>
    <[namespace]_Rule>
           <active>true</active>
           <codePool>local</codePool>
       </[namespace]_Rule>

    </modules>
</config>

I would really appreciate help.

+3
source share
1 answer

I managed to solve this by replacing the SalesRule (Mage / SalesRule / Model / Rule) instead of the rule. You can only override the Rule module when you become static (by creating a local file / Mage / Rule / Model / Rule.php).

+1
source

Source: https://habr.com/ru/post/1753740/


All Articles