Here is a simple way of adding product link such as Related, Upsell and Crosssell Link to a product in Magento. I just got the way of doing this and thought to share! So kind of me :)

/**
First Create Link Array of following type
**/

$linkArray=array(‘product_id’=>array(‘position’=>’’));

/**
Then set the Link Data
**/

/** For Upsell Link**/
$product->setUpSellLinkData($linkArray);

/** For Crosssell Link**/
$product->setCrossSellLinkData($linkArray);

/** For Crosssell Link**/
$product->setRelatedLinkData($linkArray);

$product->save();

Hope this helps.

© Subesh Pokhrel's Blog – Magento Development Tips,PHP,Google Maps

  • Share/Bookmark

Related Post

Tags: ,

4 Responses


  1. Rameez on 18 Feb 2010

    Hey subesh,
    could u plz explain, where should i put this code and in which field? and also that what changes we should bring to csv to update those related products into the product page?
    thanks.
    reply.

    • Subesh Pokhrel on 18 Feb 2010

      Hi,
      I think you want to created these product links during importing of product via CSV files. If yes then, you should add these code inside saveRow function of the Product Adapter used during product import.

      But remember you can only create a link to the product if only that product is already imported during import.

      Any further questions plz don’t hesitate to ask.

  2. Simone on 08 Mar 2010

    Hi Subesh,
    I can’t understand how it will appear the $linkArray variable. Could you give me an idea? I’m using a ProductImport advanced profile full of details, but the upsell and crossell fields are not updated.

    This is the print_r of an example of my $linkArray
    Array ( [4518] => Array ( [position] => ) [4517] => Array ( [position] => ) [5347] => Array ( [position] => ) [5348] => Array ( [position] => ) [5346] => Array ( [position] => ) [5345] => Array ( [position] => ) [5349] => Array ( [position] => ) )

    Please, let me know!

    • Subesh Pokhrel on 08 Mar 2010

      Hi,
      I think that is the correct format of the array you have to set in parameter of the the linking function.
      Are you sure you already have the product ids in the array’s key imported already in Magento? That might be your problem. Next you might have forgotten to save ( ) the product. Can be anything.. Please review your code once again or else plz do send me your code ( If you want) so that I can give a look .
      Thanks.


Leave your comment


Search engine optimization by SEO Design Solutions