最新消息:Excel无乱码转CSV,由于工作原因很少更新博客和回复大家的评论,非常抱歉。

magento分类侧栏属性多选或单选

其实多选 catagory filter 已经有一个免费模块,但是在企业版里面,安装会报错的,而且会有些兼容性问题。

免费模块:
http://www.magentocommerce.com/magento-connect/Mana+Team/extension/6831/mana_filters

经过研究 这个模块虽然在企业版里面有问题但是使用里面的代码,可以成功的实现这个功能

安装mana_filters 后禁用这个模块

重载 后替换下列代码
app\code\local\Mage\Catalog\Model\Layer\Filter\Attribute.php 代码替换为 Mana_Filters_Model_Filter_Attribute 的代码

app\code\local\Mage\Catalog\Model\Layer\Filter\Item.php 代码替换为 Mana_Filters_Model_Item 的代码

app\code\local\Mage\Catalog\Model\Resource\Eav\Mysql4\Layer\Filter\Attribute.php 代码替换为 Mana_Filters_Resource_Filter_Attribute 的代码

catalog\layer\filter.phtml 请使用 app\design\frontend\base\default\template\mana\filters\items\list.phtml

到这里为止,你已经把所有的catagory filter 属性 改为了多选的方式了

但是如果只是 某些属性是多选,其他保持以前的方式,那你的工作还没有完。

我们需要重载一个BLOCK解决这个问题

在企业版里面重在BLOCK 代码是这样的

<enterprise_search>
<rewrite>
<catalog_layer_view>Silk_Cust_Block_Catalog_Layer_View</catalog_layer_view>
</rewrite>
</enterprise_search>

Silk_Cust_Block_Catalog_Layer_View 代码如下

