0

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);
Siarhey Uchukhlebau
16.2k11 gold badges57 silver badges89 bronze badges
asked Aug 12, 2016 at 8:06

2 Answers 2

0

Please make your attribute uitgelicht_product with yes/no and then add in both attribute set and set some product yes. and please use below code.

<?php
$products = Mage::getModel('catalog/product')->getCollection();
$products->addAttributeToSelect('*');
$products->addAttributeToFilter('uitgelicht_product','1');
$products->addAttributeToFilter('status', Mage_Catalog_Model_Product_Status::STATUS_ENABLED);
$products->addAttributeToFilter('attribute_set_id','9');
//here 9 is my attribute set
print_r($products->getData());
?>
answered Aug 12, 2016 at 11:35
0

try

<?php
 $attribute_set_id = array('4','39');
 $products = Mage::getResourceModel('catalog/product_collection')
 ->addAttributeToSelect('*');
 ->addAttributeToFilter('uitgelicht_product','Ja')
 ->addAttributeToFilter('status', Mage_Catalog_Model_Product_Status::STATUS_ENABLED)
 ->addFieldToFilter('attribute_set_id',array('in' => $attribute_set_id));
 print_r($products->getData());
?>
answered Aug 12, 2016 at 12:16
3
  • Unfortunately this didn't return anything. It returned: Array ( ) Commented Aug 12, 2016 at 13:56
  • check now i had changed code Commented Aug 12, 2016 at 13:59
  • Sorry, it still shows the same result. Could it be that it has something to do with a setting? Commented Aug 12, 2016 at 14:09

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.