Magento 1.9.1 模型重写未执行
Magento 1.9.1 model rewrite not executed
几天来我一直在努力让重写的模型发挥作用。
代码似乎是正确的并且重写似乎有效,但我看不到日志,我为了调试目的把它放在 system.log.
中
我试过几个教程,结果都一样。
模块 WR_EPO 处于活动状态并且 运行。甚至一些用于向我的 sql 数据库添加新列的安装程序脚本也工作正常。
这是我的代码:
local/WR/EPO/etc/config.xml:
<?xml version="1.0"?>
<config>
<modules>
<WR_EPO>
<version>1.0.0.1</version>
</WR_EPO>
</modules>
<global>
<models>
<wr_epo>
<class>WR_EPO_Model</class>
<resourceModel>wr_epo_resource</resourceModel>
</wr_epo>
<wr_epo_resource>
<class>WR_EPO_Model_Resource</class>
<entities>
<field>
<table>wr_epo_field</table>
</field>
</entities>
</wr_epo_resource>
<catalog>
<rewrite>
<product_option_type>WR_Catalog_Model_Product_Option_Type</product_option_type>
</rewrite>
</catalog>
<wishlist>
<rewrite>
<item>WR_Wishlist_Model_Item</item>
</rewrite>
</wishlist>
</models>
<resources>
<wr_epo_setup>
<setup>
<module>WR_EPO</module>
</setup>
</wr_epo_setup>
</resources>
<blocks>
<adminhtml>
<rewrite>
<tag_edit>WR_Adminhtml_Block_Catalog_Product_Edit_Tab_Options</tag_edit>
</rewrite>
</adminhtml>
</blocks>
</global>
</config>
local/WR/EPO/Catalog/Model/Product/Option/Type/text下重写的模型。php:
<?php
class WR_Catalog_Model_Product_Option_Type_Text extends Mage_Catalog_Model_Product_Option_Type_Text
{
/**
* Validate user input for option
*
* @throws Mage_Core_Exception
* @param array $values All product option values, i.e. array (option_id => mixed, option_id => mixed...)
* @return Mage_Catalog_Model_Product_Option_Type_Default
*/
public function validateUserValue($values)
{
parent::validateUserValue($values);
$option = $this->getOption();
$value = trim($this->getUserValue());
// Check requires option to have some value
if (strlen($value) == 0 && $option->getIsRequire() && !$this->getSkipCheckRequiredOption()) {
$this->setIsValid(false);
Mage::throwException(Mage::helper('catalog')->__('Please specify the product\'s required option(s).'));
}
// Check maximal length limit
$maxCharacters = $option->getMaxCharacters();
$minValue = $option->getMinValue();
$maxValue = $option->getMaxValue();
if ($maxCharacters > 0 && Mage::helper('core/string')->strlen($value) > $maxCharacters) {
Mage::log(
"success maxChar in text.php",
null,
'WR_product-updates.log'
);
Mage::Log("success maxChar in text.php");
if (isset($minValue) && isset($maxValue) && ($value < $minValue || $value > $maxValue)){
$this->setIsValid(false);
Mage::throwException(Mage::helper('catalog')->__('The value is not in range!!!'));
}
else{
$this->setIsValid(false);
Mage::throwException(Mage::helper('catalog')->__('The text is too long'));
}
}
$this->setUserValue($value);
return $this;
}
}
在这里我添加了 2 个变量 $minValue 和 $maxValue und 之后我登录 system.log 并另外登录到自定义日志文件,但是当我刷新页面时其中 none 出现了(预先清除缓存)。
我怎么能fix/debug这个?为什么没有加载重写的模型而不是核心模型? 从我读到的自定义重写覆盖核心模型。
非常感谢帮助
你需要改变
<product_option_type>WR_Catalog_Model_Product_Option_Type</product_option_type>
到
<product_option_type_text>WR_EPO_Model_Product_Option_Type_Text</product_option_type_text>
将文件放入 WR/EPO/Model/Product/Option/Type/Text.php
并将其更改为 class name from
class WR_Catalog_Model_Product_Option_Type_Text
到
class WR_EPO_Model_Product_Option_Type_Text
几天来我一直在努力让重写的模型发挥作用。 代码似乎是正确的并且重写似乎有效,但我看不到日志,我为了调试目的把它放在 system.log.
中我试过几个教程,结果都一样。
模块 WR_EPO 处于活动状态并且 运行。甚至一些用于向我的 sql 数据库添加新列的安装程序脚本也工作正常。
这是我的代码:
local/WR/EPO/etc/config.xml:
<?xml version="1.0"?>
<config>
<modules>
<WR_EPO>
<version>1.0.0.1</version>
</WR_EPO>
</modules>
<global>
<models>
<wr_epo>
<class>WR_EPO_Model</class>
<resourceModel>wr_epo_resource</resourceModel>
</wr_epo>
<wr_epo_resource>
<class>WR_EPO_Model_Resource</class>
<entities>
<field>
<table>wr_epo_field</table>
</field>
</entities>
</wr_epo_resource>
<catalog>
<rewrite>
<product_option_type>WR_Catalog_Model_Product_Option_Type</product_option_type>
</rewrite>
</catalog>
<wishlist>
<rewrite>
<item>WR_Wishlist_Model_Item</item>
</rewrite>
</wishlist>
</models>
<resources>
<wr_epo_setup>
<setup>
<module>WR_EPO</module>
</setup>
</wr_epo_setup>
</resources>
<blocks>
<adminhtml>
<rewrite>
<tag_edit>WR_Adminhtml_Block_Catalog_Product_Edit_Tab_Options</tag_edit>
</rewrite>
</adminhtml>
</blocks>
</global>
</config>
local/WR/EPO/Catalog/Model/Product/Option/Type/text下重写的模型。php:
<?php
class WR_Catalog_Model_Product_Option_Type_Text extends Mage_Catalog_Model_Product_Option_Type_Text
{
/**
* Validate user input for option
*
* @throws Mage_Core_Exception
* @param array $values All product option values, i.e. array (option_id => mixed, option_id => mixed...)
* @return Mage_Catalog_Model_Product_Option_Type_Default
*/
public function validateUserValue($values)
{
parent::validateUserValue($values);
$option = $this->getOption();
$value = trim($this->getUserValue());
// Check requires option to have some value
if (strlen($value) == 0 && $option->getIsRequire() && !$this->getSkipCheckRequiredOption()) {
$this->setIsValid(false);
Mage::throwException(Mage::helper('catalog')->__('Please specify the product\'s required option(s).'));
}
// Check maximal length limit
$maxCharacters = $option->getMaxCharacters();
$minValue = $option->getMinValue();
$maxValue = $option->getMaxValue();
if ($maxCharacters > 0 && Mage::helper('core/string')->strlen($value) > $maxCharacters) {
Mage::log(
"success maxChar in text.php",
null,
'WR_product-updates.log'
);
Mage::Log("success maxChar in text.php");
if (isset($minValue) && isset($maxValue) && ($value < $minValue || $value > $maxValue)){
$this->setIsValid(false);
Mage::throwException(Mage::helper('catalog')->__('The value is not in range!!!'));
}
else{
$this->setIsValid(false);
Mage::throwException(Mage::helper('catalog')->__('The text is too long'));
}
}
$this->setUserValue($value);
return $this;
}
}
在这里我添加了 2 个变量 $minValue 和 $maxValue und 之后我登录 system.log 并另外登录到自定义日志文件,但是当我刷新页面时其中 none 出现了(预先清除缓存)。
我怎么能fix/debug这个?为什么没有加载重写的模型而不是核心模型? 从我读到的自定义重写覆盖核心模型。
非常感谢帮助
你需要改变
<product_option_type>WR_Catalog_Model_Product_Option_Type</product_option_type>
到
<product_option_type_text>WR_EPO_Model_Product_Option_Type_Text</product_option_type_text>
将文件放入 WR/EPO/Model/Product/Option/Type/Text.php 并将其更改为 class name from
class WR_Catalog_Model_Product_Option_Type_Text
到
class WR_EPO_Model_Product_Option_Type_Text