Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. $collectionWithRank = Mage::getResourceModel('catalog/product_collection')
  2. ->addCategoryFilter($cat_data)
  3. ->addAttributeToSelect('*')
  4. ->addAttributeToFilter('sort', ['neq' => ''])
  5. ->addAttributeToSort('sort', 'asc')
  6. ->addAttributeToSort('entity_id','desc');
  7. $collectionWithRank->load();
  8.  
  9. $collectionWithoutRank = Mage::getResourceModel('catalog/product_collection')
  10. ->addCategoryFilter($cat_data)
  11. // ->addAttributeToSelect(array('name', 'price', 'image', 'collect', 'url_key', 'sort'))
  12. ->addAttributeToSelect('*')
  13. ->addAttributeToFilter('sort', ['null' => true])
  14. ->addAttributeToSort('created_at', 'desc')
  15. ->addAttributeToSort('entity_id','desc');
  16. $collectionWithoutRank->load();
  17.  
  18. $merged_ids = array_merge($collectionWithRankids, $collectionWithoutRankids);
  19. $collection = Mage::getResourceModel('catalog/product_collection')
  20. ->addFieldToFilter('entity_id', array('in' => $merged_ids))
  21. ->addAttributeToSelect('*');
  22. $collection->getSelect()->order(new Zend_Db_Expr('FIELD(e.entity_id, ' . implode(',', $merged_ids).')'));
  23.  
  24. if($sortby = "price_h_to_l"){
  25. $collection->getSelect()->reset(Zend_Db_Select::ORDER);
  26. $collection->addAttributeToSort('price', 'desc');
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement