5

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?

  • I ended up doing it manually since there wasn't a response fast enough. it was just as easy and fast copy and paste them as a guest user into the product page and then using the admin to panel to approve all pending tags. – Jason Aug 4 '15 at 18:05
0

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 and tag_relation by hand, but I don't know how to do this exactly.

  • thanks @fabian b! Didn't use this as it was as easy and time saving to drop the tags into the product page and approve as it was to create the array. – Jason Aug 4 '15 at 18:06
2

Tags themselves are saved in the table tag, the relation with products and customers is stored in tag_relation.

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 $model->getRelatedProductIds().

0

It might be worth looking into an extension such as this one.

http://www.magentocommerce.com/magento-connect/import-export-product-tags-easy-tags-bulk-product-tags.html

There may also be open source extensions available that I'm not aware of.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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