2011-11-10 76 views
0

我需要基于特定标签在productCollection上自定义过滤器。 因此,让我们假设我有以下productCollection:Magento过滤器产品按特定标签收集

<pre> 
$collection_featured_products = Mage::getModel('catalog/product')->getCollection() 
->addCategoryFilter(Mage::registry('current_category')) 
->addAttributeToSelect('*')  
->addAttributeToFilter('featured_product', 1); 
</pre> 

OR productCollection从产品列表页:

 
    $_productCollection = $this->getLoadedProductCollection() 
    ->addAttributeToSelect('location'); 
    $_helper = $this->helper('catalog/output'); 
我如何添加一个特定的标签来过滤让所有包含该标记的产品。 如果我不能在productCollection中筛选,也许我可以使用标记表进行连接?如果真的,请举例。 PS:如果你需要的话。我有Magento版本。 1.5.0.1

谢谢补充!

回答

0
$tagId = 3; //Mage::getModel('tag/tag')->loadByName($tagName)->getId(); 

$products = Mage::getResourceModel('tag/product_collection') 
       ->addAttributeToSelect('sku') 
       ->addAttributeToSelect('name') 
       ->addTagFilter($tagId); 

print_r($products->getData());