我有以下代码在主页中显示 4 个随机产品,但有时也会显示缺货产品,我该如何避免这种情况?
我们希望在我们的网站上到处展示缺货产品,除了主页。
{{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);