File tree Expand file tree Collapse file tree 1 file changed +8
-1
lines changed
app/code/Magento/Catalog/Controller/Adminhtml/Product Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -223,16 +223,23 @@ private function handleImageRemoveError($postData, $productId)
223223 {
224224 if (isset ($ postData ['product ' ]['media_gallery ' ]['images ' ])) {
225225 $ removedImagesAmount = 0 ;
226+ $ removedImages = [];
226227 foreach ($ postData ['product ' ]['media_gallery ' ]['images ' ] as $ image ) {
227228 if (!empty ($ image ['removed ' ])) {
228229 $ removedImagesAmount ++;
230+ $ removedImages [] = $ image ['value_id ' ];
229231 }
230232 }
231233 if ($ removedImagesAmount ) {
232234 $ expectedImagesAmount = count ($ postData ['product ' ]['media_gallery ' ]['images ' ]) - $ removedImagesAmount ;
233235 $ product = $ this ->productRepository ->getById ($ productId );
234236 $ images = $ product ->getMediaGallery ('images ' );
235- if (is_array ($ images ) && $ expectedImagesAmount >= count ($ images )) {
237+ foreach ($ images as $ key => $ imageItem ) {
238+ if (in_array ($ imageItem ['value_id ' ], $ removedImages )) {
239+ unset($ images [$ key ]);
240+ }
241+ }
242+ if (is_array ($ images ) && $ expectedImagesAmount != count ($ images )) {
236243 $ this ->messageManager ->addNoticeMessage (
237244 __ ('The image cannot be removed as it has been assigned to the other image role ' )
238245 );
You can’t perform that action at this time.
0 commit comments