【问题标题】:Magento filter productCollection by a specific tagMagento 按特定标签过滤 productCollection
【发布时间】:2011-11-10 13:54:25
【问题描述】:

我需要根据特定标签对 productCollection 进行自定义过滤。 所以让我们假设我有以下 productCollection:

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

或产品列表页面中的 productCollection:

$_productCollection = $this->getLoadedProductCollection() ->addAttributeToSelect('位置'); $_helper = $this->helper('目录/输出'); 如何按特定标签添加过滤器以获取包含该标签的所有产品。 如果我无法在 productCollection 中过滤,也许我可以加入标签表?!如果属实,请举例。

PS:如果你需要。我有 Magento 版本。 1.5.0.1

感谢补充!

【问题讨论】:

    标签: magento


    【解决方案1】:
    $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());
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-25
      • 2012-11-28
      • 1970-01-01
      • 2011-09-15
      相关资源
      最近更新 更多