Magento产品按类别分类
我需要按Magento产品按类别分类,magento,magento-1.5,Magento,Magento 1.5,我需要按类别对productCollection中的产品列表进行排序 我需要这个设施,因为在我的网站上,我必须在单独的页面(选项卡)中显示新产品和特殊产品 我甚至可以使用addAttributetoSort()作为sku,news\u to\u date,news\u from\u date,name,price等,但不能使用类别id。它没有效果 我知道我可以在管理属性的管理面板中设置它。在管理属性中价格,名称可用于排序。甚至我也可以在fromManage attribute中创建sku、new
类别对productCollection
中的产品列表进行排序
我需要这个设施,因为在我的网站上,我必须在单独的页面(选项卡)中显示新产品和特殊产品
我甚至可以使用addAttributetoSort()
作为sku
,news\u to\u date
,news\u from\u date
,name
,price
等,但不能使用类别id
。它没有效果
我知道我可以在管理属性的管理面板中设置它。在管理属性中价格
,名称
可用于排序。甚至我也可以在fromManage attribute中创建sku
、news\u to\u date
等属性。但是当我将属性代码创建为category
或category\u id
时,会出现如下错误
System reserved category/category_id
表示我无法使用类别
或类别id
作为管理属性中的属性(因为它们是系统保留的)
有人能建议怎么做吗?我相信这会按类别排序:
$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSort('category_ids', 'ASC')
->addAttributeToSelect(array('name', 'sku', 'status', 'visibility', 'is_saleable'))
;
这对我很有用:
$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();
关于您应该编辑您的anwser,因为没有名为category\u id的属性
。正确的名称是category\u id
->addAttributeToSort('category\u id','ASC')不适用于我