Skip to content

product-images

Auto Added by WPeMatico

Magento 2 set product image role programmatically

Hello and this is my code: $imgURL = ‘path/to/my/image.png’; $fileSystem = $objectManager->create(‘MagentoFrameworkFilesystem’); $mediaPath = $fileSystem->getDirectoryRead(MagentoFrameworkAppFilesystemDirectoryList::MEDIA)->getAbsolutePath(); $product->addImageToMediaGallery($mediaPath.’catalog/product’.$data[‘thumbnail_image’],[‘thumbnail’, ‘swatch’], false, false); $product->setThumbnail($mediaPath.’catalog/product’.$imgURL); $product->save(); What I want to achive, is to assign programmatically an image and set it as a thumbnail. The above… Read More »Magento 2 set product image role programmatically

Product images to come without caching

<?php namespace CBCdnImagePlugin; use MagentoCatalogHelperImage; class ProductImageCdn { const CDN_BASE_URL = ‘https://cdn.yourstore.com/media/catalog/product/’; public function afterGetUrl(Image $subject, $result) { // Only modify product image URLs, not CMS/static images if (strpos($result, ‘/catalog/product/’) !== false) { return str_replace(‘/media/catalog/product/’, self::CDN_BASE_URL, $result); } return $result;… Read More »Product images to come without caching