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)
223
223
{
224
224
if (isset ($ postData ['product ' ]['media_gallery ' ]['images ' ])) {
225
225
$ removedImagesAmount = 0 ;
226
+ $ removedImages = [];
226
227
foreach ($ postData ['product ' ]['media_gallery ' ]['images ' ] as $ image ) {
227
228
if (!empty ($ image ['removed ' ])) {
228
229
$ removedImagesAmount ++;
230
+ $ removedImages [] = $ image ['value_id ' ];
229
231
}
230
232
}
231
233
if ($ removedImagesAmount ) {
232
234
$ expectedImagesAmount = count ($ postData ['product ' ]['media_gallery ' ]['images ' ]) - $ removedImagesAmount ;
233
235
$ product = $ this ->productRepository ->getById ($ productId );
234
236
$ 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 )) {
236
243
$ this ->messageManager ->addNoticeMessage (
237
244
__ ('The image cannot be removed as it has been assigned to the other image role ' )
238
245
);
You can’t perform that action at this time.
0 commit comments