http://www.panticz.de/sites/default/files/magento/customized-shop-by/local.xml
<?xml version="1.0" encoding="UTF-8"?>
css/local.css
4
category_filter
1http://www.panticz.de/sites/default/files/magento/customized-shop-by/layer_view.css
/*
* /skin/frontend/default/default/css/local.css
*/
/* layer_view custom css */
.block-layered-nav-filter {
clear:both;
}
.block-layered-nav-filter-name,
.block-layered-nav-filter-value {
float:left;
}
.block-layered-nav-filter-value li {
float:left;
padding-top:4px;
padding-left:14px;
}
1http://www.panticz.de/sites/default/files/magento/customized-shop-by/my.view.phtml
<?php /** * Category layered navigation * * @see Mage_Catalog_Block_Layer_View * http://docs.magentocommerce.com/Mage_Catalog/Mage_Catalog_Block_Layer_View.html * * customized layered navigation * ./app/design/frontend/default/default/template/catalog/layer/my.view.phtml * based on * ./app/design/frontend/base/default/template/catalog/layer/view.phtml * * v2011-02-08 by panticz */ ?> <?php function is_filter($_filters, $_content = "") { if(strlen($_content) > 0) { return true; } else { foreach ($_filters as $_filter) { if($_filter->getItemsCount() > 1) { return true; } } } return false; } /* overide this function to disable filter on some category */ function checkAttribute($_filter) { return true; /* example: show this filter only in this category $category = array( "diagonal" => array("TV", "LCD", "Plasma"), "resolution" => array("Beamer") ); $currentCategory = Mage::registry('current_category'); if($_filter->getAttributeModel() != null) { $attributeCode = $_filter->getAttributeModel()->getAttributeCode(); // check if filter for attribute exists if (array_key_exists($attributeCode, $filter)) { // find top category name while($currentCategory->getLevel() > 3) { $currentCategory = $currentCategory->getParentCategory(); } // check if top category in filter if(in_array($currentCategory->getName(), $filter[$attributeCode])) { return true; } else { return false; } } } return true; */ } /* overide this function to disable filter on some pages */ function showFilter() { return true; /* example: dont show filter in root category if(Mage::registry('current_category')->getUrlPath() == "shop.html") { return false; } else { return true; } */ } ?> <?php if($this->canShowBlock() && showFilter()): ?> <?php $_filters = $this->getFilters() ?> <?php if(is_filter($_filters, $this->getStateHtml())): ?><?php endif; ?> <?php endif; ?> 1<?php echo $this->getStateHtml() ?> <?php if($this->canShowOptions()): ?> <?php if(is_filter($_filters)): ?> <?php echo $this->__('Shopping Options') ?> <?php foreach ($_filters as $_filter): ?> <?php if($_filter->getItemsCount() > 1 && checkAttribute($_filter)): ?><?php endif; ?> <?php endforeach; ?> <?php endif; ?> <?php endif; ?>
- <?php echo $this->__($_filter->getName()) ?>:
<?php echo $_filter->getHtml() ?>
http://www.panticz.de/sites/default/files/magento/customized-shop-by/filter.phtml
<?php
if (strrpos($this->helper('core/url')->getCurrentUrl(), "catalogsearch")) {
include($_SERVER["DOCUMENT_ROOT"] . "/app/design/frontend/base/default/template/catalog/layer/filter.phtml");
} else {
include("filter.select.phtml");
}
?>
1http://www.panticz.de/sites/default/files/magento/customized-shop-by/filter.select.phtml
<?php /** * Template for filter items block * * @see Mage_Catalog_Block_Layer_Filter * http://docs.magentocommerce.com/Mage_Catalog/Mage_Catalog_Block_Layer_Filter_Attribute.html * * ./app/design/frontend/default/default/template/catalog/layer/filter.phtml * based on * ./app/design/frontend/base/default/template/catalog/layer/filter.phtml */ ?> <?php echo $this->__('All') ?> <?php foreach ($this->getItems() as $_item): ?> urlEscape($_item->getUrl()) ?>"><?php echo $_item->getLabel() ?> (<?php echo $_item->getCount() ?>) <?php endforeach ?> 1
http://www.panticz.de/sites/default/files/magento/customized-shop-by/state.phtml
<?php
if (strrpos($this->helper('core/url')->getCurrentUrl(), "catalogsearch")) {
echo "";
//include($_SERVER["DOCUMENT_ROOT"] . "/app/design/frontend/base/default/template/catalog/layer/state.phtml");
} else {
include("state.select.phtml");
}
?>
1http://www.panticz.de/sites/default/files/magento/customized-shop-by/state.select.phtml
<?php /** * Category layered navigation state * * @see Mage_Catalog_Block_Layer_State * http://docs.magentocommerce.com/Mage_Catalog/Mage_Catalog_Block_Layer_State.html * * ./app/design/frontend/default/default/template/catalog/layer/state.phtml * based on * ./app/design/frontend/base/default/template/catalog/layer/state.phtml * * v2011-02-08 by panticz * */ ?> <?php $_filters = $this->getActiveFilters() ?> <?php if(!empty($_filters)): ?> <?php echo $this->__('Currently Shopping by') ?> getClearUrl() ?>" class="btn-remove" title="<?php echo $this->__('Clear All') ?>"><?php echo $this->__('Clear All') ?> <?php foreach ($_filters as $_filter): ?><?php echo $_filter->getLabel() ?> getRemoveUrl() ?>"><?php echo $this->__('All') ?> <?php endforeach; ?> <?php endif; ?> 1
- <?php echo $this->__($_filter->getName()) ?>:
OPTIONAL: state.phtml with filter
ToDo: HowTo get avaiable options in a category for a filter?
http://www.panticz.de/sites/default/files/magento/customized-shop-by/state.phtml.with.filter.dev
<?php /** * Category layered navigation state * * @see Mage_Catalog_Block_Layer_State * http://docs.magentocommerce.com/Mage_Catalog/Mage_Catalog_Block_Layer_State.html * * ./app/design/frontend/default/default/template/catalog/layer/state.phtml * based on * ./app/design/frontend/base/default/template/catalog/layer/state.phtml */ ?> <?php $_filters = $this->getActiveFilters() ?> <?php if(!empty($_filters)): ?> <?php echo $this->__('Currently Shopping by') ?>getClearUrl() ?>" class="btn-remove" title="<?php echo $this->__('Clear All') ?>"><?php echo $this->__('Clear All') ?> <?php foreach ($_filters as $_filter): ?>getRemoveUrl() ?>"><?php echo $this->__('All') ?> <?php $attributeCode = $_filter->getFilter()->getRequestVar(); $product = Mage::getModel('catalog/product'); $collection = Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter($attributeCode); // ->setEntityTypeFilter($product->getResource()->getTypeId()) $_attribute = $collection->getFirstItem()->setEntity($product->getResource()); $attribute_options = $_attribute->getSource()->getAllOptions(false); /* $layer = Mage::getModel("catalog/layer"); //foreach($categories as $categoryid) { // $category = Mage::getModel("catalog/category")->load($categoryid); $category = Mage::registry('current_category'); $layer->setCurrentCategory($category); $attributes = $layer->getFilterableAttributes(); echo "xxxxxxxxxxxx" . print_r($attributes); //} //$_activefilters = Mage::getSingleton(’Mage_Catalog_Block_Layer_State’)->getActiveFilters(); */ ?> <?php foreach($attribute_options as $option): ?> <?php $optionLabel = $option['label']; ?> <?php $optionValue = $option['value']; ?> <?php if(strrpos($_filter->getRemoveUrl(), "?")) $token = "&"; else $token = "?"; ?> <?php $link = $token . $attributeCode . "=" . $optionValue; echo $link; ?> getRemoveUrl()) . $link; ?>" <?php if($optionLabel == $_filter->getLabel()) echo " selected"; ?>><?php echo $optionLabel // $_filter->getLabel() ?> <?php endforeach; ?> <?php endforeach; ?> <?php endif; ?> 1
- <?php echo $this->__($_filter->getName()) ?>:
other files
./app/code/core/Mage/Catalog/Block/Layer/Filter/Abstract.php
./app/design/frontend/default/default/layout/catalogsearch.xml
Links
http://classyllama.com/development/magento-development/the-better-way-to-modify-magento-layout/
http://docs.magentocommerce.com/Mage_Catalog/Mage_Catalog_Block_Layer_Filter_Attribute.html
http://www.mageintern.de/magento-shop-design/magento-navigation/filternavigation-layered-nav-mit-drop-down-auswahl.html
http://www.magentocommerce.com/boards/viewthread/28220/