I added a new attribute "featured_category" as a boolean.

The issue I'm having is when filtering on a category collection - it seemingly ignores this value in my filtering:

/** @var $categories Mage_Catalog_Model_Resource_Category_Collection */
$categories = Mage::getResourceModel("catalog/category_collection");
$categories->addAttributeToSelect(array("name", "image"))
           ->addAttributeToFilter('is_active', array('eq'=>'1'))
           ->addAttributeToFilter("featured_category", array("eq", '1'));

I originally thought it was a string/integer/boolean type thing, but '1', 1 and "1" all fail to filter the collection.

I'm sure this is going to be something obvious...

-- including mysql4-install-0.2.0.php in case it has some impact...

$installer = $this;

$setup = new Mage_Eav_Model_Entity_Setup('core_setup');

$entityTypeId     = $setup->getEntityTypeId('catalog_product');
$attributeSetId   = $setup->getDefaultAttributeSetId($entityTypeId);
$attributeGroupId = $setup->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);

$setup->addAttribute('catalog_category', 'featured_category', array(
    'type' => 'int',
    'group'     => 'General Information',
    'backend' => '',
    'frontend' => '',
    'label' => 'Featured Category (Home Page)',
    'input' => 'select',
    'class' => '',
    'source' => 'eav/entity_attribute_source_boolean',
    'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
    'visible' => true,
    'required' => false,
    'user_defined' => false,
    'default' => '0',
    'searchable' => false,
    'filterable' => false,
    'comparable' => false,
    'visible_on_front' => false,
    'unique' => false,

    '13'//last Magento's attribute position in General tab is 10

  • everything reindexed? – Marius Jun 15 '14 at 18:59
  • Everything indexed, caches cleared. I've also gone into each category and re-saved it through the admin, and it's still giving me ones that aren't set. – Douglas Radburn Jun 15 '14 at 19:29

Not 100% sure, but I think this is the problem.

->addAttributeToFilter("featured_category", array("eq", '1'));

Should be

->addAttributeToFilter("featured_category", array("eq"=>'1'));

or just simply

->addAttributeToFilter("featured_category", 1);
  • Genius. Couldn't see the wood for the trees - that's the one! Thanks very much! – Douglas Radburn Jun 15 '14 at 19:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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