I'm trying to search for all the tags assigned to a particular product, and using this code to do so:

    $model = Mage::getModel('tag/tag');
    $prod_collection = $model->getResourceCollection()
        ->addProductFilter((int) $productId)
        ->setFlag('relation', true)
        ->addStoreFilter((int) $store['id'])

$store['id'] is 1, and $productId is 13065 (a product that I assigned a couple of tags directly using the backend).

The content of tag_relations if searching for product_id = 13065 is this: tag_relations

As you can see the product has a couple tags assigned on store = 1, and another one assigned on store = 9.

But the above search returns an empty set. I checked the produced SQL and I see that what I'm getting is:

SELECT `main_table`.*, `summary_store`.* FROM `tag` AS `main_table`
 LEFT JOIN `tag_relation` AS `relation` ON main_table.tag_id = relation.tag_id
 LEFT JOIN `tag_summary` AS `summary_store` ON main_table.tag_id = summary_store.tag_id 

 WHERE (main_table.status = 1)
    AND (`relation`.`product_id` = 13065)
    AND (summary_store.store_id IN (1))
    AND (relation.store_id IN (1))
    AND (relation.active = 1)

 GROUP BY `main_table`.`tag_id`, `main_table`.`tag_id`

And I see that it fails because the contents of tag_summary are: tag_summary

where apparently every summary line is stored with store_id = 0, instead of saving one line per store.

How can I change my search so it doesn't join against tag_summary, and only against tag_relations? Does the content of my tag_summary look alright, or should I have a summary line per each store view?


It would seem that the problem is that the corresponding summary lines aren't being generated. I created my tags using the admin, in Catalog->Manage Tags, and assigned the tags to arbitrary products, but it only creates the summary lines for Store ID 0... :(

1 Answer 1


I ended up rewriting my search as:

$model         = Mage::getModel('tag/tag');
$tagCollection = $model->getResourceCollection()

$tagCollection->getSelect()->where('relation.store_id IN (?)', $store['id']);

I don't like this solution very much, and I still think something is wrong on how the summary lines are being saved, but can't find any documentation on how to proceed. Leaving this up until a better answer comes along.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.