我正在尋找增強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