簡體   English   中英

Magento 中分層導航的類別

[英]Categories for layered navigation in Magento

我希望增強 Magento 中的分層導航。

目前,分層導航中使用的屬性無法分組,這意味着如果您有多個邏輯上屬於一組的屬性(即屬性“高度”、“寬度”和“深度”,即“尺寸”和“顏色” ”和“紋理”屬於“外觀”部分)。

我認為這將增強用戶的可用性和導航。

在我繼續為此開發模塊之前,我想知道是否有人遇到過這樣的 magento 問題,如果沒有,您有什么建議嗎?

約瑟夫

我為此創建了一個模塊。 以下是我所做的更改:

我的名字/導航/目錄/模型/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 使用我的模塊而不是核心文件。 我的名字/導航/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 和 Group/Sort 從那里的屬性。

過濾導航的代碼已經在 Magento 論壇上很久了,它仍然適用於最新版本:

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

這可能會提供您自定義過濾導航的外觀以滿足您的需要所需的內容。

您還可以在屬性中定義分層導航中的排序順序。 而不是使用 '1, 2, 3' 改為 '100, 200, 300' 以便稍后您可以定義 - 例如 - 'width' 到 210 等,並將屬性插入到您需要的排序順序中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM