As we know, sorting option of a category is persistent on different categories. Which means if you select sorting option as "Price" for a Category 1 and go to Category 2 sorting option will be selected as "Price" though default sorting is selected as "Best Value".
Scenario:
Suppose there is a category as "New" and default category for "New" is "Product New from Date (news_from_date)" attribute.
When ever customer comes to New category, default sorting option should be selected as "New" (news_from_date), which means Sorting persistence should not affect New Category.
Step (1):
- Go to BO => Catalog => Categories => Manage Categories => Select Category "Niw"
- Under Display Settings Tab
---- Default Product Listing Sort By = "Set Product as New from Date"
- Under Custom Design Tab
---- Custom Layout Update:
<reference name="product_list_toolbar">
<action method="setDefaultDirection"><string>desc</string></action>
</reference>
Step (2):
app/code/local/ISM/New/etc/config.xml
<config>
<frontend> <events> <core_block_abstract_to_html_before> <observers> <ism_sorting_new_category> <class>ism_new/observer</class> <method>unsetSortingNewCategory</method> </ism_sorting_new_category> </observers> </core_block_abstract_to_html_before> <controller_action_postdispatch_catalog_category_view> <observers> <ism_disable_cache_for_new_category> <class>ism_new/observer</class> <method>disableCacheForNewCategory</method> </ism_disable_cache_for_new_category> </observers> </controller_action_postdispatch_catalog_category_view> </events> </frontend>
</config>
Step (3):app/code/local/ISM/New/Model/Observer.php
/** * Disable parameter memorizing and unset sorting order & category for category "Nieuwe"(New) * @param Varien_Event_Observer $observer * @return $this */
public function unsetSortingNewCategory(Varien_Event_Observer $observer) { $block = $observer->getBlock(); if ($block instanceof Mage_Catalog_Block_Product_List) { $category = Mage::registry('current_category'); if ($category && $category->getDefaultSortBy() == 'news_from_date') { $sortingOrder = Mage::app()->getRequest()->getParam('order', false); $sortingDirection = Mage::app()->getRequest()->getParam('dir', false); if (!$sortingOrder && !$sortingDirection) { Mage::getSingleton('catalog/session')->unsSortOrder(); Mage::getSingleton('catalog/session')->unsSortDirection(); } } } return $this; } /** * Disable Cache for New (Nieuwe) category * @param Varien_Event_Observer $observer * @return $this */
public function disableCacheForNewCategory(Varien_Event_Observer $observer) { $category = Mage::registry('current_category'); if ($category && $category->getDefaultSortBy() == 'news_from_date') { $request = $observer->getEvent()->getControllerAction()->getRequest(); $request->setParam('no_cache', true); } return $this; }
No comments:
Post a Comment