@@ -167,8 +167,11 @@ public function execute($product, $arguments = [])
167
167
if (empty ($ attrData ) && empty ($ clearImages ) && empty ($ newImages ) && empty ($ existImages )) {
168
168
continue ;
169
169
}
170
+ $ resetLabel = false ;
170
171
if (in_array ($ attrData , $ clearImages )) {
171
172
$ product ->setData ($ mediaAttrCode , 'no_selection ' );
173
+ $ product ->setData ($ mediaAttrCode . '_label ' , null );
174
+ $ resetLabel = true ;
172
175
}
173
176
174
177
if (in_array ($ attrData , array_keys ($ newImages ))) {
@@ -179,13 +182,31 @@ public function execute($product, $arguments = [])
179
182
if (in_array ($ attrData , array_keys ($ existImages )) && isset ($ existImages [$ attrData ]['label ' ])) {
180
183
$ product ->setData ($ mediaAttrCode . '_label ' , $ existImages [$ attrData ]['label ' ]);
181
184
}
185
+
186
+ if ($ attrData === 'no_selection ' && !empty ($ product ->getData ($ mediaAttrCode . '_label ' ))) {
187
+ $ product ->setData ($ mediaAttrCode . '_label ' , null );
188
+ $ resetLabel = true ;
189
+ }
182
190
if (!empty ($ product ->getData ($ mediaAttrCode ))) {
183
191
$ product ->addAttributeUpdate (
184
192
$ mediaAttrCode ,
185
193
$ product ->getData ($ mediaAttrCode ),
186
194
$ product ->getStoreId ()
187
195
);
188
196
}
197
+ if (
198
+ in_array ($ mediaAttrCode , ['image ' , 'small_image ' , 'thumbnail ' ])
199
+ && (
200
+ !empty ($ product ->getData ($ mediaAttrCode . '_label ' ))
201
+ || $ resetLabel === true
202
+ )
203
+ ) {
204
+ $ product ->addAttributeUpdate (
205
+ $ mediaAttrCode . '_label ' ,
206
+ $ product ->getData ($ mediaAttrCode . '_label ' ),
207
+ $ product ->getStoreId ()
208
+ );
209
+ }
189
210
}
190
211
191
212
$ product ->setData ($ attrCode , $ value );
0 commit comments