An e-commerce site can hold innumerable products – after all, variety brings more buyers! Creating links for each every one of these products by importing them takes time. Instead we can simply query the database and create product links directly in a jiffy!
// The code below helps create product links via SQL: $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 $write->query("INSERT into $linkTable SET 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."' "); Thanks for reading!