Magento Rule Model override
I've got a little problem overriding the Magento core class: Core/Rule/Model/Rule.php. I think I'm doing everything correctly, but the code just doesn't work (Nothing changes).
My [namespace]开发者_如何学JAVA/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 app/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 some help.
I've managed to solve it by overriding SalesRule (Mage/SalesRule/Model/Rule) instead of Rule. You can only override the Rule module when you do it static (by creating a local/Mage/Rule/Model/Rule.php file).
精彩评论