Magento 中的分层导航类别

发布于 2024-11-06 10:12:05 字数 225 浏览 1 评论 0原文

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

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

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

在我继续为此开发模块之前,我想知道是否有人遇到过类似的 magento 功能,如果没有,您有什么建议可以做到这一点吗?

约瑟夫

I'm looking to enhance the layered navigation in Magento.

Presently, attributes that are used in layered navigation can't be grouped, meaning if you have several attributes that are logically in one group (i.e. attributes "height", "width" & "depth" which are "Dimensions", and "color" and "texture" belong in an "Appearance" section).

I think this would enhance the usability and navigation for users.

Before I go ahead and begin developing a module for this, I was wondering if anyone came across something like this for magento, and if not, do you have any tips how this should be done?

Joseph

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦言归人 2024-11-13 10:12:05

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

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_Layer 中的重写函数,并添加了以下行:

        $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;
    }

}

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_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>

调用

$_item->getGroupName();

现在您可以从模板文件中 :template/catalog/layer/filter.php

$_filter->getGroupName();
来自您的模板文件:template/catalog/layer/view.php
并对属性进行分组/排序。

I created a module for this. Here are the changes I made:

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;
    }
}

I'm just rewriting the overridden function from Mage_Catalog_Model_Layer with that addition of the line:

        $collection->addSetInfo(true);

This ensures that the group data will be loaded when I need it.

The next two changes just allow you to access the data.

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;
    }

}

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_Block_Layer_Filter_Attribute extends Mage_Catalog_Block_Layer_Filter_Attribute {
    public function getGroupName() {
        return $this->_filter->getGroupName();
    }
}

Tell magento to use my module and not the core files.
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>

Now you can call

$_item->getGroupName();

from your template file: template/catalog/layer/filter.php
or

$_filter->getGroupName();
from your template file: template/catalog/layer/view.php
and Group/Sort the attributes from there.

梦里梦着梦中梦 2024-11-13 10:12:05

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

http://www.magentocommerce.com/boards/viewthread/5500/

这可能会提供您自定义过滤导航的外观以满足您的需求所需的内容。

您还可以在属性中定义分层导航中的排序顺序。不要使用“1、2、3”,而是使用“100、200、300”,以便稍后您可以将“宽度”定义为 210 等,并将属性插入到您需要的排序顺序中。

The code for the filtered navigation has been on the Magento forums for a long time, it still works in the most recent versions:

http://www.magentocommerce.com/boards/viewthread/5500/

This may provide what you need to customise the appearance of the filtered navigation to suit your needs.

You can also define in your attribute the sort order in the layered navigation. Rather than use '1, 2, 3' go for '100, 200, 300' so that later on you can define - say - 'width' to 210, etc. and slot the attributes in to the sort order you need.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文