【问题标题】:Magento Rule Model overrideMagento 规则模型覆盖
【发布时间】:2011-03-13 10:44:15
【问题描述】:

我在覆盖 Magento 核心类时遇到了一点问题:Core/Rule/Model/Rule.php。 我认为我做的一切都是正确的,但是代码不起作用(没有任何变化)。

我的[命名空间]/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>

我的[命名空间]/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();
    }

我的应用程序/etc/[命名空间]_All.xml:

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

    </modules>
</config>

非常感谢您的帮助。

【问题讨论】:

    标签: magento


    【解决方案1】:

    我已经设法通过覆盖 SalesRule (Mage/SalesRule/Model/Rule) 而不是 Rule 来解决它。您只能在静态时覆盖 Rule 模块(通过创建本地/Mage/Rule/Model/Rule.php 文件)。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-03
    • 2013-01-07
    • 2012-09-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多