0

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

1 Answer 1

1

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

1
  • on /app/design/frontend/default/idp/template/catalog/product/list.phhtml this code doesn't do what is expected... when checking for $this->getListBlock() it always fails... so that block is not set (placed at top of page)
    – Kender
    Sep 22, 2014 at 13:48

Your Answer

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

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