I am displaying products from collection.

There are different attributes assigned to different products.

Here is my code:

    $collection =  Mage::getResourceModel('catalog/product_collection') 
  ->addAttributeToFilter('category_id', array('IN' => array($category))) ->addAttributeToSelect('*');

 foreach ($collection as $_product) 

Here above $category is category id.

There are 2 attributes. consider A and B.

Now my problem is.. I want to display products with attribute 'A' first.. then products with attribute 'B' and then remaining products will be displayed. I have tried.

$collection->addAttributeToSort('A', 'DESC');

But it is not working.

Can anyone help me?

Your help will be highly appreciated.

  • you have tried with ->addAttributeToSort('A', 'DESC')->->addAttributeToSort('A', 'ASC); – Amit Bera Oct 7 '15 at 5:50
  • but there are no changes after using it. – ved Oct 7 '15 at 6:03
  • checking and get back to you sortly – Amit Bera Oct 7 '15 at 6:04

Your Answer

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

Browse other questions tagged or ask your own question.