如果它缺货,如何隐藏主页的新产品或特色产品 - Magento 1.7
-
12-12-2019 - |
题
我在我的主页上显示了新的和特色产品。我想只展示有货的产品。如果产品被标记为新的或特色,那么它将在此股票(具有大于零的库存)。
这个要求只是为了主页,在其他页面上,我想展现出股票产品。
此方法不起作用:系统/配置/目录/库存产品脱离库存产品 - 否
如何做到这一点?
谢谢!
解决方案
marius,
请从 admin>系统>索引管理。
基本上,您可以通过
过滤任何产品集合Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($collection);
.
但它取决于System/Configuration/Catalog/Inventory/Display Out of Stock Products -NO
如果不起作用,请尝试此
/* $collection=Your Product Collection */
$cond = array(
'{{table}}.use_config_manage_stock = 0 AND {{table}}.manage_stock=1 AND {{table}}.is_in_stock=1',
'{{table}}.use_config_manage_stock = 0 AND {{table}}.manage_stock=0',
);
$cond[] = '{{table}}.use_config_manage_stock = 1 AND {{table}}.is_in_stock=1';
$collection->joinField(
'inventory_in_stock',
'cataloginventory/stock_item',
'is_in_stock',
'product_id=entity_id',
'(' . join(') OR (', $cond) . ')'
);
.