Let’s initiate a discussion!!
Step 1). Get the Product image from URL – create a file in Helper/Data.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
public function getProductImage($imgurl){ $fileSystem = $this->_objectManager->create('\Magento\Framework\Filesystem'); $mediaPath = $fileSystem->getDirectoryRead(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA)->getAbsolutePath(); if (!file_exists($mediaPath.'imagefolder')) { mkdir($mediaPath.'imagefolder', 0777, true); } $url = $imgurl; $ch = curl_init($url); $my_save_dir = $mediaPath.'imagefolder/'; $filename = basename($url); $complete_save_loc = $my_save_dir . $filename; $fp = fopen($complete_save_loc, 'wb'); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_TIMEOUT, 28800); $return = curl_exec($ch); curl_close($ch); $image = $return; return $image; } |
Step 2). Assign the images to existing products.
1 2 3 4 5 6 7 8 9 |
$product = $this->productFactory->create()->load($proid); $getimgurl = $url; $imagename= basename($getimgurl); $imgpath = $mediaPath.'imagefolder/'.$imagename; if (!file_exists($imgpath)) { //check image already exist in directory $this->helperData->getProductImage($getimgurl); } $product->addImageToMediaGallery($imgpath, array('image', 'small_image', 'thumbnail','media_gallery'), false, false); $product->save(); |
[crayon-641fbdc15c230548521828/] Using above fucntion Images can be imported directly from...
Override view block using di.xml and add the below code...
You can check a list of called layout XML for...
Follow the below steps to install and set up PWA...
If you want to remove all leading zero's from order,...
Let our Magento expert connect to discuss your requirement.
We offer Magento
certified developers.
Our Magento clientele
is 500+.
We sign NDA for the
security of your projects.
We’ve performed 100+
Magento migration projects.
Free quotation
on your project.
Three months warranty on
code developed by us.