Kender
Kender

Reputation: 1254

Magento - set default product sort on single category only

I am trying to set default (uneditable) sort for a single category in Magento to SKU DESC and hide the sort option on that category only

basically I want this to only sort on SKU, DESC... regardless of what options were selected on other pages before hitting this page

So far I am able to hide the sort feature, no problem, but setting the sort is giving me some trouble

I have added in: /app/design/frontend/default/idp/template/catalog/category/view.phtml

if($_SERVER['REMOTE_ADDR'] == {MY IP}) :
  if($_category->getId() == 4) :
    $_category->_data['default_sort_by'] = "sku_sort";
   endif;
endif;

This is setting the default sort order on this page fine, but I cannot find how to force it to go DESC instead of ASC.. any help would be appreciated

as a temporary fix until I figure this out, I am using the solution found here, the first comment on the page has a specialized solution (changed created_at to sku) The only problem with this solution is it affects all sku based sorting pages and results, not just the single page

Upvotes: 0

Views: 1497

Answers (1)

David Arroyo
David Arroyo

Reputation: 11

You can modify the toolbar object from the catalog/product/list.phtm removing available sort attributes and setting the default sort you need:

$_category = Mage::registry('current_category');
if ($_category && $_category->getId() == 4 && $this->getListBlock()){
   $availableOrders = $_category->getAvailableSortByOptions();
   unset($availableOrders['position']); // Delete the sort attributes you don't need

   $this->getListBlock()
    ->setAvailableOrders($availableOrders)
    ->setDefaultDirection('desc')
    ->setSortBy('sku_sort');
}

Hope that helps

Upvotes: 1

Related Questions