1

In Magento 1.9.2.x I would like to create a custom module that will show all sale items (anything with a current special price) within a different section of the store but retaining the normal category hierarchy/structure and filtered navigation etc.

Example:

Standard category URLs showing non-sale items:

/books/
/videos/
/games/

New URLs showing only sale items within those same categories:

/sale/books/
/sale/videos/
/sale/games/

Previously we have done this by creating the "Sale" category and replicating the standard category tree beneath that and assigning products to those categories.

This quickly becomes un-manageable for a large catalogue, and when special prices end it is almost impossible to remember to remove the items from the Sale categories. A previous dev tried scripting the removal of products from sale categories but I don't feel that is the right approach either.

This guide from Inchoo looks like it will help me achieve most of what I want. The missing part is how I could implement the normal (/) and sale (/sale/) category URL structure.

Any ideas how I may handle this?

0

you could write a custom module and register 'sale' as its frontname and the category's url_key as a parameter (eg. /sale/category/books) i have some hints here for you regarding loading the products. when you want to have all filters available from the layered nav you should load the products via the catalog/layer model...

Namespace/Module/config.xml:

<frontend>
    <routers>
        <saleproducts>
            <use>standard</use>
            <args>
                <module>{Namespace_Module}</module>
                <frontName>sale</frontName>
            </args>
        </saleproducts>
    </routers>
    <layout>
        <updates>
            <saleproducts>
                <file>sale.xml</file>
            </saleproducts>
        </updates>
    </layout>
</frontend>

Namespace/Module/controllers/IndexController.php:

class Namespace_Module_IndexController extends Mage_Core_Controller_Front_Action
{
    public function indexAction()
    {
        $this->loadLayout();     
        $this->renderLayout(); 
    }
}

in the layout file /design/frontend/base/default/layout/sale.xml:

<?xml version="1.0"?>
<layout version="0.1.0">
    <sale_index_index>
        <reference name="content">
            <block type="sale/product_list" name="product_list" template="catalog/product/list.phtml">
                <block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
                    <block type="page/html_pager" name="product_list_toolbar_pager"/>
                </block>
                <action method="addColumnCountLayoutDepend"><layout>empty</layout><count>6</count></action>
                <action method="addColumnCountLayoutDepend"><layout>one_column</layout><count>5</count></action>
                <action method="addColumnCountLayoutDepend"><layout>two_columns_left</layout><count>4</count></action>
                <action method="addColumnCountLayoutDepend"><layout>two_columns_right</layout><count>4</count></action>
                <action method="addColumnCountLayoutDepend"><layout>three_columns</layout><count>3</count></action>
                <action method="setToolbarBlockName"><name>product_list_toolbar</name></action>
            </block>
        </reference>
    </sale_index_index>
</layout> 

and a Block in Namespace/Module/Block/Product/List.php :

class Namespace_Module_Block_Product_List extends Mage_Catalog_Block_Product_List
{
 protected function _getProductCollection()
{

        $category = Mage::getModel('catalog/category')->setStoreId(Mage::app()->getStore()->getId())->load($this->getRequest()->getCategory(), 'url_key');
        Mage::register('current_category', $category);
        $productCollection = Mage::getSingleton('catalog/layer')->getProductCollection();

        return $productCollection;

}

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.