I’ve already made a post in this blog about Adding Related Product and other links to Product in Magento . But when I used the method to creating links among product’s, while importing very large number of products and creating large number of product links, it took a lot of time and resource. So I thought why not give it a try by direclty creating a link using SQL? And YES! it worked.
Below is the code how I created those links using Custom SQL. But I have to tell you that the former methods looks organized, this is just a work around to a situation. You might know what I am trying to say!
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
$resource = Mage :: getSingleton( 'core/resource' );$read= $resource -> getConnection( 'core_read' );$write= $resource->getConnection('core_write');$linkTable=$resource->getTableName('catalog/product_link');// Creating Upsell Product link product_id='".$productId."', linked_product_id='".$linkProduct."', link_type_id='".Mage_Catalog_Model_Product_Link::LINK_TYPE_UPSELL."' ");// Creating Related Product link$write->query("INSERT into $linkTable SET product_id='".$productId."', linked_product_id='".$linkProduct."', link_type_id='".Mage_Catalog_Model_Product_Link::LINK_TYPE_RELATED."' ");// Creating Crosssell Product Link$write->query("INSERT into $linkTable SET product_id='".$productId."', linked_product_id='".$linkProduct."', link_type_id='".Mage_Catalog_Model_Product_Link::LINK_TYPE_CROSSSELL."' "); |
