$product = Mage::getModel(‘catalog/product’)->loadByAttribute(‘sku’,$products);
$data = ”;
$relatedData = $product->getRelatedProductIds();
$insertIt = array();
if(count($relatedData) > 0){
foreach($relatedData as $relatedProduct)
{
$insertIt[$relatedProduct] = array(‘position’=>0,’qty’=>”) ;
}
}
$insertIt[$pr_id]= array(‘position’=>0,’qty’=>”);
try{
$product->setRelatedLinkData($insertIt)->save();
Mage::getSingleton(‘adminhtml/session’)->addSuccess(Mage::helper(‘adminhtml’)->__(‘Product assigned succesfully’));
}
catch(Exception $e)
{
Mage::getSingleton(‘adminhtml/session’)->addError(Mage::helper(‘adminhtml’)->__(‘There is problem with products, please refresh the page to see the result’));
}

By admin

Leave a Reply

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