我需要代表品牌/制造商展示产品数量
foreach($children as $subCat)
{
$brand_name = $subCat->getName();
$products = Mage::getModel('catalog/product')->getCollection();
$products = $products->addAttributeToFilter('manufacturer',$brand_name);
echo $products->count();
}
答案 0 :(得分:1)
如果品牌为dropdowon or Multi Select attribute
,则您无法按BrandName(That means option name).
进行过滤
您可以按品牌选项ID进行过滤:
$products = Mage::getModel('catalog/product')->getCollection();
$products = $products->addAttributeToFilter('manufacturer',$brand_id);
如果您使用的是Catalog Product flat
,那么您需要从“管理”属性>“将制造商属性启用到Product Listing
”选择制造商属性启用属性到产品列表
根据您的评论,如果您想通过两个粪便进行产品收集,请尝试以下
$_productCollection = Mage::getModel('catalog/product')
->getCollection()
->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left')
->addAttributeToSelect('*')
->addAttributeToFilter('category_id', array(
array('finset' => $catid),
array('finset' => $parent_Cat_id))
)
->addAttributeToSort('created_at', 'desc');
Magento 1.7 Filter products by multiple categories
中的更多详情或者获取Manufacture属性的所有选项列表,然后您可以通过以下代码获取选项ID
$attribute_code = "manufacture";
$attribute_details = Mage::getSingleton("eav/config")->getAttribute("catalog_product", $attribute_code);
$options = $attribute_details->getSource()->getAllOptions(false);
foreach($options as $option){
// print_r($option) and find all the elements e
cho $option["value"];
echo $option["label"];
}