I try to implement a module in which I need to rewrite Mage_Catalog_Model_Product_Option.
I then add the following file to the module
<?php
class Mine_Custoptiontype_Model_Catalog_Product_Option extends Mage_Catalog_Model_Product_Option
{
const OPTION_GROUP_FILESSTATE = 'filesstate';
const OPTION_TYPE_FILESSTATE_TYPE = 'filesstate_type';
/**
* Get group name of option by given option type
*
* @param string $type
* @return string
*/
public function getGroupByType($type = null)
{
if (is_null($type)) {
$type = $this->getType();
}
$group = parent::getGroupByType($type);
if( $group === '' && $type = self::OPTION_TYPE_FILESSTATE_TYPE ){
$group = self::OPTION_GROUP_FILESSTATE;
}
return $group;
}
/**
* Group model factory
*
* @param string $type Option type
* @return Mage_Catalog_Model_Product_Option_Group_Abstract
*/
public function groupFactory($type)
{
if( $type === self::OPTION_TYPE_FILESSTATE_TYPE ){
return Mage::getModel('custoptiontype/catalog_product_option_type_filesstatetype');
}
return parent::groupFactory($type);
}
}
?>
and modify my model config.xml file :
<models>
<catalog>
<rewrite>
<product_option>Mine_Custoptiontype_Model_Catalog_Product_Option</product_option>
</rewrite>
</catalog>
</models>
but when I would like to access the OPTION_GROUP_FILESSTATE and OPTION_TYPE_FILESSTATE_TYPE using app/code/core/Mage/Catalog/Model/Resource/Product/Option.php,
I have got errors saying these 2 constant do not exist…
Help me please !
Best Answer
You cannot access constants from a child class using the parent class name.
Those constants don't exist in
Mage_Catalog_Model_Product_Option
.You should be able to access them like this: