通过产品属性和目录获取产品

piaoling  2011-07-18 10:37:38

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');
    }

类别 :  magento(258)  |  浏览(3912)  |  评论(0)
发表评论(评论将通过邮件发给作者):

Email: