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