2

I have a category with an ID of 12 and an ID of 15. In category settings category 15 has a custom design of mylayout_default and category 12 has a custom design of mylayout_design2. The difference in the two designs is catalog/product/list.phtml.

When I browse to category 15 it loads the default layout of mylayout_default, as it should. When I browse to category 12 it loads the design2 layout, as it should.

The Problem

When I search I need the same rules to apply and they don't. Let's say the search URL is /catalogsearch/result/?cat=15&q=show me some results. The default layout is loaded. However, when I search category 12 (/catalogsearch/result/?cat=12&q=show me some results) the layout does not update to design2.

In catalogsearch.xml I can modify the block to <block type="catalog/product_list" name="search_result_list" template="../../design2/template/catalog/product/list.phtml"> but that only works if I modify the default layout file (not design2) and it, of course, applies globally rather than just a single category.

2 Answers 2

3

The issue here is that there is no concept of a cateogory within search. You're merely filtering by category within that search.

To compensate for this I suggest that either rewrite your searches to a specific subcategory for specific filter terms, OR, remove categories as filters and rather have them link to the subcategory with the current filters applied.

This is not a terribly simple solution, granted, but your requirements are a bit out of the ordinary.

2

Based on @philwinkle's guidance I was able to resolve this by creating an observer. The observer below allows the search to use the design of the category being filtered by. It hasn't been fully tested with FPC.

Config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Etre_Catalogsearch>
            <version>0.1.0</version>
            <description>Module allows search design to match category custom design settings</description>
        </Etre_Catalogsearch>
    </modules>
    <global>
        <models>
            <etre_catalogsearch>
                <class>Etre_Catalogsearch_Model</class>
                <resourceModel>etre_catalogsearch_resource</resourceModel>
            </etre_catalogsearch>
            <etre_catalogsearch_resource>
                <class>Etre_Catalogsearch_Model_Resource</class>
            </etre_catalogsearch_resource>
        </models>
    </global>
    <frontend>
        <events>
            <controller_action_layout_load_before>
                <observers>
                    <layout_test>
                        <class>etre_catalogsearch/observer</class>
                        <method>dynamicCatalogSearchDesign</method>
                    </layout_test>
                </observers>
            </controller_action_layout_load_before>
        </events>
    </frontend>
</config>

Observer.php

<?php

class Etre_Catalogsearch_Model_Observer
{
    public function dynamicCatalogSearchDesign($observer)
    {
        $handles = $observer->getEvent()->getLayout()->getUpdate()->getHandles();
        if (is_array($handles)) {
            if (in_array("catalogsearch_result_index", $handles, true)) {
                $catId = Mage::app()->getRequest()->getParam("cat");
                $category = Mage::getModel("catalog/category")->load($catId);
                $currentDateTimestamp = Mage::getModel('core/date')->timestamp();
                $customTo = $category->getCustomDesignDate()["to"];
                $customFrom = $category->getCustomDesignDate()["from"];
                $customDesignActiveDates = [
                    'to' => [
                        'readable' => $customTo,
                        'timestamp' => Mage::getModel('core/date')->timestamp($customTo)
                    ],
                    'from' => [
                        'readable' => $customFrom,
                        'timestamp' => Mage::getModel('core/date')->timestamp($customFrom)
                    ]
                ];
                $endDatePassed = false;
                if ($customDesignActiveDates['to']['timestamp'] > $currentDateTimestamp || $customDesignActiveDates['to']['readable'] == null) {
                    $endDatePassed = true;
                }
                $toDatePassed = false;
                if ($customDesignActiveDates['from']['timestamp'] < $currentDateTimestamp || $customDesignActiveDates['from']['readable'] == null) {
                    $toDatePassed = true;
                }
                if($endDatePassed && $toDatePassed){
                    $design = $category->getCustomDesign();
                    Mage::getModel("catalog/design")->applyCustomDesign($design);
                }
            }
        }
    }
} 
1
  • I don't believe that catalogsearch will allow FPC support anyhow, depending on the # of querystring params! Glad to see this worked for you. Don't forget to mark this as answered as soon as it allows you to do so.
    – philwinkle
    Commented Sep 2, 2015 at 18:59

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.