Magento 2 Product Base , Thumbnails not saving Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?REST API creating more than one media entry for productimport/export error - magento 2.0.1Magento 2: Manual Import Image IssueMagento 2 import products with imagesMagento 2.2.2 - Import Product Images CategoricallyHow to get product quantity by using REST API product filterProduct image not rename while import product in Magento 2How to Update Magento 2 configurable child products price by REST APICustom Import Product Images with obligatory fields in Magento 2Rewrite rule for media images
France's Public Holidays' Puzzle
Protagonist's race is hidden - should I reveal it?
Is there a verb for listening stealthily?
How was Lagrange appointed professor of mathematics so early?
What's parked in Mil Moscow helicopter plant?
What were wait-states, and why was it only an issue for PCs?
Will I be more secure with my own router behind my ISP's router?
Has a Nobel Peace laureate ever been accused of war crimes?
What is the term for extremely loose Latin word order?
Getting AggregateResult variables from Execute Anonymous Window
Where/What are Arya's scars from?
How to keep bees out of canned beverages?
How did Elite on the NES work?
How would it unbalance gameplay to rule that Weapon Master allows for picking a fighting style?
What is a 'Key' in computer science?
Are there existing rules/lore for MTG planeswalkers?
Is Bran literally the world's memory?
How do I deal with an erroneously large refund?
What happened to Viserion in Season 7?
Determinant of a matrix with 2 equal rows
Where to find documentation for `whois` command options?
All ASCII characters with a given bit count
Retract an already submitted Recommendation Letter (written for an undergrad student)
What was Apollo 13's "Little Jolt" after MECO?
Magento 2 Product Base , Thumbnails not saving
Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?REST API creating more than one media entry for productimport/export error - magento 2.0.1Magento 2: Manual Import Image IssueMagento 2 import products with imagesMagento 2.2.2 - Import Product Images CategoricallyHow to get product quantity by using REST API product filterProduct image not rename while import product in Magento 2How to Update Magento 2 configurable child products price by REST APICustom Import Product Images with obligatory fields in Magento 2Rewrite rule for media images
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
In Magento, I am building a bulk image upload feature.
Here user can upload images as "sku_1.jpg, sku_2.jpg, sku_3.jpg ".
Now I need to set "sku_1.jpg" as the main image, thumbnail.
I used the following code for it. But some times it's working and some times it failed.
try{
$data[] = ['sku' => "sku" , 'image_name'=>"image",'status'=>"status"];
foreach($files as $file)
$image_count++;
unset( $file_to_sku);
$file_name=$file["name"];
$file_tmp=$file["tmp_name"];
$generic_path = $vendorId.'/'.str_replace("-", "", date("Y-m-d"));
if(!is_dir($path."/media/import/".$generic_path))
mkdir($path."/media/import/".$generic_path,0777,true);
$image_path = $path."/media/import/".$generic_path.'/'.$file_name;
$ext=pathinfo($file_name,PATHINFO_EXTENSION);
if(in_array($ext,$extension))
move_uploaded_file($file_tmp,"pub/media/import/".$generic_path.'/'.$file_name);
$base_filename = pathinfo($file_name, PATHINFO_FILENAME);
$fileNameNoExtension = preg_replace("/.[^.]+$/", "", $file["name"]);
$file_to_sku = explode("_",$base_filename);
$product_image_sku = $file_to_sku[0];
if($product_image_sku!="")
$prod = $this->_vproducts->getVendorProductsByVendorSkuId($vendorId,$product_image_sku);
$vend_prod_count = count($prod->getData());
if($vend_prod_count > 0)
$product = $this->_objectManager->create('MagentoCatalogModelProduct')->load($prod->getProductId());
$prod_media = $product->getMediaGalleryImages();
$existingMediaGalleryEntries = $product->getMediaGalleryEntries();
$product_status=$product->getStatus();
$cmp_image=$product_image_sku."_1";
$productRepository = $this->_objectManager->create('MagentoCatalogApiProductRepositoryInterface');
$ext_images = array();
if($product_status == 2)
if($existingMediaGalleryEntries)
foreach ($existingMediaGalleryEntries as $key => $entry)
$new_img=basename($entry['file']);
$ext_images[]=$new_img;
if($new_img==$file["name"])
$this->imageProcessor->removeImage($product, $entry['file']);
unset($existingMediaGalleryEntries[$key]);
$product->setMediaGalleryEntries($existingMediaGalleryEntries);
$this->productRepository->save($product);
if(count($prod_media) <= 6)
/*Add Images To The Product*/
if($file_to_sku[1] <= 6)
if( $product_status == 2)
$cmp_image=$product_image_sku."_1";
if($fileNameNoExtension == $cmp_image)
$product->setBaseImage($image_path)
// ->setSmallImage($image_path)
// ->setThumbnail($image_path)
->addImageToMediaGallery($image_path,array('image', 'small_image', 'thumbnail'),false, false);
$product->save();
//
else
$product->addImageToMediaGallery($image_path, null, false, false);
if($product->save())
$data[] = ['sku' => $product_image_sku , 'image_name'=>$file["name"],'status'=>'success'];
$success++;
else
$data[] = ['sku' => $product_image_sku , 'image_name'=>$file["name"],'status'=>'Image not saved'];
elseif(!in_array($file["name"],$ext_images))
if($fileNameNoExtension == $product_image_sku."_1")
$product->addImageToMediaGallery($image_path, array('image', 'small_image', 'thumbnail'), false, false);
else
$product->addImageToMediaGallery($image_path, null, false, false);
if($product->save())
$data[] = ['sku' => $product_image_sku , 'image_name'=>$file["name"],'status'=>'success'];
else
$data[] = ['sku' => $product_image_sku , 'image_name'=>$file["name"],'status'=>'Image not saved'];
else
$data[] = ['sku' => $product_image_sku , 'image_name'=>$file["name"],'status'=>'image is not a valid extension'];
else
$data[] = ['sku' => $product_image_sku , 'image_name'=>$file["name"],'status'=>'product already have 6 images'];
else
$data[] = ['sku' => $product_image_sku , 'image_name'=>$file["name"],'status'=>'product sku not found'];
else
$data[] = ['sku' => $product_image_sku , 'image_name'=>$file["name"],'status'=>'product sku not found'];
else
$data[] = ['sku' => $product_image_sku , 'image_name'=>$file["name"],'status'=>'image is not a valid extension'];
//array_push($error,"$file_name, ");
What was wrong in my code? please help me.
magento2 magento-2.1
add a comment |
In Magento, I am building a bulk image upload feature.
Here user can upload images as "sku_1.jpg, sku_2.jpg, sku_3.jpg ".
Now I need to set "sku_1.jpg" as the main image, thumbnail.
I used the following code for it. But some times it's working and some times it failed.
try{
$data[] = ['sku' => "sku" , 'image_name'=>"image",'status'=>"status"];
foreach($files as $file)
$image_count++;
unset( $file_to_sku);
$file_name=$file["name"];
$file_tmp=$file["tmp_name"];
$generic_path = $vendorId.'/'.str_replace("-", "", date("Y-m-d"));
if(!is_dir($path."/media/import/".$generic_path))
mkdir($path."/media/import/".$generic_path,0777,true);
$image_path = $path."/media/import/".$generic_path.'/'.$file_name;
$ext=pathinfo($file_name,PATHINFO_EXTENSION);
if(in_array($ext,$extension))
move_uploaded_file($file_tmp,"pub/media/import/".$generic_path.'/'.$file_name);
$base_filename = pathinfo($file_name, PATHINFO_FILENAME);
$fileNameNoExtension = preg_replace("/.[^.]+$/", "", $file["name"]);
$file_to_sku = explode("_",$base_filename);
$product_image_sku = $file_to_sku[0];
if($product_image_sku!="")
$prod = $this->_vproducts->getVendorProductsByVendorSkuId($vendorId,$product_image_sku);
$vend_prod_count = count($prod->getData());
if($vend_prod_count > 0)
$product = $this->_objectManager->create('MagentoCatalogModelProduct')->load($prod->getProductId());
$prod_media = $product->getMediaGalleryImages();
$existingMediaGalleryEntries = $product->getMediaGalleryEntries();
$product_status=$product->getStatus();
$cmp_image=$product_image_sku."_1";
$productRepository = $this->_objectManager->create('MagentoCatalogApiProductRepositoryInterface');
$ext_images = array();
if($product_status == 2)
if($existingMediaGalleryEntries)
foreach ($existingMediaGalleryEntries as $key => $entry)
$new_img=basename($entry['file']);
$ext_images[]=$new_img;
if($new_img==$file["name"])
$this->imageProcessor->removeImage($product, $entry['file']);
unset($existingMediaGalleryEntries[$key]);
$product->setMediaGalleryEntries($existingMediaGalleryEntries);
$this->productRepository->save($product);
if(count($prod_media) <= 6)
/*Add Images To The Product*/
if($file_to_sku[1] <= 6)
if( $product_status == 2)
$cmp_image=$product_image_sku."_1";
if($fileNameNoExtension == $cmp_image)
$product->setBaseImage($image_path)
// ->setSmallImage($image_path)
// ->setThumbnail($image_path)
->addImageToMediaGallery($image_path,array('image', 'small_image', 'thumbnail'),false, false);
$product->save();
//
else
$product->addImageToMediaGallery($image_path, null, false, false);
if($product->save())
$data[] = ['sku' => $product_image_sku , 'image_name'=>$file["name"],'status'=>'success'];
$success++;
else
$data[] = ['sku' => $product_image_sku , 'image_name'=>$file["name"],'status'=>'Image not saved'];
elseif(!in_array($file["name"],$ext_images))
if($fileNameNoExtension == $product_image_sku."_1")
$product->addImageToMediaGallery($image_path, array('image', 'small_image', 'thumbnail'), false, false);
else
$product->addImageToMediaGallery($image_path, null, false, false);
if($product->save())
$data[] = ['sku' => $product_image_sku , 'image_name'=>$file["name"],'status'=>'success'];
else
$data[] = ['sku' => $product_image_sku , 'image_name'=>$file["name"],'status'=>'Image not saved'];
else
$data[] = ['sku' => $product_image_sku , 'image_name'=>$file["name"],'status'=>'image is not a valid extension'];
else
$data[] = ['sku' => $product_image_sku , 'image_name'=>$file["name"],'status'=>'product already have 6 images'];
else
$data[] = ['sku' => $product_image_sku , 'image_name'=>$file["name"],'status'=>'product sku not found'];
else
$data[] = ['sku' => $product_image_sku , 'image_name'=>$file["name"],'status'=>'product sku not found'];
else
$data[] = ['sku' => $product_image_sku , 'image_name'=>$file["name"],'status'=>'image is not a valid extension'];
//array_push($error,"$file_name, ");
What was wrong in my code? please help me.
magento2 magento-2.1
could you please post your full code?
– Keyur Shah
Apr 19 at 10:10
updated full code
– Dinesh
Apr 19 at 10:19
I tried following code as well.... but not worked. $mediaGalleryEntriesTemp = []; foreach ($product->getMediaGalleryEntries() as $item) $new_img=basename($item['file']); if ($new_img == $cmp_image) $item->setTypes(['image', 'small_image', 'thumbnail']); $mediaGalleryEntriesTemp[] = $item; $i++; $product->setMediaGalleryEntries($mediaGalleryEntriesTemp); $this->productRepository->save($product);
– Dinesh
Apr 19 at 13:17
add a comment |
In Magento, I am building a bulk image upload feature.
Here user can upload images as "sku_1.jpg, sku_2.jpg, sku_3.jpg ".
Now I need to set "sku_1.jpg" as the main image, thumbnail.
I used the following code for it. But some times it's working and some times it failed.
try{
$data[] = ['sku' => "sku" , 'image_name'=>"image",'status'=>"status"];
foreach($files as $file)
$image_count++;
unset( $file_to_sku);
$file_name=$file["name"];
$file_tmp=$file["tmp_name"];
$generic_path = $vendorId.'/'.str_replace("-", "", date("Y-m-d"));
if(!is_dir($path."/media/import/".$generic_path))
mkdir($path."/media/import/".$generic_path,0777,true);
$image_path = $path."/media/import/".$generic_path.'/'.$file_name;
$ext=pathinfo($file_name,PATHINFO_EXTENSION);
if(in_array($ext,$extension))
move_uploaded_file($file_tmp,"pub/media/import/".$generic_path.'/'.$file_name);
$base_filename = pathinfo($file_name, PATHINFO_FILENAME);
$fileNameNoExtension = preg_replace("/.[^.]+$/", "", $file["name"]);
$file_to_sku = explode("_",$base_filename);
$product_image_sku = $file_to_sku[0];
if($product_image_sku!="")
$prod = $this->_vproducts->getVendorProductsByVendorSkuId($vendorId,$product_image_sku);
$vend_prod_count = count($prod->getData());
if($vend_prod_count > 0)
$product = $this->_objectManager->create('MagentoCatalogModelProduct')->load($prod->getProductId());
$prod_media = $product->getMediaGalleryImages();
$existingMediaGalleryEntries = $product->getMediaGalleryEntries();
$product_status=$product->getStatus();
$cmp_image=$product_image_sku."_1";
$productRepository = $this->_objectManager->create('MagentoCatalogApiProductRepositoryInterface');
$ext_images = array();
if($product_status == 2)
if($existingMediaGalleryEntries)
foreach ($existingMediaGalleryEntries as $key => $entry)
$new_img=basename($entry['file']);
$ext_images[]=$new_img;
if($new_img==$file["name"])
$this->imageProcessor->removeImage($product, $entry['file']);
unset($existingMediaGalleryEntries[$key]);
$product->setMediaGalleryEntries($existingMediaGalleryEntries);
$this->productRepository->save($product);
if(count($prod_media) <= 6)
/*Add Images To The Product*/
if($file_to_sku[1] <= 6)
if( $product_status == 2)
$cmp_image=$product_image_sku."_1";
if($fileNameNoExtension == $cmp_image)
$product->setBaseImage($image_path)
// ->setSmallImage($image_path)
// ->setThumbnail($image_path)
->addImageToMediaGallery($image_path,array('image', 'small_image', 'thumbnail'),false, false);
$product->save();
//
else
$product->addImageToMediaGallery($image_path, null, false, false);
if($product->save())
$data[] = ['sku' => $product_image_sku , 'image_name'=>$file["name"],'status'=>'success'];
$success++;
else
$data[] = ['sku' => $product_image_sku , 'image_name'=>$file["name"],'status'=>'Image not saved'];
elseif(!in_array($file["name"],$ext_images))
if($fileNameNoExtension == $product_image_sku."_1")
$product->addImageToMediaGallery($image_path, array('image', 'small_image', 'thumbnail'), false, false);
else
$product->addImageToMediaGallery($image_path, null, false, false);
if($product->save())
$data[] = ['sku' => $product_image_sku , 'image_name'=>$file["name"],'status'=>'success'];
else
$data[] = ['sku' => $product_image_sku , 'image_name'=>$file["name"],'status'=>'Image not saved'];
else
$data[] = ['sku' => $product_image_sku , 'image_name'=>$file["name"],'status'=>'image is not a valid extension'];
else
$data[] = ['sku' => $product_image_sku , 'image_name'=>$file["name"],'status'=>'product already have 6 images'];
else
$data[] = ['sku' => $product_image_sku , 'image_name'=>$file["name"],'status'=>'product sku not found'];
else
$data[] = ['sku' => $product_image_sku , 'image_name'=>$file["name"],'status'=>'product sku not found'];
else
$data[] = ['sku' => $product_image_sku , 'image_name'=>$file["name"],'status'=>'image is not a valid extension'];
//array_push($error,"$file_name, ");
What was wrong in my code? please help me.
magento2 magento-2.1
In Magento, I am building a bulk image upload feature.
Here user can upload images as "sku_1.jpg, sku_2.jpg, sku_3.jpg ".
Now I need to set "sku_1.jpg" as the main image, thumbnail.
I used the following code for it. But some times it's working and some times it failed.
try{
$data[] = ['sku' => "sku" , 'image_name'=>"image",'status'=>"status"];
foreach($files as $file)
$image_count++;
unset( $file_to_sku);
$file_name=$file["name"];
$file_tmp=$file["tmp_name"];
$generic_path = $vendorId.'/'.str_replace("-", "", date("Y-m-d"));
if(!is_dir($path."/media/import/".$generic_path))
mkdir($path."/media/import/".$generic_path,0777,true);
$image_path = $path."/media/import/".$generic_path.'/'.$file_name;
$ext=pathinfo($file_name,PATHINFO_EXTENSION);
if(in_array($ext,$extension))
move_uploaded_file($file_tmp,"pub/media/import/".$generic_path.'/'.$file_name);
$base_filename = pathinfo($file_name, PATHINFO_FILENAME);
$fileNameNoExtension = preg_replace("/.[^.]+$/", "", $file["name"]);
$file_to_sku = explode("_",$base_filename);
$product_image_sku = $file_to_sku[0];
if($product_image_sku!="")
$prod = $this->_vproducts->getVendorProductsByVendorSkuId($vendorId,$product_image_sku);
$vend_prod_count = count($prod->getData());
if($vend_prod_count > 0)
$product = $this->_objectManager->create('MagentoCatalogModelProduct')->load($prod->getProductId());
$prod_media = $product->getMediaGalleryImages();
$existingMediaGalleryEntries = $product->getMediaGalleryEntries();
$product_status=$product->getStatus();
$cmp_image=$product_image_sku."_1";
$productRepository = $this->_objectManager->create('MagentoCatalogApiProductRepositoryInterface');
$ext_images = array();
if($product_status == 2)
if($existingMediaGalleryEntries)
foreach ($existingMediaGalleryEntries as $key => $entry)
$new_img=basename($entry['file']);
$ext_images[]=$new_img;
if($new_img==$file["name"])
$this->imageProcessor->removeImage($product, $entry['file']);
unset($existingMediaGalleryEntries[$key]);
$product->setMediaGalleryEntries($existingMediaGalleryEntries);
$this->productRepository->save($product);
if(count($prod_media) <= 6)
/*Add Images To The Product*/
if($file_to_sku[1] <= 6)
if( $product_status == 2)
$cmp_image=$product_image_sku."_1";
if($fileNameNoExtension == $cmp_image)
$product->setBaseImage($image_path)
// ->setSmallImage($image_path)
// ->setThumbnail($image_path)
->addImageToMediaGallery($image_path,array('image', 'small_image', 'thumbnail'),false, false);
$product->save();
//
else
$product->addImageToMediaGallery($image_path, null, false, false);
if($product->save())
$data[] = ['sku' => $product_image_sku , 'image_name'=>$file["name"],'status'=>'success'];
$success++;
else
$data[] = ['sku' => $product_image_sku , 'image_name'=>$file["name"],'status'=>'Image not saved'];
elseif(!in_array($file["name"],$ext_images))
if($fileNameNoExtension == $product_image_sku."_1")
$product->addImageToMediaGallery($image_path, array('image', 'small_image', 'thumbnail'), false, false);
else
$product->addImageToMediaGallery($image_path, null, false, false);
if($product->save())
$data[] = ['sku' => $product_image_sku , 'image_name'=>$file["name"],'status'=>'success'];
else
$data[] = ['sku' => $product_image_sku , 'image_name'=>$file["name"],'status'=>'Image not saved'];
else
$data[] = ['sku' => $product_image_sku , 'image_name'=>$file["name"],'status'=>'image is not a valid extension'];
else
$data[] = ['sku' => $product_image_sku , 'image_name'=>$file["name"],'status'=>'product already have 6 images'];
else
$data[] = ['sku' => $product_image_sku , 'image_name'=>$file["name"],'status'=>'product sku not found'];
else
$data[] = ['sku' => $product_image_sku , 'image_name'=>$file["name"],'status'=>'product sku not found'];
else
$data[] = ['sku' => $product_image_sku , 'image_name'=>$file["name"],'status'=>'image is not a valid extension'];
//array_push($error,"$file_name, ");
What was wrong in my code? please help me.
magento2 magento-2.1
magento2 magento-2.1
edited Apr 19 at 10:19
Dinesh
asked Apr 19 at 9:44
DineshDinesh
11511
11511
could you please post your full code?
– Keyur Shah
Apr 19 at 10:10
updated full code
– Dinesh
Apr 19 at 10:19
I tried following code as well.... but not worked. $mediaGalleryEntriesTemp = []; foreach ($product->getMediaGalleryEntries() as $item) $new_img=basename($item['file']); if ($new_img == $cmp_image) $item->setTypes(['image', 'small_image', 'thumbnail']); $mediaGalleryEntriesTemp[] = $item; $i++; $product->setMediaGalleryEntries($mediaGalleryEntriesTemp); $this->productRepository->save($product);
– Dinesh
Apr 19 at 13:17
add a comment |
could you please post your full code?
– Keyur Shah
Apr 19 at 10:10
updated full code
– Dinesh
Apr 19 at 10:19
I tried following code as well.... but not worked. $mediaGalleryEntriesTemp = []; foreach ($product->getMediaGalleryEntries() as $item) $new_img=basename($item['file']); if ($new_img == $cmp_image) $item->setTypes(['image', 'small_image', 'thumbnail']); $mediaGalleryEntriesTemp[] = $item; $i++; $product->setMediaGalleryEntries($mediaGalleryEntriesTemp); $this->productRepository->save($product);
– Dinesh
Apr 19 at 13:17
could you please post your full code?
– Keyur Shah
Apr 19 at 10:10
could you please post your full code?
– Keyur Shah
Apr 19 at 10:10
updated full code
– Dinesh
Apr 19 at 10:19
updated full code
– Dinesh
Apr 19 at 10:19
I tried following code as well.... but not worked. $mediaGalleryEntriesTemp = []; foreach ($product->getMediaGalleryEntries() as $item) $new_img=basename($item['file']); if ($new_img == $cmp_image) $item->setTypes(['image', 'small_image', 'thumbnail']); $mediaGalleryEntriesTemp[] = $item; $i++; $product->setMediaGalleryEntries($mediaGalleryEntriesTemp); $this->productRepository->save($product);
– Dinesh
Apr 19 at 13:17
I tried following code as well.... but not worked. $mediaGalleryEntriesTemp = []; foreach ($product->getMediaGalleryEntries() as $item) $new_img=basename($item['file']); if ($new_img == $cmp_image) $item->setTypes(['image', 'small_image', 'thumbnail']); $mediaGalleryEntriesTemp[] = $item; $i++; $product->setMediaGalleryEntries($mediaGalleryEntriesTemp); $this->productRepository->save($product);
– Dinesh
Apr 19 at 13:17
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f270776%2fmagento-2-product-base-thumbnails-not-saving%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f270776%2fmagento-2-product-base-thumbnails-not-saving%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
could you please post your full code?
– Keyur Shah
Apr 19 at 10:10
updated full code
– Dinesh
Apr 19 at 10:19
I tried following code as well.... but not worked. $mediaGalleryEntriesTemp = []; foreach ($product->getMediaGalleryEntries() as $item) $new_img=basename($item['file']); if ($new_img == $cmp_image) $item->setTypes(['image', 'small_image', 'thumbnail']); $mediaGalleryEntriesTemp[] = $item; $i++; $product->setMediaGalleryEntries($mediaGalleryEntriesTemp); $this->productRepository->save($product);
– Dinesh
Apr 19 at 13:17