1

I want to display Maxprice display first how to get that collection

$categoryIds = array(469);//category id
$products = Mage::getResourceModel('catalog/product_collection')
->addCategoryFilter(Mage::getModel('catalog/category')->load($categoryIds));
$Collection = Mage::getModel('catalog/product')->getCollection()->addFieldToFilter('entity_id', array('in' => $products->getAllIds()));;
$Collection->addAttributeToSelect(array(
                                   'image','small_image',
                                   'name',
                                   'short_description'
                   ))
->addFieldToFilter('visibility', array(
                               Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
                               Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG
                   )) 


->joinField('qty',
             'cataloginventory/stock_item',
             'qty',
             'product_id=entity_id',
             '{{table}}.stock_id=1',
             'left')
 ->addAttributeToFilter('qty', array("gt" => 0))

->addFinalPrice()
->getSelect()
->where('price_index.final_price' < 'price_index.price')->Order('price_index.final_price', 'DESC');
1

try that

$categoryIds = array(469);//category id


      $products = Mage::getResourceModel('catalog/product_collection')
->addCategoryFilter(Mage::getModel('catalog/category')->load($categoryIds));
$Collection = Mage::getModel('catalog/product')->getCollection()->addFieldToFilter('entity_id', array('in' => $products->getAllIds()));;
$Collection->addAttributeToSelect(array(
                                   'image','small_image',
                                   'name',
                                   'short_description'
                   ))
->addFieldToFilter('visibility', array(
                               Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
                               Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG
                   )) 


->joinField('qty',
             'cataloginventory/stock_item',
             'qty',
             'product_id=entity_id',
             '{{table}}.stock_id=1',
             'left')
 ->addAttributeToFilter('qty', array("gt" => 0))

->addFinalPrice()
->getSelect()
->where('price_index.final_price' < 'price_index.price');
$Collection->addAttributeToSort('price', 'desc');
  • I already try this it won't show that block also – Magento 2 Feb 16 '16 at 5:44
  • update the answer kindly try that and feedback.. – Qaisar Satti Feb 16 '16 at 5:47
  • I will check and let you know i got confused – Magento 2 Feb 16 '16 at 5:56
  • it works for ASC order – Magento 2 Feb 22 '16 at 5:53
  • yes just change DESC to ASC – Qaisar Satti Feb 22 '16 at 5:58
0

In Magento,you can sort a product collection by addAttributeToSort().

If you want to sort product collection by final price,then Use getSelect()->order("price_index.final_price DESC") , as final_price is not an attribute.

Also, if you want to sort by price then you can use addAttributeToSort('price','DESC');

  • I will check and let you know i got confused – Magento 2 Feb 16 '16 at 6:01

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.