我正在寻找增强Magento中的分层导航。Magento中的分层导航分类
目前,被分层导航使用不能被分组的属性,这意味着如果有多个属性,这些属性在逻辑上是在一组(即,属性“高度”,“宽度” &“深度”,其是“尺寸” ,“颜色”和“纹理”属于“外观”部分)。
我认为这会增强用户的可用性和导航。
在我开始为此开发一个模块之前,我想知道是否有人遇到类似于magento的东西,如果没有,您是否有任何提示应该如何做?
约瑟夫
我正在寻找增强Magento中的分层导航。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;
}
}
我只是从Mage_Catalog_Model_Layer重写重写的功能与另外的线路:
$collection->addSetInfo(true);
这可以确保组数据在我需要时加载。
接下来的两个更改只允许您访问数据。
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;
}
}
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();
}
}
MYNAME /导航/ Catalog/Block/Layer/Filter/Attribute.php:
class MyName_Navigation_Catalog_Block_Layer_Filter_Attribute extends Mage_Catalog_Block_Layer_Filter_Attribute {
public function getGroupName() {
return $this->_filter->getGroupName();
}
}
告诉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>
现在你可以从你的模板文件中调用
$_item->getGroupName();
:模板/目录/层/过滤器。php 或
$ _filter-> getGroupName(); 从模板文件:template/catalog/layer/view.php 和组/排序从那里的属性。
看起来不错。而为了这个工作,我需要做的就是将属性放在正确的属性组中.... – josephtikva1 2011-05-15 16:51:26
这不是我正在寻找的,因为分组发生在$ _item中。 - 这是特定属性的选项。我需要这种情况发生得更高,也就是说,在我们循环访问属性之前,我们应该先循环访问属性组,如果该组中有可过滤的属性,则打印组名称,然后遍历属性。 – josephtikva1 2011-05-15 18:32:00
我需要在过滤器级别访问组信息,所以我一起黑客并修改了我的答案。希望这适合你的账单,如果不是的话,我希望它至少能指出你的方向。 – ben 2011-05-16 18:33:27
的过滤导航代码已经在Magento的论坛上很长一段时间,它仍然工作在最新版本:
http://www.magentocommerce.com/boards/viewthread/5500/
这可以提供你所需要的自定义过滤导航的外观以满足您的需求。
您还可以在属性中定义分层导航中的排序顺序。而不是使用'1,2,3'去'100,200,300',以便稍后您可以定义 - 例如 - 'width'到210等等,并将属性放入您需要的排序顺序中。
这不是我要找的。我想我还不够清楚。我正在寻找在分层导航区块中创建另一个标题(属性组),该标题将把属性分成不同的类别。 – josephtikva1 2011-05-15 16:46:56
嗯,只是改变视图,你可以让他们分别分组。该文件是catalog/layer/view.phtml。 – Darren 2011-05-12 15:17:39
我想我可以做到这一点。但不理想 – josephtikva1 2011-05-15 16:48:06