1

I am trying to setup a module that will extract my Base (CAD) Canadian prices and show converted USD price. To me it seems like I set up everything as needed, but there is error in the admin panel when I try to EXTRACT product data.

ERROR: Invalid backend model specified: customcatattrb/product_attribute_backend

/htdocs/app/code/local/Meteorify/Customcatattrb/sql/customcatattrb_setup/mysql4-install-0.0.1.php

<?php
$installer = $this;
$installer->startSetup();
$installer->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'price_usd', array(
    'type'                       => 'decimal',
    'label'                      => 'USD Price',
    'input'                      => 'text',
    'backend'                    => 'customcatattrb/product_attribute_backend_usdprice',
    'global'                     => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE,
    'required'                   => false,
    'searchable'                 => false,
    'filterable'                 => false,
    'comparable'                 => false,
    'is_configurable'            => false,
   'group'                      => 'Price'
));
$installer->endSetup();
?>

htdocs/app/code/local/Meteorify/Customcatattrb/Model/Product/Attribute/Backend/Usdprice.php

class Meteorify_Customcatattrb_Model_Product_Attribute_Backend_Usdprice extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract
{
    /**
     * Before save method
     *
     * @param Varien_Object $object
     *
     * @return Mage_Eav_Model_Entity_Attribute_Backend_Abstract
     */
    public function beforeSave($object)
    {
        $attrCode = $this->getAttribute()->getAttributeCode();
        $basePrice = $object->getData('price');

        $value = Mage::helper('directory')->currencyConvert($basePrice, Mage::app()->getStore()->getDefaultCurrencyCode(), 'USD');
        $object->setData($attrCode, $value);

        return $this;
    }
}

Could someone please check the codes above and see if there are any problems causing the error

Invalid backend model specified: customcatattrb/product_attribute_backend

3
  • Did you define the <models> node correctly in the config.xml? Paste it here, if you can.
    – laketuna
    Commented Oct 29, 2014 at 19:25
  • @laketuna I believe so, Yes. The module is installed. I see attributes in Magento admin, Its just there is an error when I export products. This is how I configured config.xml <module>Meteorify_Customcatattrb</module> <class>Mage_Eav_Model_Entity_Setup</class>
    – philtak
    Commented Oct 29, 2014 at 19:26
  • @laketuna <?xml version="1.0"?> <config> <modules> <Meteorify_Customcatattrb> <version>0.0.1</version> </Meteorify_Customcatattrb> </modules> <global> <resources> <customcatattrb_setup> <setup> <module>Meteorify_Customcatattrb</module> <class>Mage_Eav_Model_Entity_Setup</class> </setup> <connection> <use>default_setup</use> </connection> </customcatattrb_setup> </resources> </global> </config>
    – philtak
    Commented Oct 29, 2014 at 19:41

1 Answer 1

1

Your installation script configuration is correct if your script is run and you get that error. I don't see in your pasted config.xml the following..

<config>
    ....
    <global>
        <models>
            <customcatattrb>
                <class>Meteorify_Customcatattrb_Model</class>
            </customcatattrb>
            ...
        </models>
        ...
    </global>
</config>

Did you define the above, which tells Magento where your models are? When you use customcatattrb/product_attribute_backend_usdprice, Magento looks for your <model>'s definition of where your model classes are supposed to be. Give it a shot.

3
  • I actually don't have this particular code in my config. But the module got isntalled without it. Where in code should I insert it?
    – philtak
    Commented Oct 29, 2014 at 19:51
  • It must be in the config.xml. Let me format it for you better..
    – laketuna
    Commented Oct 29, 2014 at 21:36
  • Thank you for helping me with index.php. I would like to ask you, how to create an Observer for Reindex for this function ?
    – philtak
    Commented Oct 31, 2014 at 17:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.