I've got a list of several configurable products that need product tags added. There are about 15-20 tags per product and close to 50 separate products.
Is there a way to import the tags or run a SQL command to add them?
The easiest is to just use
\Mage_Tag_Model_Api::add. I never used it, but from reading the code the parameter should be:
$data = [ 'customer_id' = 123, 'product_id' => 321, 'store' => 1, 'tag' => [ 'shoe', 'pullover', 'elephpant', ] ];
The alternative is to fill
tag_relation by hand, but I don't know how to do this exactly.
Tags themselves are saved in the table
tag, the relation with products and customers is stored in
If you already have the tags created you can run a simple query
INSERT INTO `tag_relation` (`tag_id`, `customer_id`, `product_id`, `store_id`, `active`, `created_at`) VALUES ([tag id], null, [product ID], 1, 1, '2015-06-27 15:53:00');
And just add a line per product & tag.
If you also need to create the tags in the query it might be a bit more tricky. I would use the Magento
Tag module and check the save method in
Mage_Adminhtml_TagController to see what Magento does.
Basically something like this should work (untested so please don't run it on production without testing)
$model = Mage::getModel('tag/tag'); $model->addData(array( 'name' => '[the name]', 'status' => 1, 'base_popularity' => 0, 'store' => [store_id] )); $model->setData('tag_assigned_products', array([id of product],[id of product])); $model->save();
In order to add to existing relations (instead of replacing currently assigned products), you need to include them in the array of IDs you specify with
tag_assigned_products, which you can obtain with
It might be worth looking into an extension such as this one.
There may also be open source extensions available that I'm not aware of.