Subesh Pokhrel's Blog – Magento Development Tips,PHP,Google Maps
PHP & Magento Tips & Tutorials
Share

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.

  • Share/Bookmark

You may also be interested

Comments

4 Responses to “Adding Related Product and other links to Product in Magento”

  1. 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 says:

      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. 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 says:

      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.

Write a Comment

Search engine optimization by SEO Design Solutions