1

I have a product with 3 attributes(color,size,brand) and some other attributes.

I need to display above 3 attributes in a table with unique rows.

For example product1 values: green,12,samsung

product2 values :yellow,12,samsung

product3 vaules:green,12,samsung.

So I need to get only (product1 or product3 ) & product2 from collection.

(because product1 & product3 all values are same.So i want to avoid duplicate rows)

and my sample code:

$collection=Mage::getResourceModel('catalog/product_collection')->distinct(true);

How to write query to get above one. Can any one help this ? Thanks in advance.

6

2 Answers 2

4

Using this resource you can see that the method ->addAttributeToFilter(AttributeCode, Value) is what you need to apply to a collection to filter products.

So something along these lines should work for you:

$collection=Mage::getModel('catalog/product')->getCollection()
    ->addAttributeToFilter('brand', array('eq'=>'samsung'))
    ->addAttributeToFilter('size', array('eq'=>'12'))
    ->addAttributeToSelect('*')
    ->distinct(TRUE);

Depending on your setup you may need to find the ID of those values instead of the text that the customer sees. Also it still may not help you get just the two you are looking for since they have other fields or attributes that make them unique.

0

You could try with:

Mage::getModel('catalog/product')->getCollection()->getSelect()->distinct();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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