class Silk_Cust_Block_Catalog_Layer_View extends Mage_Core_Block_Template
{
/**
* State block name
*
* @var string
*/
protected $_stateBlockName;

/**
* Category Block Name
*
* @var string
*/
protected $_categoryBlockName;

/**
* Attribute Filter Block Name
*
* @var string
*/
protected $_attributeFilterBlockName;

/**
* Price Filter Block Name
*
* @var string
*/
protected $_priceFilterBlockName;

/**
* Decimal Filter Block Name
*
* @var string
*/
protected $_decimalFilterBlockName;

/**
* Internal constructor
*/
protected function _construct()
{
parent::_construct();
Mage::register('current_layer', $this->getLayer());

$this->_initBlocks();
}

/**
* Initialize blocks names
*/
protected function _initBlocks()
{
$this->_stateBlockName = 'catalog/layer_state';
$this->_categoryBlockName = 'catalog/layer_filter_category';
$this->_attributeFilterBlockName = 'catalog/layer_filter_attribute';
        $this->_attributeMsFilterBlockName = 'catalog/layer_filter_msattribute';
$this->_priceFilterBlockName = 'catalog/layer_filter_price';
$this->_decimalFilterBlockName = 'catalog/layer_filter_decimal';

if ($this->getIsEngineAvailable()) {
$this->_categoryBlockName = 'enterprise_search/catalog_layer_filter_category';
$this->_attributeFilterBlockName = 'enterprise_search/catalog_layer_filter_attribute';
$this->_priceFilterBlockName = 'enterprise_search/catalog_layer_filter_price';
$this->_decimalFilterBlockName = 'enterprise_search/catalog_layer_filter_decimal';
}
}

/**
* Get attribute filter block name
*
* @deprecated after 1.4.1.0
*
* @return string
*/
protected function _getAttributeFilterBlockName()
{
return 'catalog/layer_filter_attribute';
}

/**
* Prepare child blocks
*
* @return Mage_Catalog_Block_Layer_View
*/
protected function _prepareLayout()
{
$stateBlock = $this->getLayout()->createBlock($this->_stateBlockName)
->setLayer($this->getLayer());

$categoryBlock = $this->getLayout()->createBlock($this->_categoryBlockName)
->setLayer($this->getLayer())
->init();

$this->setChild('layer_state', $stateBlock);
$this->setChild('category_filter', $categoryBlock);

$filterableAttributes = $this->_getFilterableAttributes();
foreach ($filterableAttributes as $attribute) {
if ($attribute->getAttributeCode() == 'price') {
$filterBlockName = $this->_priceFilterBlockName;
}
elseif ($attribute->getBackendType() == 'decimal') {
$filterBlockName = $this->_decimalFilterBlockName;
}
            elseif($attribute->getAttributeCode() == 'color'||$attribute->getAttributeCode() == 'size') { $filterBlockName = $this->_attributeMsFilterBlockName; }

else {
$filterBlockName = $this->_attributeFilterBlockName;
}

$this->setChild($attribute->getAttributeCode() . '_filter',
$this->getLayout()->createBlock($filterBlockName)
->setLayer($this->getLayer())
->setAttributeModel($attribute)
->init());
}

$this->getLayer()->apply();

return parent::_prepareLayout();
}

/**
* Get layer object
*
* @return Mage_Catalog_Model_Layer
*/

public function getLayer()
{
if ($this->getIsEngineAvailable()) {
return Mage::getSingleton('enterprise_search/catalog_layer');
}
return Mage::getSingleton('catalog/layer');
}

/**
* Check if search engine gen be used for catalog navigation
*
* @return bool
*/
public function getIsEngineAvailable()
{
if (!$this->hasData('is_engine_available')) {
$available = Mage::helper('enterprise_search')->isActiveEngine()
&& Mage::helper('enterprise_search')->getSearchConfigData('solr_server_use_in_catalog_navigation')
&& !Mage::helper('enterprise_search')->getTaxInfluence();
$this->setData('is_engine_available', $available);
}
return $this->_getData('is_engine_available');
}

/**
* Get all fiterable attributes of current category
*
* @return array
*/
protected function _getFilterableAttributes()
{
$attributes = $this->getData('_filterable_attributes');
if (is_null($attributes)) {
$attributes = $this->getLayer()->getFilterableAttributes();
$this->setData('_filterable_attributes', $attributes);
}

return $attributes;
}

/**
* Get layered navigation state html
*
* @return string
*/
public function getStateHtml()
{
return $this->getChildHtml('layer_state');
}

/**
* Get all layer filters
*
* @return array
*/
public function getFilters()
{
$filters = array();
if ($categoryFilter = $this->_getCategoryFilter()) {
$filters[] = $categoryFilter;
}

$filterableAttributes = $this->_getFilterableAttributes();
foreach ($filterableAttributes as $attribute) {
$filters[] = $this->getChild($attribute->getAttributeCode() . '_filter');
}

return $filters;
}

/**
* Get category filter block
*
* @return Mage_Catalog_Block_Layer_Filter_Category
*/
protected function _getCategoryFilter()
{
return $this->getChild('category_filter');
}

/**
* Check availability display layer options
*
* @return bool
*/
public function canShowOptions()
{
foreach ($this->getFilters() as $filter) {
if ($filter->getItemsCount()) {
return true;
}
}

return false;
}

/**
* Check availability display layer block
*
* @return bool
*/
public function canShowBlock()
{
return $this->canShowOptions() || count($this->getLayer()->getState()->getFilters());
}

/**
* Retrieve Price Filter block
*
* @return Mage_Catalog_Block_Layer_Filter_Price
*/
protected function _getPriceFilter()
{
return $this->getChild('_price_filter');
}
}

上面代码红色部分是我根据

Mage\Catalog\Block\Layer\View.php

进行的改动

接着更改下面3个文件的名称 类名

app\code\local\Mage\Catalog\Model\Layer\Filter\Attribute.php

to:  app\code\local\Mage\Catalog\Model\Layer\Filter\Msattribute.php

app\code\local\Mage\Catalog\Model\Layer\Filter\Item.php

to:  app\code\local\Mage\Catalog\Model\Layer\Filter\MsItem.php

app\code\local\Mage\Catalog\Model\Resource\Eav\Mysql4\Layer\Filter\Attribute.php

to: app\code\local\Mage\Catalog\Model\Resource\Eav\Mysql4\Layer\Filter\Msattribute.php

删除原来重载的3个文件,改为新的3个Ms开头的文件,并把里面相应的类名替换为 Ms 开头。

我们现在已经大功告成了。

哦 SORRY  我忘记一个关键的文件
app\code\core\Mage\Catalog\Block\Layer\Filter\Msattribute.php
一定要加!

转载请注明:嗨酷哥,有你更酷! » magento分类侧栏属性多选或单选

与本文相关文章

发表我的评论

取消评论
表情 插代码

Hi,您需要填写昵称和邮箱!

  • 必填项
  • 必填项