【问题标题】:How to sort product collection on stock status in magento如何在magento中根据库存状态对产品集合进行排序
【发布时间】:2016-09-03 07:59:41
【问题描述】:

我想在类别页面上对产品集合进行排序,以便库存产品出现在缺货产品之前。所有缺货产品将在有货产品之后显示。我已经重写了 Mage_Product_Block_List 块。

【问题讨论】:

    标签: php xml magento zend-framework magento-1.9


    【解决方案1】:
    You can use catalog_product_collection_load_before event.   
    And in the observer:
    
    public function modifyProductCollection(Varien_Event_Observer $observer) {
        //catalog_product_collection_load_before
        $collection = $observer->getCollection();
    
        $collection->getSelect()->joinLeft(
                    array('_inventory_table' => $collection->getTable('cataloginventory/stock_item')),
                    "_inventory_table.product_id = e.entity_id",
                    array('is_in_stock')
                )
                ->order('is_in_stock DESC')
                ->order('created_at DESC');
    }
    

    【讨论】:

      猜你喜欢
      • 2013-01-15
      • 2015-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多