1

Im am in the progress of making a gift finder. For that, I need to make some specific filterable attributes, that I would like to show in this category only (Gifts for men, Gifts for women, etc..)

What would be the best way to achieve this? Some check for category id in view.phtml or some hiding in catalog.xml and a custom xml-layout for the specific category to show it there?

3 Answers 3

1

Custom layout update for specific category will be a good idea. That way you will not require to add some specific category id conditions.

You can add in admin for specific category, in custom layout update field like

<reference name="category.products">
   <block type="module/block" name="gift_finder" template="catalog/product/gift_finder.phtml">
</reference>
2
  • Thanks. However, as soon as I enable the filter to be used in layered navigation, it shows up in all categories by default. I need to figure out some way to hide it by default, then make it show up in gift finder.. Oct 12, 2015 at 9:14
  • If you need to use it in filter section, this link might be help magento.stackexchange.com/questions/11567/… Oct 12, 2015 at 9:21
0

Managed to get it working like this:

In /template/catalog/layer/view.phtml i added these variables in the top:

if (Mage::registry('current_category')) {
    $_category = Mage::registry('current_category')->getId();
    $parentId  = Mage::getModel('catalog/category')->load($_category)->getParentId();
}

Then I changed the code that's getting the available filters. The name of my filter is 'Filter' and the only category I want it shown on has id 317.

<dl id="narrow-by-list">
    <?php if ($_category == 317 || $parentId == 317):?>

        <?php $_filters = $this->getFilters() ?>
        <?php foreach ($_filters as $_filter): ?>       
        <?php if($_filter->getItemsCount()): ?>
            <dt><?php echo $this->__($_filter->getName()) ?></dt>
            <dd><?php echo $_filter->getHtml() ?></dd>
        <?php endif; ?>
        <?php endforeach; ?>

    <?php else: ?>

        <?php $_filters = $this->getFilters() ?>
        <?php foreach ($_filters as $_filter): ?>       

        <?php if ($this->__($_filter->getName() == "Filter")):?>
        <?php continue; ?>
        <?php endif; ?>

        <?php if($_filter->getItemsCount()): ?>
            <dt><?php echo $this->__($_filter->getName()) ?></dt>
            <dd><?php echo $_filter->getHtml() ?></dd>
        <?php endif; ?>
        <?php endforeach; ?>

    <?php endif;?>    
</dl>
0

You can use the code from Hide an attribute in Layering Navigation for a specified category and change !in_array to in_array

if (!$hiddenAttributes || (is_array($hiddenAttributes) && !in_array($attribute->getAttributeCode(), $hiddenAttributes))) {

to:

if (!$hiddenAttributes || (is_array($hiddenAttributes) && in_array($attribute->getAttributeCode(), $hiddenAttributes))) {

Now you can go to categories "Custom Layout Update" (or local.xml) and add this:

<reference name="catalog.leftnav">
    <action method="hideAttributes"><code>price,manufacturer</code></action>
</reference>

Rename variables and method name too ...

Your Answer

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

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