I am currently trying to add a new category attribute to the category admin screen in Magento 1.8.1, I am having issues with getting anything to show though.
The only code examples I can find include mysql4, however I thought this had been retired? Please can anyone point us in the right direction here.
I can see my extension under Config > Advanced and in the core_resources table. But not in the front end of the site.
You can use Category's CollectionFactory class and select all attributes by using a star (*) symbol in addAttributeToSelect method. You can use this code example below in your class. protected $_categoryFactory; public function __construct( // ...
Category attributes are characteristics of a category which can be used to extend webshop search and also for filtering of products in the webshop using facets. To assign category attributes to the category hierarchy click: Product information management > Setup > Categories > Category hierarchies.
We've tried this recently with 1.8.2.0. You don't really need to create a module just to add a category attribute, once. It seems such a waste to go through so much file cruft to get something installed just once.
Category attributes tend to stay permanently once installed so what worked better for us is to just use a one-off script. Save this one right at magento root.
<?php
require_once "app/Mage.php";
Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID));
$installer = new Mage_Sales_Model_Mysql4_Setup;
// change details below:
$attribute = array(
'type' => 'int',
'label'=> 'Your attribute label',
'input' => 'text',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'visible' => true,
'required' => false,
'user_defined' => true,
'default' => "",
'group' => "General Information"
);
$installer->addAttribute('catalog_category', 'your_attribute_code', $attribute);
$installer->endSetup();
Save it as add_category_attribute.php
or something else memorable for you.
You can either use the browser to get to this file, or use php-cli
to run this:
php -f add_category_attribute.php
Good luck.
Change the file name from mysql4-install-0.0.1.php
to install-0.0.1.php
@h3nr1ke You can get attribute with:
$category = Mage::registry('current_category');
if ($category){
$value = $category->getData('YOUR_CUSTOM_ATTRIBUTE_CODE');
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With