Anonymous Anonymous - 1 year ago 238
PHP Question

Magento 1.9.1 model rewrite not executed

I've been trying for days now to get a rewritten model to function.
The code seems to be correct and the rewrite seems to work, but I can't see the logs, that I've put there for debugging purposes in the system.log.

I've tried several tutorials with all the same result.

Module WR_EPO is active and running. Even some installer-scripts for adding new columns in to my sql database are working fine.

Here's my code:

under 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>


the rewritten model under 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;
}


}

here I add 2 variables $minValue and $maxValue und afterwards I do the logging into system.log and additionally into a custom log file, but none of them appear, when I refresh the page (cache cleared beforehand).

How can I fix/debug this? Why is the rewritten model not loaded instead of the core one? From what I've read custom rewrites override core Models.

Help is very appreciated

Answer Source

You need to change

<product_option_type>WR_Catalog_Model_Product_Option_Type</product_option_type>

to

<product_option_type_text>WR_EPO_Model_Product_Option_Type_Text</product_option_type_text>

put file to WR/EPO/Model/Product/Option/Type/Text.php and change it class name from

class WR_Catalog_Model_Product_Option_Type_Text

to

class WR_EPO_Model_Product_Option_Type_Text