Advertisement
pharmokan

magento add gallery image list of sku and file name

Apr 16th, 2020
486
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.33 KB | None | 0 0
  1. <?php
  2. error_reporting(E_ALL);
  3. ini_set('display_errors', 1);
  4. require_once 'app/Mage.php';
  5. Mage::app();
  6. Mage::app()->getStore()->setId(Mage_Core_Model_App::ADMIN_STORE_ID);
  7.  
  8. $arr = array(
  9.   array("sku"=>"SKU###","file"=>"76763.jpg"),
  10.   array("sku"=>"SKU###","file"=>"76133.jpg"),
  11.   array("sku"=>"SKU###","file"=>"76931.jpg"),
  12.   array("sku"=>"SKU###","file"=>"76703.jpg"),
  13.   array("sku"=>"SKU###","file"=>"77239_1.jpg"),
  14.   array("sku"=>"SKU###","file"=>"77239.jpg"),
  15.   array("sku"=>"SKU###","file"=>"75296.jpg"),
  16.   array("sku"=>"SKU###","file"=>"77261_1.jpg"),
  17.   array("sku"=>"SKU###","file"=>"76422.jpg"),
  18.   array("sku"=>"SKU###","file"=>"76759.jpg"),
  19.   array("sku"=>"SKU###","file"=>"76344.jpg"),
  20.   array("sku"=>"SKU###","file"=>"73661.jpg"),
  21.   array("sku"=>"SKU###","file"=>"77261.jpg"),
  22.   array("sku"=>"SKU###","file"=>"76426_1.jpg"),
  23. );
  24.  
  25. $importDir = Mage::getBaseDir('media') . DS . 'import' . DS;
  26.  
  27. foreach($arr as $val){
  28.     $sku = $val['sku'];
  29.     $image = $val['file'];
  30.     $filePath = $importDir.$image;
  31.     $product = Mage::getModel('catalog/product')->loadByAttribute('sku',$sku);
  32.     if(file_exists($filePath)){
  33.     $product->addImageToMediaGallery($filePath, null, false, false);
  34.     echo "done";
  35.     $product->save();
  36.     } else {
  37.         echo $productSKU . " not done";
  38.        
  39.     }  
  40.  echo "<br>";
  41. }
  42.  
  43. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement