【发布时间】:2013-09-13 19:02:12
【问题描述】:
我有以下代码,在主页显示 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);
【问题讨论】:
-
看看这里:stackoverflow.com/questions/3283223/… 您只需将
0替换为1。
标签: php magento zend-framework magento-1.7 magento-1.4