I'm trying to select all products with an attribute called uitgelicht_product
set to Ja
. It's not the first time that I'm doing this and it usually goes well, but this is situation is a bit different, because I have 2 different attribute sets. The attribute occurs in both attribute sets: Default
and Test
.
I'm able to retrieve the products with uitgelicht_product
set to Ja
in the Default
set, but I also want the products from the attribute set Test
. I tried using this to see if I can get it only from Test
:
$products->addAttributeToFilter('attribute_set_id','39');
But this doesn't return anything, while 39 is the attribute ID of Test
. Changing 39 to 4 (the id of the Default set) works fine and returns the product using the attribute set Default with uitgelicht_product
set to Ja
.
How do I get the products with uitgelicht_product
set to Ja
in both the Test
as the Default
attribute set?
This is the entire code I'm using to retrieve the products:
<?php
$_helper = $this->helper('catalog/output');
$productBlock = $this->getLayout()->createBlock('catalog/product_price');
$yesOpID = null;
$attribute = Mage::getSingleton('eav/config')->getAttribute('catalog_product', 'uitgelicht_product');
if ($attribute->usesSource()) {
$options = $attribute->getSource()->getAllOptions(false);
foreach ($options as $e) {
if ($e['label'] == 'Ja'):
$yesOpID = $e['value'];
endif;
}
}
$products = Mage::getModel('catalog/product')->getCollection();
$products->addAttributeToSelect('*');
$products->addAttributeToFilter('uitgelicht_product', $yesOpID);
$products->addAttributeToFilter('status', Mage_Catalog_Model_Product_Status::STATUS_ENABLED);
$products->addAttributeToFilter('attribute_set_id', '39');
$products->addStoreFilter();
$products->getSelect()->group('e.entity_id');
$products->getSelect()->order('RAND()');
$products->getSelect()->limit(4);