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');
}
}
यहाँ
हम बच्चे श्रेणी नाम से संग्रह प्रकार सेट बनाते हैं, आप इसे करने के लिए श्रेणी आईडी बदलने के लिए या करने के लिए जोड़ सकते हैं किसी भी श्रेणी विशेषता को संग्रहित करें और इस विशेषता द्वारा क्रमबद्ध करें
->order('child_category_name DESC');
यह सिर्फ नमूना है कि बाल श्रेणियों द्वारा उत्पाद संग्रह को कितनी तेज़ी से सॉर्ट करें, निश्चित रूप से आप टूलबार में विकल्प जोड़ सकते हैं और क्रमशः
और इस सॉर्टिंग के लिए कोड कैसे बनाऊं? –
आपको कोड करने की आवश्यकता नहीं है। इसके परिणामस्वरूप डिफ़ॉल्ट रूप से आरोही क्रम के रूप में परिणाम प्राप्त हो रहा है। – Supravat
जब मैंने देखा कि आपने क्या जवाब दिया है तो मुझे थक गया होगा - क्षमा करें। यह उत्पाद बदलते समय काम की तरह लगता है, इसे कस्टम विशेषता या कुछ और कस्टम के साथ बनाने का एक तरीका होना चाहिए –