通过产品属性和目录获取产品
public function getProducts()
{
$categories = $this->helper('specific')->getAllCategories();
$hightlightProducts = array();
if($categories)
foreach($categories as $category_id)
{
$collection = Mage::getModel('catalog/product')->getCollection();
$category = $this->helper('specific')->getCategoryModel()->load($category_id);
$items = $collection->addCategoryFilter($category)
->addAttributeToSelect('*')
->addAttributeToSelect('selection_accueil')
->addAttributeToFilter('status','1')
->addAttributeToFilter('selection_accueil','1')->getItems();
if(!empty($items))
{
$key = array_rand($items);
$hightlightProducts[$category_id] = $items[$key];
}
}
return $hightlightProducts;
}
public function getAllCategories()
{
return $this->getCategoryModel()->getTreeModel()->load()->getCollection()->getAllIds();
}
public function getCategoryModel()
{
return Mage::getModel('catalog/category');
}