Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Magento产品按类别分类_Magento_Magento 1.5 - Fatal编程技术网

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')不适用于我