But there must be a way to add them as a batch, right? Absolutely! These relationships are in fact stored in the Magento database, within the "catalog_product_link" table, and Magento is very particular about the way in which these relationships are inserted and handled.
Here is a set of typical insert statements to create some relationships among products:
INSERT INTO `catalog_product_link` VALUES (35,269,206,1);
INSERT INTO `catalog_product_link` VALUES (36,269,210,1);
INSERT INTO `catalog_product_link` VALUES (37,339,284,1);
INSERT INTO `catalog_product_link` VALUES (38,339,218,1);
INSERT INTO `catalog_product_link` VALUES (39,383,280,1);
INSERT INTO `catalog_product_link` VALUES (40,334,356,1);
INSERT INTO `catalog_product_link` VALUES (41,334,228,1);
INSERT INTO `catalog_product_link` VALUES (42,334,222,1);
INSERT INTO `catalog_product_link` VALUES (43,368,226,1);
INSERT INTO `catalog_product_link` VALUES (44,368,299,1);
INSERT INTO `catalog_product_link` VALUES (45,368,230,1);
The first parameter is the "id" of the relationship, and yes it has to be in order. My catalog_product_link table already had 34 entries in it, most of which were created during testing. Actually my table only had 32,33, and 34 in it. I deleted the first 31, since they were bogus and used for testing. As I attempted to start over with 1, Magento crash.
TIP: It's very important to retain the ordering of this table.
The second parameter is the ID of the product that is being assigned the relationships.
The third parameter is the ID of the product being assigned as a related product to the second parameter.
The fourth parameter is the "link type". Link type '1' indicates that the entry is representative of a "related product". A link type of '4' is an upsell, and is handled in exactly the same way.
And this is how I batch imported 700 or so product relationships using phpmyadmin and some relatively clever macro programming.
IMPORTANT TIP: PRODUCT IDs
For some probably logical but completely elusive reason (correct me if I'm wrong), Magento's catalog export seem to include the product ID numbers of each product. It exports the SKU, which is used by the store operators. I am not a store operator.
Do yourself a favor and create a product id attribute that you can then export. Nothing fancy, just call it backend_id, and set it manually if you have to when you create a product.
Note that Magento assigns the ID, and not always in a way that makes sense. Just because the product you created yesterday had an ID of 385 doesn't mean the product you add today will have an ID of 386. It might be 390, or 391. I'm not sure why. I don't care why. I don't have time to care.
COMMENTARY (because it's my show)
When I created this blog I imagined I would have the time to update it often, but I've just been too busy! I've got a theory about people in technology who do a lot of blogging: they've got a lot of time on their hands...and do a lot of regurgitating posts from other blogs in an effort to inflate their professional credentials.
Consequently I will be updating this blog rarely. But when I do, I hope to provide someone with something of use.
nice article about magento related product this article more useful to magento shopping cart vendors. magento eCommerce site is global enterprise Magento Developers
ReplyDeleteThank for sharing such a great blog. All the information which you provide is amazing.
ReplyDeleteFor more information about the magento programming can check it