如何覆盖magento enterprise或magento 1.8中的rate.php?
我需要更改app\code\core\Mage\Tax\Model\Calculation\Rate.php如何覆盖magento enterprise或magento 1.8中的rate.php?,magento,Magento,我需要更改app\code\core\Mage\Tax\Model\Calculation\Rate.php if (!is_numeric($this->getRate()) || $this->getRate() <= 0) { 如果(!是数值($this->getRate())|$this->getRate()getRate())|$this->getRate()
if (!is_numeric($this->getRate()) || $this->getRate() <= 0) {
如果(!是数值($this->getRate())|$this->getRate()getRate())|$this->getRate()<0){
所以我想覆盖这个文件,而不是在核心文件夹中进行更改
请帮助……首先,您需要在自定义模块的config.xml文件中重写core Magento模型:
<config>
<modules>
<MyPackage_MyModule>
<version>0.0.1</version>
</MyPackage_MyModule>
</modules>
<global>
<models>
<mypackage_mymodule>
<class>MyPackage_MyModule_Model</class>
</mypackage_mymodule>
<tax>
<rewrite>
<calculation_rate>MyPackage_MyModule_Model_Calculation_Rate</calculation_rate>
</rewrite>
</tax>
</models>
</global>
</config>
现在,当新方法工作时,您可以添加所需的代码
希望这有帮助!:)只需将您自己的文件Rate.php添加到您的文件夹
/app/code/local/Mage/Tax/Model/Calculation/Rate.php
Magento将检查此文件夹是否存在文件,并在从core加载之前对其进行优先级排序,这意味着不会加载文件/app/code/core/Mage/Tax/Model/Calculation/Rate.php
文件
图例:
ROOT/app/core/ magento files (never do any changes)
ROOT/app/community/ installed modules etc ...
ROOT/app/local/ your own changes only for this installation
谢谢J.S.的帮助。我昨天晚上也试过同样的方法,效果很好。:)你能告诉我如果我在保存之前加上仅方法,其余方法保持不变。您只能添加所需的方法。如果您的重写模型中没有所有方法,则Magento将在核心文件中搜索这些方法:)+1中搜索其他透视图。Magento的框架功能强大且复杂,在处理任务时,最好将所有选项都放在表上。
class MyPackage_MyModule_Model_Calculation_Rate extends Mage_Tax_Model_Calculation_Rate {
/**
* Prepare location settings and tax postcode before save rate
*
* @return Mage_Tax_Model_Calculation_Rate
*/
protected function _beforeSave()
{
die("it works!");
}
}
ROOT/app/core/ magento files (never do any changes)
ROOT/app/community/ installed modules etc ...
ROOT/app/local/ your own changes only for this installation