Advertisement
pharmokan

magento add programatically gallery image to existing sku

Apr 14th, 2020
469
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.71 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. $importDir = Mage::getBaseDir('media') . DS . 'import' . DS;
  9. $productsData = array('2abc.jpg','2def.jpg');
  10. $productSKU = 'SKU';
  11. $product = Mage::getModel('catalog/product')->loadByAttribute('sku',$productSKU);
  12.  
  13. foreach($productsData as $fileName){
  14.     $filePath = $importDir.$fileName;
  15.     if(file_exists($importDir . $fileName)){
  16.     $product->addImageToMediaGallery($importDir . $fileName, null, false, false);
  17.     echo "done";
  18. } else {
  19.         echo $productSKU . " not done";
  20.         echo "<br>";
  21.     }  
  22. }
  23. $product->save();
  24. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement