我正在使用Magento 1.9,我在/app/code/local/Mage/Catalog/Block/Product/List.php中使用了这个代码行:
$this->_productCollection = $layer->getProductCollection()
->joinField(
'inventory_in_stock',
'cataloginventory_stock_item',
'is_in_stock',
'product_id=entity_id',
'is_in_stock>=0',
'left')
->setOrder('inventory_in_stock','desc');
但没有发生任何事情。
有人能帮助我吗? 提前谢谢!
答案 0 :(得分:0)
您必须添加以下代码:
$this->getSelect()->joinLeft(
array('_inventory_table'=>$this->getTable('cataloginventory/stock_item')),
"_inventory_table.product_id = e.entity_id",
array('is_in_stock', 'manage_stock')
);
$this->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());
$this->getSelect()->order('on_top DESC');
就在
之前if ($attribute == 'price' && $storeId != 0) {
in app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Collection.php
如果你有Magento app/code/core/Mage/Catalog/Model/Resource/Product/Collection.php
1.7.0.0
或者你可以使用这个magento模块
http://www.magentocommerce.com/magento-connect/show-out-of-stocks-products-at-bottom.html