Skip to content

Instantly share code, notes, and snippets.

@aleron75
Last active May 18, 2018 15:57
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aleron75/7304592 to your computer and use it in GitHub Desktop.
Save aleron75/7304592 to your computer and use it in GitHub Desktop.
Programmaticalli create a Yes/No Magento Category Attribute
<?php
/** @var Mage_Eav_Model_Entity_Setup $installer */
$installer = $this;
$installer->startSetup();
$this->addAttribute(
'catalog_category',
'my_custom_attribute',
array(
'group' => 'General Information',
'input' => 'select',
'type' => 'int',
'source' => 'eav/entity_attribute_source_boolean',
'label' => 'My Custom Attribute',
'required' => 0,
'unique' => 0,
'sort_order' => 3,
'user_defined' => 1,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));
$installer->endSetup();
@rafiqeladli
Copy link

Hi, thank's for this greate code.i have quation how can'i filtring categories collection by this cutom attribute.

@luizventurote
Copy link

Thanks!

@dfelton
Copy link

dfelton commented Jun 16, 2016

@rafiqeladli like this:

/* @var $collection Mage_Catalog_Model_Resource_Category_Collection */
$collection = Mage::getResourceModel('catalog/category_collection');
$collection->addAttributeToFilter(
    'my_custom_attribute' // <!-- Change this to your actual category attribute
    '1' // Supplying "0" would filter by categories set to "no" instead"
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment