0

I tried to update the related product via script in magento 1.9.3.7 but i am getting one error. I don't have an idea related to this error.

<?php
ini_set("display_errors", 1);
//require dirname(__FILE__) . '/app/Mage.php';
require_once ( "app/Mage.php" );
Mage::app();
umask(0);
//$product = Mage::getModel('catalog/product')->loadByAttribute('sku','KU7');
$productCollection = Mage::getModel('catalog/product')->getCollection();

$i = 1;
foreach ($productCollection as $product2) {
    $sku = $product2->getSku();
    $id = $product2->getData()['entity_id'];
    if(!empty($id))
    {
        //$product = Mage::getModel('catalog/product')->loadByAttribute('sku',$product2->getSku());
        $product = Mage::getModel('catalog/product')->load($id);

        $data = ”;
        $relatedData = array(58,108,109,110);

         $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();
            echo $i;
            echo "\n";
            $i++;
         }
         catch(Exception $e)
         {
            echo $e;
         }
    }
}
?>

Error:

Fatal error: Cannot redeclare a48bf1b50() (previously declared in /html/lib/Zend/Validate/Hostname/Com.php:1) in /html/lib/Zend/Validate/Hostname/Com.php on line 1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.