Advertisement
kiatng

Magento Layered Navigation

Apr 13th, 2011
984
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.07 KB | None | 0 0
  1. <?php
  2.     $param = '';
  3.     if(isset($_GET['cat'])) {
  4.         $curCatId = $_GET['cat'];
  5.         $curCat = Mage::getModel('catalog/category')->load($curCatId);
  6.         $param = "&cat=$curCatId";      
  7.     } else {
  8.         $curCat = Mage::getSingleton('catalog/layer')->getCurrentCategory();            
  9.     }
  10.     $subCatIds  = $curCat->getAllChildren(true);  
  11.     $_filters = $this->getActiveFilters();
  12. ?>
  13.  
  14. <?php if(!empty($_filters)): ?>
  15. <div class="state">
  16.     <p class="block-subtitle"><?php echo $this->__('Currently Shopping by:') ?></p>
  17.     <dl>
  18.     <?php foreach ($_filters as $_filter): ?>
  19.             <dd>                
  20.                 <?php if(get_class($_filter->getFilter()) == 'Mage_Catalog_Model_Layer_Filter_Attribute') :?>                
  21.                     <?php                    
  22.                         $attributeModel = $_filter->getFilter()->getAttributeModel();    
  23.                         $attrOptions = $attributeModel->getSource()->getAllOptions();  //array of options
  24.                         $catModel= Mage::getModel('catalog/category');
  25.                         $filterColor = $this->stripTags($_filter->getLabel());
  26.                        
  27.                         $colors = '';
  28.                         foreach($subCatIds as $catId) {
  29.                             $catModel->load($catId);          
  30.                             $collection = $catModel->getProductCollection();  
  31.                             $collection->addAttributeToSelect('apparel_color_value')
  32.                                   ->getSelect()->group('apparel_color_value');
  33.                             foreach($collection as $product) {
  34.                                 if ($product->isSaleable()) {
  35.                                     $colors .= $product['apparel_color_value'].',';                                
  36.                                 }
  37.                             }
  38.                         }
  39.                     ?>
  40.                     <ol id="option-list-<?php echo $attributeModel->getAttributeId() ?>">                              
  41.                     <?php foreach($attrOptions as $attr): ?>                          
  42.                           <?php if($attr['value']): ?>                                                                                              
  43.                               <?php if($attr["label"] != $filterColor): ?>                                                                            
  44.                                     <?php if(strpos($colors, $attr["label"].',') !== false) : ?>
  45.                                           <li><a href="<?php echo $this->getUrl('').$curCat->getUrlPath() ?>?apparel_color=<?php echo $attr["value"]?><?php echo $param ?>" ><?php echo  $attr["label"]; ?></a></li>                                              
  46.                                     <?php endif; ?>                                                                                                                  
  47.                               <?php else:?>
  48.                                   <li class="current"> <?php echo $filterColor; ?></li>  
  49.                               <?php endif;?>                    
  50.                         <?php endif; ?>
  51.                     <?php endforeach;  ?>          
  52.                     </ol>
  53.                 <script type="text/javascript">decorateList('option-list-<?php echo $attributeModel->getAttributeId() ?>', 'none-recursive')</script>
  54.             <?php else:?>
  55.                   <ol>
  56.                       <li>
  57.                           <a href="<?php echo $_filter->getRemoveUrl() ?>" title="<?php echo $this->__('Remove This Item') ?>" class="btn-remove"><?php echo $this->__('Remove This Item') ?></a>
  58.                           <span class="label"><?php echo $this->__($_filter->getName()) ?>:</span> <?php echo $_filter->getLabel() ?>
  59.                       </li>
  60.                   </ol>
  61.             <?php endif; ?>
  62.             </dd>
  63.      <?php endforeach; ?>      
  64.     </dl>
  65.    
  66.     <a class="all" style="float:right;" href="<?php echo $this->getClearUrl()?>">All</a>  
  67. </div>
  68. <?php endif; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement