0

I am trying to upload product images using csv .

    if ($key === 'image') {
         if (trim($data[$key])) {
              $img_path = $base_dir . "/media/catalog/product/" . trim($data[$key]);  

    if (file_exists($img_path)) {

       try { 
           $p->addImageToMediaGallery($img_path, array( 'image',  'small_image',  'thumbnail' ) , false, false);

           $p->setThumbnail($p->getImage());
           $p->setSmallImage($p->getImage());
           $p->setImage($p->getImage());                                            $p->setThumbnail(Mage::helper('catalog/image')->init($p, array('thumbnail','small_image','image')));

          $p->save();
        }
       catch(Exception $e) {
           Mage::log('Exception Arrised in Updating Product with sku ' . $sku . " Exception " . $e->getMessage() , null, date('Y-m-d--H', strtotime('now')) . "__" . 'product_create_error.log');
        $i++;
          continue;
     }

  }
}
}else{
     if (trim($data[$value])) {
          $p->setData($key, trim($data[$value]));
      }
   }
}

this is my code but it is not saving the image.. Any help would be appreciated!!!

  • Why are you trying to reinvent the wheel when Magento provides the feature of products import (with images)? – Mohit Kumar Arora Jun 26 '18 at 13:53
  • Yes , but I have a different module and I want add this feature there. Axovel Importer the module name. – Monalisa Jun 27 '18 at 7:00

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.