Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/249.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何根据magento中的库存状态对产品集合进行排序_Php_Xml_Magento_Zend Framework_Magento 1.9 - Fatal编程技术网

Php 如何根据magento中的库存状态对产品集合进行排序

Php 如何根据magento中的库存状态对产品集合进行排序,php,xml,magento,zend-framework,magento-1.9,Php,Xml,Magento,Zend Framework,Magento 1.9,我想在分类页面上对产品集合进行排序,以便库存产品出现在缺货产品之前。所有缺货产品将显示在库存产品之后。我已经重写了Mage_Product_Block_列表块 You can use catalog_product_collection_load_before event. And in the observer: public function modifyProductCollection(Varien_Event_Observer $observer) { //catalo

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

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');
}