@@ -141,6 +141,7 @@ public function execute()
141
141
$ originalSku = $ product ->getSku ();
142
142
$ canSaveCustomOptions = $ product ->getCanSaveCustomOptions ();
143
143
$ product ->save ();
144
+
144
145
$ this ->handleImageRemoveError ($ data , $ product ->getId ());
145
146
$ productId = $ product ->getEntityId ();
146
147
$ productAttributeSetId = $ product ->getAttributeSetId ();
@@ -213,7 +214,7 @@ public function execute()
213
214
/**
214
215
* Notify customer when image was not deleted in specific case.
215
216
*
216
- * TODO: temporary workaround must be eliminated in MAGETWO -45306
217
+ * TODO: temporary workaround must be eliminated in MAGETNO -45306
217
218
*
218
219
* @param array $postData
219
220
* @param int $productId
@@ -223,22 +224,15 @@ private function handleImageRemoveError($postData, $productId)
223
224
{
224
225
if (isset ($ postData ['product ' ]['media_gallery ' ]['images ' ])) {
225
226
$ removedImagesAmount = 0 ;
226
- $ removedImages = [];
227
227
foreach ($ postData ['product ' ]['media_gallery ' ]['images ' ] as $ image ) {
228
228
if (!empty ($ image ['removed ' ])) {
229
229
$ removedImagesAmount ++;
230
- $ removedImages [] = $ image ['value_id ' ];
231
230
}
232
231
}
233
232
if ($ removedImagesAmount ) {
234
233
$ expectedImagesAmount = count ($ postData ['product ' ]['media_gallery ' ]['images ' ]) - $ removedImagesAmount ;
235
- $ product = $ this ->productRepository ->getById ($ productId );
234
+ $ product = $ this ->productRepository ->getById ($ productId, false , null , true );
236
235
$ images = $ product ->getMediaGallery ('images ' );
237
- foreach ($ images as $ key => $ imageItem ) {
238
- if (in_array ($ imageItem ['value_id ' ], $ removedImages )) {
239
- unset($ images [$ key ]);
240
- }
241
- }
242
236
if (is_array ($ images ) && $ expectedImagesAmount != count ($ images )) {
243
237
$ this ->messageManager ->addNoticeMessage (
244
238
__ ('The image cannot be removed as it has been assigned to the other image role ' )
0 commit comments