dopcpc9207 2014-08-11 14:56
浏览 33
已采纳

Magento覆盖核心模型

I know this has been asked a few times on here, but I've been through the answers and still can't figure out why I can't override a core model in Magento:

I am trying to override the Eav/Attribute/Data/Text.php but it refuses to use my version of the validateValue() function.

Here is my model class /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() . "|!
";

        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);
        }
    }
}

Here is my 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>

And here is my module xml file

/app/etc/modules/Hailstorm_Eav.xml

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

I've been through the tutorials and the answers to other questions like this on here, but I can't see what I'm doing wrong!

Thanks for any help

  • 写回答

2条回答 默认 最新

  • dousi0144 2014-08-11 15:05
    关注

    Use this

    <codePool>local</codePool>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试