@@ -19,6 +19,8 @@ class CreateHandler extends AbstractHandler
19
19
const ADDITIONAL_STORE_DATA_KEY = 'additional_store_data ' ;
20
20
21
21
/**
22
+ * Execute before Plugin
23
+ *
22
24
* @param \Magento\Catalog\Model\Product\Gallery\CreateHandler $mediaGalleryCreateHandler
23
25
* @param \Magento\Catalog\Model\Product $product
24
26
* @param array $arguments
@@ -44,6 +46,8 @@ public function beforeExecute(
44
46
}
45
47
46
48
/**
49
+ * Execute plugin
50
+ *
47
51
* @param \Magento\Catalog\Model\Product\Gallery\CreateHandler $mediaGalleryCreateHandler
48
52
* @param \Magento\Catalog\Model\Product $product
49
53
* @return \Magento\Catalog\Model\Product
@@ -58,6 +62,9 @@ public function afterExecute(
58
62
);
59
63
60
64
if (!empty ($ mediaCollection )) {
65
+ if ($ product ->getIsDuplicate () === true ) {
66
+ $ mediaCollection = $ this ->makeAllNewVideos ($ product ->getId (), $ mediaCollection );
67
+ }
61
68
$ newVideoCollection = $ this ->collectNewVideos ($ mediaCollection );
62
69
$ this ->saveVideoData ($ newVideoCollection , 0 );
63
70
@@ -70,6 +77,8 @@ public function afterExecute(
70
77
}
71
78
72
79
/**
80
+ * Saves video data
81
+ *
73
82
* @param array $videoDataCollection
74
83
* @param int $storeId
75
84
* @return void
@@ -83,6 +92,8 @@ protected function saveVideoData(array $videoDataCollection, $storeId)
83
92
}
84
93
85
94
/**
95
+ * Saves additioanal video data
96
+ *
86
97
* @param array $videoDataCollection
87
98
* @return void
88
99
*/
@@ -99,6 +110,8 @@ protected function saveAdditionalStoreData(array $videoDataCollection)
99
110
}
100
111
101
112
/**
113
+ * Saves video data
114
+ *
102
115
* @param array $item
103
116
* @return void
104
117
*/
@@ -111,6 +124,8 @@ protected function saveVideoValuesItem(array $item)
111
124
}
112
125
113
126
/**
127
+ * Excludes current store data
128
+ *
114
129
* @param array $mediaCollection
115
130
* @param int $currentStoreId
116
131
* @return array
@@ -126,6 +141,8 @@ function ($item) use ($currentStoreId) {
126
141
}
127
142
128
143
/**
144
+ * Prepare video data for saving
145
+ *
129
146
* @param array $rowData
130
147
* @return array
131
148
*/
@@ -143,6 +160,8 @@ protected function prepareVideoRowDataForSave(array $rowData)
143
160
}
144
161
145
162
/**
163
+ * Loads video data
164
+ *
146
165
* @param array $mediaCollection
147
166
* @param int $excludedStore
148
167
* @return array
@@ -165,6 +184,8 @@ protected function loadStoreViewVideoData(array $mediaCollection, $excludedStore
165
184
}
166
185
167
186
/**
187
+ * Collect video data
188
+ *
168
189
* @param array $mediaCollection
169
190
* @return array
170
191
*/
@@ -182,6 +203,8 @@ protected function collectVideoData(array $mediaCollection)
182
203
}
183
204
184
205
/**
206
+ * Extract video data
207
+ *
185
208
* @param array $rowData
186
209
* @return array
187
210
*/
@@ -194,6 +217,8 @@ protected function extractVideoDataFromRowData(array $rowData)
194
217
}
195
218
196
219
/**
220
+ * Collect items for additional data adding
221
+ *
197
222
* @param array $mediaCollection
198
223
* @return array
199
224
*/
@@ -209,6 +234,8 @@ protected function collectVideoEntriesIdsToAdditionalLoad(array $mediaCollection
209
234
}
210
235
211
236
/**
237
+ * Add additional data
238
+ *
212
239
* @param array $mediaCollection
213
240
* @param array $data
214
241
* @return array
@@ -229,6 +256,8 @@ protected function addAdditionalStoreData(array $mediaCollection, array $data):
229
256
}
230
257
231
258
/**
259
+ * Creates additional video data
260
+ *
232
261
* @param array $storeData
233
262
* @param int $valueId
234
263
* @return array
@@ -247,6 +276,8 @@ protected function createAdditionalStoreDataCollection(array $storeData, $valueI
247
276
}
248
277
249
278
/**
279
+ * Collect new videos
280
+ *
250
281
* @param array $mediaCollection
251
282
* @return array
252
283
*/
@@ -262,6 +293,8 @@ private function collectNewVideos(array $mediaCollection): array
262
293
}
263
294
264
295
/**
296
+ * Checks if gallery item is video
297
+ *
265
298
* @param array $item
266
299
* @return bool
267
300
*/
@@ -273,6 +306,8 @@ private function isVideoItem(array $item): bool
273
306
}
274
307
275
308
/**
309
+ * Checks if video is new
310
+ *
276
311
* @param array $item
277
312
* @return bool
278
313
*/
@@ -282,4 +317,23 @@ private function isNewVideo(array $item): bool
282
317
|| empty ($ item ['video_url_default ' ])
283
318
|| empty ($ item ['video_title_default ' ]);
284
319
}
320
+
321
+ /**
322
+ * Mark all videos as new
323
+ *
324
+ * @param int $entityId
325
+ * @param array $mediaCollection
326
+ * @return array
327
+ */
328
+ private function makeAllNewVideos ($ entityId , array $ mediaCollection ): array
329
+ {
330
+ foreach ($ mediaCollection as $ key => $ video ) {
331
+ if ($ this ->isVideoItem ($ video )) {
332
+ unset($ video ['video_url_default ' ], $ video ['video_title_default ' ]);
333
+ $ video ['entity_id ' ] = $ entityId ;
334
+ $ mediaCollection [$ key ] = $ video ;
335
+ }
336
+ }
337
+ return $ mediaCollection ;
338
+ }
285
339
}
0 commit comments