我正在寻求增强Magento中的分层导航.
目前,分层导航中使用的属性无法分组,这意味着如果您有多个逻辑上属于一个组的属性(即属性"高度","宽度"和"深度",即"尺寸"和"颜色" "和"纹理"属于"外观"部分).
我认为这会增强用户的可用性和导航.
在我开始为此开发一个模块之前,我想知道是否有人为magento遇到这样的事情,如果没有,你有任何提示应该怎么做?
约瑟夫
我为此创建了一个模块.以下是我所做的更改:
MYNAME /导航/目录/型号/ Layer.php:
class MyName_Navigation_Catalog_Model_Layer extends Mage_Catalog_Model_Layer {
public function getFilterableAttributes()
{
$setIds = $this->_getSetIds();
if (!$setIds) {
return array();
}
$collection = Mage::getResourceModel('catalog/product_attribute_collection')
->setItemObjectClass('catalog/resource_eav_attribute');
$collection->addSetInfo(true);
$collection->getSelect()->distinct(true);
$collection
->setAttributeSetFilter($setIds)
->addStoreLabel(Mage::app()->getStore()->getId())
->setOrder('position', 'ASC');
$collection = $this->_prepareAttributeCollection($collection);
$collection->load();
return $collection;
}
}
Run Code Online (Sandbox Code Playgroud)
我只是用Mage_Catalog_Model_Layer重写了被覆盖的函数:
$collection->addSetInfo(true);
Run Code Online (Sandbox Code Playgroud)
这可确保在需要时加载组数据.
接下来的两个更改只允许您访问数据.
MYNAME /导航/目录/型号/层/ Attribute.php:
class MyName_Navigation_Catalog_Model_Layer_Filter_Attribute extends Mage_Catalog_Model_Layer_Filter_Attribute {
public function getGroupName($setId = 4) {
$attribute = $this->getAttributeModel();
$group_id = $attribute->getData('attribute_set_info/' . $setId . '/group_id');
$group = Mage::getModel('eav/entity_attribute_group')->load($group_id);
$group_name = $group->getData('attribute_group_name');
return $group_name;
}
}
Run Code Online (Sandbox Code Playgroud)
MYNAME /导航/目录/型号/层/ Item.php:
class MyName_Navigation_Catalog_Model_Layer_Filter_Item extends Mage_Catalog_Model_Layer_Filter_Item {
public function getGroupName()
{
return $this->getFilter()->getGroupName();
}
}
Run Code Online (Sandbox Code Playgroud)
MYNAME /导航/目录/块/层/过滤/ Attribute.php:
class MyName_Navigation_Catalog_Block_Layer_Filter_Attribute extends Mage_Catalog_Block_Layer_Filter_Attribute {
public function getGroupName() {
return $this->_filter->getGroupName();
}
}
Run Code Online (Sandbox Code Playgroud)
告诉magento使用我的模块而不是核心文件.MYNAME /导航的/ etc/config.xml中
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<MyName_Navigation>
<version>0.1.0</version>
</MyName_Navigation>
</modules>
<global>
<blocks>
<catalog>
<rewrite>
<layer_filter_attribute>MyName_Navigation_Catalog_Block_Layer_Filter_Attribute</layer_filter_attribute>
</rewrite>
</catalog>
</blocks>
<models>
<catalog>
<rewrite>
<layer>MyName_Navigation_Catalog_Model_Layer</layer>
<layer_filter_attribute>MyName_Navigation_Catalog_Model_Layer_Filter_Attribute</layer_filter_attribute>
<layer_filter_item>MyName_Navigation_Catalog_Model_Layer_Filter_Item</layer_filter_item>
</rewrite>
</catalog>
</models>
</global>
</config>
Run Code Online (Sandbox Code Playgroud)
现在你可以打电话了
$_item->getGroupName();
Run Code Online (Sandbox Code Playgroud)
来自您的模板文件:template/catalog/layer/filter.php或
$ _filter-> getGroupName(); 从您的模板文件:template/catalog/layer/view.php和Group/Sort属性.
| 归档时间: |
|
| 查看次数: |
7058 次 |
| 最近记录: |