Add related products programmatically Magento

Add related products programmatically Magento

In this post we will show you Add related products programmatically Magento, hear for Add related products programmatically Magento we will give you demo and example for implement.

How to related products Add programmatically Magento

we will show you How to Add related products to the Magento by code or script. For related products Add programmatically you need this code.

// if call is come form external file
require_once '../app/Mage.php';

// your Sku
$set_sku = 'onlinecode';
$get_product = Mage::getModel('catalog/product')->loadByAttribute('sku',$set_sku);

// add sku in string or other way to
// get the array of related product sku
$related_products = "5689,965";
$related_products_array = explode(',', $related_products);

$params = array();
$related_counter = 1;
$Product    = Mage::getModel('catalog/product')->loadByAttribute('sku', $set_sku);
$main_product = Mage::getModel('catalog/product');

foreach($related_products_array as $sku_value)
$related_product = Mage::getModel('catalog/product')->loadByAttribute('sku', $sku_value);

$params[$related_product['entity_id']] = array(
'position'     => $related_counter



echo "Add related products programmatically updated successfully ";


Hope this code and post will helped you for implement Add related products programmatically Magento. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve onlincode. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

Leave a Comment

Your email address will not be published. Required fields are marked *

29  +    =  30

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US