我正在尝试使用magento 2中的属性过滤器获取特定类别的产品集合,例如:颜色,大小,性别。
我的代码:
$c_id = $categoryid;
$category = $this->_category;
$product = $this->_product;
$category->load($c_id);
//~ var_dump($category->getData());die;
$collection = $category->getProductCollection()->addStoreFilter($store_id)->addAttributeToSelect('*')->addAttributeToFilter('type_id', array(
'in' => array(
'simple',
'virtual',
'bundle',
'downloadable',
'grouped',
'configurable'
)
))->addAttributeToFilter('visibility', 4)->addAttributeToFilter('status', 1)->addAttributeToSort($sortType, $sortOrder);
$collection->addAttributeToFilter('gender', 82)->addStoreFilter();
var_dump($collection->getSize());die;
return 0;
请帮帮我。