MagestyApps / module-web-images

Magento 2 module for uploading images in optimised formats (SVG, WebP, etc.)
https://www.magestyapps.com
93 stars 16 forks source link

programmatically product import issue. #19

Closed hgati closed 1 year ago

hgati commented 1 year ago

I run following code for import product with image.

$product = $objectManager->get('Magento\Catalog\Model\Product')->load(4);
$importDir = '/var/www/magento/pub/media/import;
//$url = $importDir . $product->getImage();
$product->addImageToMediaGallery("$importDir/zion-t-zzz-un.webp", array('image', 'small_image', 'thumbnail'), false, false);
$product->save();

I got the following error. PHP Fatal error: Uncaught Magento\Framework\Exception\LocalizedException: The image type for the file is invalid. Enter the correct image type and try again. in /var/www/magento/vendor/magento/module-catalog/Model/Product/Gallery/Processor.php:164