在 Magento 中获取产品集合,按类别和自定义属性值过滤

Dha*_*val 0 magento

我正在创建 magento API,所以现在我需要从类别 id 和目录属性 id 中获取产品集合。

例如:我的类别名称为 test ,id 为 1 。此外,我还设置了属性color(来自catalog->attributes->manage attributes),并为此颜色属性设置了值,例如white, blue, black

现在我添加了一些产品,它的类别是 test (id=1) 并且设置了 color 属性white

我的问题是:现在我想获取类别 id1和颜色为的产品集合white

我怎样才能得到这个集合。提前致谢

Mah*_*awy 5

<?php
// load category object by category ID
$category = Mage::getModel('catalog/category')->load(1);

// get product collection, filter it by category, 
// add the color attribute to select to be able to filter using it later
$productCollection = Mage::getResourceModel('catalog/product_collection')
                       ->addCategoryFilter($category)
                       ->addAttributeToSelect('color')
                       ->addFieldToFilter(array(
                           array('attribute'=>'color','eq'=>'white'),
                       ));
Run Code Online (Sandbox Code Playgroud)

更多信息检查

如何从 magento 电子商务中的特定类别中获取产品

Magento - 检索具有特定属性值的产品

https://magento.stackexchange.com/questions/5838/get-product-collection-from-a-category-id