2015-11-16 194 views
0

我想通過標籤獲得8個產品如何獲得當前產品標籤ID。如何獲得產品標籤ID

$tagId = 1; // I want to get id on view.html 
    $collection = Mage::getResourceModel('tag/product_collection') 
    ->addAttributeToSelect('sku') 
    ->addAttributeToSelect('name') 
    ->addTagFilter($tagId); 
    print_r($collection->getData()); 

回答

1

有兩種方法可以限制收集。

$tagId = 1; // I want to get id on view.html 
     $collection = Mage::getResourceModel('tag/product_collection') 
     ->addAttributeToSelect('sku') 
     ->addAttributeToSelect('name') 
     ->addTagFilter($tagId) 
     ->setPageSize(8); 

$collection = Mage::getResourceModel('tag/product_collection') 
     ->addAttributeToSelect('sku') 
     ->addAttributeToSelect('name') 
     ->addTagFilter($tagId); 
$collection->getSelect()->limit(8); 
+0

感謝您的幫助,但我想標籤識別動態只得到有關產品 –

+0

這些標籤ID看到這個問題http://stackoverflow.com/questions/18742046/how-to-get-only-the-tags-of-a-product-in-view-phtml-in-magento-1-7-0-2 –

+0

其罰款,但我可以使用數組 - > addTagFilter($ tagId); –

0

我認爲你是後addProductFilterMage_Tag_Model_Entity_Customer_Collection

$model = Mage::getModel('tag/tag')->getCollection() 
    ->addProductFilter($ProductId) 
    ->setFlag('relation', true) 
    ->addStoreFilter(Mage::app()->getStore()->getId()) 
    ->setActiveFilter();