I am trying to set a custom backend model for a custom attribute. The problem is that Magento prepends the ‘Mage’ directory to the path, so I can’t keep all the files in my extension directory.
Code:
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$setup->addAttribute('catalog_category', $postData['attribute_code'], array(
'label' => $postData['frontend_label'],
'input' => $postData['frontend_input'],
'backend' => 'my_company/myextension_model_category_attribute_backend_file',
'required' => $postData['is_required'],
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
'group' => $postData['attribute_group_name'],
'sort_order' => $postData['sort_order']
));
Instead of the path being relative to my extension, ‘Mage’ gets prepended and results in this error:
Warning: include(Mage/My_Company/Model/My_Extension/Model/Category/Attribute/Backend/File.php): failed to open stream
I haven’t found a solution that works with the addAttribute() method.
In troubleshooting, it wasn’t immediately clear where Magento is prepending the path.
Everything renders fine (I’m using a file renderer), but it doesn’t save correctly without the backend of course.
I’m on Magento 1.6.1.
Double check if your app/code/local/Your_Company/Your_Extension/etc/config.xml registered your model to Magento system: