Magento中分层导航的类别

Magento中分层导航的类别,magento,Magento,我希望增强Magento中的分层导航 目前,分层导航中使用的属性无法分组,这意味着如果您有多个属性逻辑上属于一个组(即属性“高度”、“宽度”和“深度”,即“尺寸”,“颜色”和“纹理”属于“外观”部分) 我认为这将增强用户的可用性和导航能力 在我开始为这个开发一个模块之前,我想知道是否有人在magento中遇到过类似的东西,如果没有,你有什么建议如何做到这一点 Joseph过滤导航的代码已经出现在Magento论坛上很长时间了,它在最新版本中仍然有效: 这可能会提供您需要定制过滤导航外观的功能,

我希望增强Magento中的分层导航

目前,分层导航中使用的属性无法分组,这意味着如果您有多个属性逻辑上属于一个组(即属性“高度”、“宽度”和“深度”,即“尺寸”,“颜色”和“纹理”属于“外观”部分)

我认为这将增强用户的可用性和导航能力

在我开始为这个开发一个模块之前,我想知道是否有人在magento中遇到过类似的东西,如果没有,你有什么建议如何做到这一点


Joseph

过滤导航的代码已经出现在Magento论坛上很长时间了,它在最新版本中仍然有效:

这可能会提供您需要定制过滤导航外观的功能,以满足您的需要


您还可以在属性中定义分层导航中的排序顺序。与其使用“1、2、3”,不如选择“100、200、300”,这样以后您就可以定义-比如说-“宽度”到210等,并将属性按您需要的排序顺序放入其中。

过滤导航的代码在Magento论坛上已经存在很长时间了,它在最新版本中仍然有效:

这可能会提供您需要定制过滤导航外观的功能,以满足您的需要


您还可以在属性中定义分层导航中的排序顺序。不要使用“1、2、3”,而是选择“100、200、300”,这样以后您就可以定义-比如说-从“宽度”到210等,并将属性按您需要的排序顺序放入其中。

我为此创建了一个模块。以下是我所做的更改:

MyName/Navigation/Catalog/Model/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_层重写重写重写的函数,添加了以下行:

        $collection->addSetInfo(true);
这样可以确保在需要时加载组数据

接下来的两个更改只允许您访问数据

MyName/Navigation/Catalog/Model/Layer/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;
    }

}
class MyName_Navigation_Catalog_Block_Layer_Filter_Attribute extends Mage_Catalog_Block_Layer_Filter_Attribute {
    public function getGroupName() {
        return $this->_filter->getGroupName();
    }
}
MyName/Navigation/Catalog/Model/Layer/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/Navigation/Catalog/Block/Layer/Filter/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;
    }

}
class MyName_Navigation_Catalog_Block_Layer_Filter_Attribute extends Mage_Catalog_Block_Layer_Filter_Attribute {
    public function getGroupName() {
        return $this->_filter->getGroupName();
    }
}
告诉magento使用我的模块,而不是核心文件。 MyName/Navigation/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>
从模板文件:template/catalog/layer/filter.php 或

$\u过滤器->getGroupName(); 从模板文件:template/catalog/layer/view.php
然后对属性进行分组/排序。

我为此创建了一个模块。以下是我所做的更改:

MyName/Navigation/Catalog/Model/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_层重写重写重写的函数,添加了以下行:

        $collection->addSetInfo(true);
这样可以确保在需要时加载组数据

接下来的两个更改只允许您访问数据

MyName/Navigation/Catalog/Model/Layer/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;
    }

}
class MyName_Navigation_Catalog_Block_Layer_Filter_Attribute extends Mage_Catalog_Block_Layer_Filter_Attribute {
    public function getGroupName() {
        return $this->_filter->getGroupName();
    }
}
MyName/Navigation/Catalog/Model/Layer/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/Navigation/Catalog/Block/Layer/Filter/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;
    }

}
class MyName_Navigation_Catalog_Block_Layer_Filter_Attribute extends Mage_Catalog_Block_Layer_Filter_Attribute {
    public function getGroupName() {
        return $this->_filter->getGroupName();
    }
}
告诉magento使用我的模块,而不是核心文件。 MyName/Navigation/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>
从模板文件:template/catalog/layer/filter.php 或

$\u过滤器->getGroupName(); 从模板文件:template/catalog/layer/view.php
然后从那里对属性进行分组/排序。

嗯,只要更改视图,就可以将它们单独分组。文件是catalog/layer/view.phtml。我想我可以做到。但不是idealUm,只要更改视图,就可以将它们单独分组。文件是catalog/layer/view.phtml。我想我可以做到。但这不是我想要的。我想我还不够清楚。我希望在分层导航块中创建另一个标题(属性组),它将属性分解为多个类别。这不是我想要的。我想我还不够清楚。我希望在分层导航块中创建另一个标题(属性组),它将属性分解为多个类别。看起来很棒。为了让它起作用,我需要做的就是把属性放在正确的属性组中……这不是我想要的,因为分组发生在$\u项中这是特定属性的选项。我需要在更高的层次上执行此操作,即在循环属性之前,我们应该首先循环属性组,如果该组中有可筛选的属性,则打印组名,然后循环属性。我需要在筛选级别访问组信息,因此我将其合并并编辑了我的答案。希望这符合你的要求,如果不符合,我希望它至少能为你指明正确的方向。看起来很棒。为了让它起作用,我需要做的就是把属性放在正确的属性组中……这不是我想要的,因为分组发生在$\u项中这是特定属性的选项。我需要在更高的层次上执行此操作,即在循环属性之前,我们应该首先循环属性组,如果该组中有可筛选的属性,则打印组名,然后循环属性。我需要在筛选级别访问组信息,因此我将其合并并编辑了我的答案。希望这符合你的要求,如果不符合,我希望它至少能为你指明正确的方向。