将MAGENTO中的PRODUCT产品进行排序,有货的在前,无货的在后

在product collision后面加入对产品是否有货的排序

            //add code for product collection sort by stock
            $productColl->getSelect()->joinLeft(
                array('_inventory_table'=>$productColl->getTable('cataloginventory/stock_item')),
                "_inventory_table.product_id = e.entity_id",
                array('is_in_stock', 'manage_stock')
            );
            $productColl->addExpressionAttributeToSelect('on_top',
                '(CASE WHEN (((_inventory_table.use_config_manage_stock = 1) AND (_inventory_table.is_in_stock = 1)) OR  ((_inventory_table.use_config_manage_stock = 0) AND (1 - _inventory_table.manage_stock + _inventory_table.is_in_stock >= 1))) THEN 1 ELSE 0 END)',
                array());
            $productColl->getSelect()->order('on_top DESC');

你可能感兴趣的:(将MAGENTO中的PRODUCT产品进行排序,有货的在前,无货的在后)