Search code examples
magentomoduletagsmagento-1.9php

how to get Product Tag id


I want to get 8 product using by tag how to get current product tag 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());

Solution

  • there are two way to put limit on collection.

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

    or

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