获取Magento中的产品系列,并按类别&过滤自定义属性值 [英] Get product collection in Magento, filtered by Category & Custom Attribute Value

查看:118
本文介绍了获取Magento中的产品系列,并按类别&过滤自定义属性值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am creating magento API so now I need to get product collection from category id and catalog attribute id.

例如: 我有名称为test且ID为1的类别.另外,我已经设置了属性color(来自catalog->attributes->manage attributes),并且已经为此颜色属性设置了值,例如whiteblueblack.

for ex : I have category with name test and id is 1 . Also I have set attribute color (from catalog->attributes->manage attributes) and I have set values for this color attribute like white , blue , black.

现在我添加了一些产品,其类别为test(id = 1),并且颜色属性设置为white.

now I add few product and it's category is test (id=1) and color attribute is set white.

我的问题是: 现在,我要获取类别ID为1并且颜色为white的产品集合.

My Question is : Now I want to get product collection for whom category id is 1 and color is white.

如何获取此收藏集. 预先感谢

How can I get this collection. Thanks in advance

推荐答案

<?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'),
                       ));

更多信息检查

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

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

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

这篇关于获取Magento中的产品系列,并按类别&amp;过滤自定义属性值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