我有一個相當特殊的問題。按類別排序產品(在父類別視圖中)
我那裏有多個類別中設置這樣
收集
....短褲(產品:小16 - 紅色和小20 - BLUE)商店
... 。連衣裙(產品:藍:16,綠19)
如果我在店裏打開收藏我得到這樣
項目藍16
綠19
小16 - RED
小20 - BLUE
我希望我的輸出是這樣的:
小16 - RED
小20 - 藍色
藍色16
綠色19
我如何得到這個結果?我很抱歉,我沒有提供任何代碼,因爲我不知道我應該如何實現這一
我有一個相當特殊的問題。按類別排序產品(在父類別視圖中)
我那裏有多個類別中設置這樣
收集
....短褲(產品:小16 - 紅色和小20 - BLUE)商店
... 。連衣裙(產品:藍:16,綠19)
如果我在店裏打開收藏我得到這樣
項目藍16
綠19
小16 - RED
小20 - BLUE
我希望我的輸出是這樣的:
小16 - RED
小20 - 藍色
藍色16
綠色19
我如何得到這個結果?我很抱歉,我沒有提供任何代碼,因爲我不知道我應該如何實現這一
1上catalog_block_product_list_collection事件創建觀察者
<events>
<catalog_block_product_list_collection>
<observers>
<namespace_module>
<class> namespace_module/observer</class>
<method>collectionList</method>
</namespace_module >
</observers>
</catalog_block_product_list_collection>
</events>
2創建類Namespace_Module_Model_Observer
class Namespace_Module_Model_Observer
{
public function collectionList($observer)
{
/** @var Mage_Catalog_Model_Category $currentCategory */
$currentCategory = Mage::registry('current_category');
$children = Mage::getResourceModel('catalog/category')->getChildrenIds($currentCategory);
if (!$children) {
return $this;
}
$children = implode(',', $children);
/** @var Mage_Catalog_Model_Resource_Product_Collection $collection */
$collection = $observer->getCollection();
$attr = $this->_getAttribute('name');
$collection->getSelect()
->join(
array('c' => $this->_getResource()->getTableName('catalog_category_product')),
"c.product_id = e.entity_id AND c.category_id IN ($children)",
array('child_category_id' => 'category_id')
)
->join(
array('ac' => $this->_getResource()->getTableName('catalog_category_entity_' . $attr['backend_type'])),
"c.category_id = ac.entity_id AND ac.attribute_id = {$attr['attribute_id']}",
array('child_category_name' => 'value')
)
->order('child_category_name DESC');
return $this;
}
protected function _getAttribute($attributeCode, $static = true, $entityTypeId = 3)
{
$readAdapter = $this->_getReadAdapter();
$select = $readAdapter->select()
->from($this->_getResource()->getTableName('eav/attribute'))
->reset(Zend_Db_Select::COLUMNS)
->columns(array('attribute_id', 'backend_type'))
->where('entity_type_id = ?', $entityTypeId)
->where('attribute_code = ?', $attributeCode)
->limit(1);
if (!$static) {
$select->where('backend_type != ?', 'static');
}
$entityId = $readAdapter->query($select)->fetch();
return $entityId;
}
protected function _getResource()
{
return Mage::getSingleton('core/resource');
}
protected function _getReadAdapter()
{
return $this->_getResource()->getConnection('core_read');
}
}
這裏我們設置的子類別名稱集合排序,你可以把它改成類別ID或增加收集任何分類屬性並按此屬性排序
->order('child_category_name DESC');
這只是示例如何快速按子類別對產品集合進行排序,當然您可以在工具欄中添加選項並動態排序集合
我想你應該創建一個從管理屬性,
從管理 - >目錄創建一個屬性custom_order
- >屬性 - >管理屬性。
集中使用產品列表中=是 用於產品上市的排序=是
單獨分配每個產品的位置值。
然後去管理 - >目錄 - >管理類別。
選擇一個類別,單擊顯示設置選項卡上,
集「默認產品列表排序依據」 custom_order
我做一些類似的。
在Magento管理員中,您可以手動設置產品在類別頁面上顯示的順序。
以及如何/我在哪裏爲此排序創建代碼? –
不需要編碼給你。它的默認結果是按升序排列。 – Supravat
當我看到你的迴應時,我一定很累,對不起。 這似乎是很多工作產品改變時,必須有一種方法來使這與自定義屬性或更自定義的東西 –