简体   繁体   English

如何在magento主页中不显示缺货的产品

[英]How not to show out of stock products in magento homepage

I have the following code which shows 4 random products in the homepage, however its also showing sometimes out of stock products, how can I avoid that? 我有以下代码,该代码在首页中显示4种随机产品,但是有时也显示缺货产品,如何避免这种情况?

We want to show out of stock products on our website everywhere, except in the homepage. 我们希望在网站上除首页之外的所有地方展示缺货的产品。

{{block type="catalog/product_list" category_id="108" template="catalog/product/list_home.phtml"}} {{block type =“ catalog / product_list” category_id =“ 108” template =“ catalog / product / list_home.phtml”}}

 $_helper = $this->helper('catalog/output');
 $_category = Mage::getModel('catalog/category')->load($this->getCategoryId());
 $_productCollection = Mage::getResourceModel('reports/product_collection')
                       ->addAttributeToSelect('*')
                       ->addCategoryFilter($_category)
                       ->setVisibility(array(2,3,4));
 $_productCollection->getSelect()->order(new Zend_Db_Expr('RAND()'));                  
 $_productCollection->setPage(1, 4);

Luis Valencia 路易斯·瓦伦西亚

I think In magento you can create a Featured category for home page product. 我认为您可以在magento中为首页产品创建“特色类别”。 where you can shows only that product which is featured category. 在这里,您只能显示属于特色类别的产品。 and you add there only in stock product 并且您只在库存产品中添加

Its easiest way in magento showing a featured product. 在magento中,最简单的方法就是展示特色产品。

How to create featured product in magento. 如何在magento中创建特色产品。 http://www.magentocommerce.com/wiki/5_-_modules_and_development/catalog/how_to_create_a_featured_product http://www.magentocommerce.com/wiki/5_-_modules_and_development/catalog/how_to_create_a_featured_product

foreach ($_productCollection as $_product) foreach($ _productCollection作为$ _product)

then you can use $_product->isInStock() or $_product->isSaleable() function as if and else condition 那么您就可以使用$ _product-> isInStock()或$ _product-> isSaleable()函数,好像和其他条件一样

Thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM