2012-06-07 209 views
1

我需要排列productCollection产品清单CategoryMagento产品排序产品分类

我需要这个工具,因为在我的地盘我一定要显示新产品在单独的页面(标签)特殊产品

我甚至可以用addAttributetoSort()skunews_to_datenews_from_datenameprice等,但不能使用category_id。它没有效果。

我知道我可以从管理面板中设置它在管理属性。在管理属性price,name可用于排序。即使我可以从管理属性创建sku,news_to_date等属性。但是,当我创建属性代码categorycategory_id,它带有像

System reserved category/category_id 

指的错误,我不能使用categorycategory_id作为属性从管理属性(因为它们是由系统预留)。

任何人都可以建议如何做到这一点?

回答

1

我敢肯定,这会按类别进行排序:

$collection = Mage::getModel('catalog/product')->getCollection() 
    ->addAttributeToSort('category_ids', 'ASC') 
    ->addAttributeToSelect(array('name', 'sku', 'status', 'visibility', 'is_saleable')) 
; 
+0

您应该编辑您的anwser因为没有名为'属性category_idS' 。正确的名称是'category_id' – RPDeshaies

+0

- > addAttributeToSort('category_id','ASC')不适用于我 – Bogz

-1

这对我的作品:

$category ='1503'; // Is in my case Categoryid of New Products Category 

    $_products = Mage::getResourceModel('catalog/product_collection') 
    ->joinField('category_id','catalog/category_product','category_id','product_id=entity_id',null,'left') 
    ->addAttributeToFilter('category_id', array('in' => $category)) 
    ->addAttributeToSelect('*'); 

    $_products->load(); 

问候