php - Magento 覆盖核心模型

标签 php magento model overriding core

我知道这个问题已经在这里被问过几次了,但我已经看完了答案,但仍然不明白为什么我不能覆盖 Magento 中的核心模型:

我试图覆盖 Eav/Attribute/Data/Text.php,但它拒绝使用我的 validateValue() 函数版本。

这是我的模型类/app/code/local/Hailstorm/Eav/Model/Attribute/Data/Text.php

class Hailstorm_Eav_Model_Attribute_Data_Text extends Mage_Eav_Model_Attribute_Data_Text {
    public function validateValue($value) {


        $attribute  = $this->getAttribute();    

        echo "My validator for |" . $attribute->getAttributeCode() . "|!\n";

        if ($attribute->getAttributeCode() == 'postcode') {
            $countryId = $this->getExtractedData('country_id');
            $optionalZip = Mage::helper('directory')->getCountriesWithOptionalZip();
            if (!in_array($countryId, $optionalZip)) {
                return parent::validateValue($value);
            }
            return true;
        }
        else {
            return parent::validateValue($value);
        }
    }
}

这是我的 config.xml/app/code/local/Hailstorm/Eav/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <hailstorm_eav>
            <version>0.1.0</version>
        </hailstorm_eav>
    </modules>
    <global>
       <models>
          <eav>
              <rewrite>
                  <attribute_data_text>Hailstorm_Eav_Model_Attribute_Data_Text</attribute_data_text>
              </rewrite>
          </eav>
       </models>
       <hailstorm_eav>
            <class>Hailstorm_Eav_Model</class>
       </hailstorm_eav>
    </global>
</config>

这是我的模块 xml 文件

/app/etc/modules/Hailstorm_Eav.xml

<?xml version="1.0"?>
<config>
    <modules>
        <hailstorm_eav>
            <active>true</active>
            <codepool>local</codepool>
        </hailstorm_eav>
    </modules>
</config>

我已经阅读了这里的教程和其他类似问题的答案,但我看不出我做错了什么!

感谢您的帮助

最佳答案

使用这个

<codePool>local</codePool>

关于php - Magento 覆盖核心模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25246275/

相关文章:

model-view-controller - 为什么身份验证通常在 MVC 的 Controller 中?

java - Java 中的动态模型

php - MySQL:获取推荐人花费最多的前 3 个推荐人

php - 在 PHPUnit 异常上禁用堆栈跟踪

javascript - Magento jQuery 主题

magento - 如何在 Magento 管理区添加自定义 CSS 文件

php - PHP MySQL 中的循环内循环

php - 使用PHP在mysql更新中影响的行

css - 玛根托 : how to properly move custom simple products options in the right column on product page?

javascript - 在 React 和 React Native 中使用模型