1
votes

I'm working on a magento module that shows particular product collections under a new controller and front-name.

Some of these collections get big, so I'd like to add layered navigation to the side of the page. (And hey, pagination and sort while we're at it.)

I can add the layered navigation block with

        <reference name="left">
           <block type="catalog/layer_view" name="catalog.leftnav" template="landing/layer.phtml"/>
        </reference>

What I get with that is the layered navigation as applied to the whole catalog, with categories broken, and no interface with the on-page product collection.

How would I go about wiring up the layered navigation (and hey, pagination and sort) to this custom product collection?

2

2 Answers

1
votes

No answers were forthcoming here, and I changed direction and never completed this path of development. Figured I'd post what I'd learned.

The approach above is sound. The work basically entails recreating the functionality on the catalog or catalogsearch modules. You'll have to subclass the models and blocks of catalog, modifying the product collection and current category.

This post heads vaguely in the right direction, but doesn't get there.
http://www.webdesign-gm.co.uk/news/layered-navigation-on-home-page-or-any-cms-page-magento.php If you make more headway on this, feel free to post.

0
votes

I've had a similar request from a client to include specific filterable attributes under a mega menu. Using a static block i've added this line to everywhere i needed a listing of attributes for specific category

{{block type="core/template" attribute_code="age_specific" category_id="12"  template="megamenu-custom-filter-list.phtml"}}

And then the "megamenu-custom-filter-list.phtml"

<?php if($this->getCategoryId() && is_numeric($this->getCategoryId()) && $this->getAttributeCode()): ?>
 <?php
  $visible_items = 12;
  $category = Mage::getModel('catalog/category')->load($this->getCategoryId());
  $attrCode = $this->getAttributeCode();
  unset($layer);
  $layer = Mage::getModel("catalog/layer");
  $layer->setCurrentCategory($category);
  $attributes = $layer->getFilterableAttributes();
  foreach ($attributes as $attribute):
    if($attribute->getAttributeCode() != $attrCode){
      continue;
    }
    if ($attribute->getAttributeCode() == 'price') {
      $filterBlockName = 'catalog/layer_filter_price';
    } elseif ($attribute->getBackendType() == 'decimal') {
      $filterBlockName = 'catalog/layer_filter_decimal';
    } else {
      $filterBlockName = 'catalog/layer_filter_attribute';
    }
    $result = Mage::app()->getLayout()->createBlock($filterBlockName)->setLayer($layer)->setAttributeModel($attribute)->init();
 ?>
    <div>
      <h4 class="menu-block-title"><?php echo $this->__($attribute->getFrontendLabel()) ?></h4>
      <ul class="menu-attr-list">
        <?php $counting = 1; ?>
        <?php foreach($result->getItems() as $option): ?>
          <?php $optionUrl = $category->getUrl() . "?" . $attribute->getAttributeCode() . "=" . $option->getValue(); ?>
          <?php if(!$option->getCount()){ continue; } ?>
          <li class="<?php echo ($counting >= $visible_items+1)?"visible-on-showmore":"" ?>" style="list-style: none;">
            <a class="cube" href="<?php echo $optionUrl ?>">
              <?php echo $option->getLabel() ?> <?php /* (<?php echo $option->getCount() ?>) */ ?>
            </a>
          </li>
          <?php $counting++; ?>
        <?php endforeach; ?>
        <?php if($counting >= $visible_items+1): ?>
          <li class="show-more-menuitem">
            <a href="javascript:void(0)" onclick="showMoreMenuItems(this); return false;" class="">
              <?php echo $this->__('Visa fler') ?>
            </a>
          </li>
        <?php endif; ?>
      </ul>
    </div>
 <?php endoreach; ?>
<?php endif; ?>

Of course, this can be extended to allow all attributes to be shown and not limit them to 12 (as i did here). Although, i've not build a feature to show this for a custom collection, but i believe that following the "catalog/layer" model and see where the collection was loaded, you can see how to overwrite it and load your own custom collection.