@@ -74,11 +74,6 @@ class Helper
74
74
* @var \Magento\Framework\Stdlib\DateTime\Filter\DateTime
75
75
*/
76
76
private $ dateTimeFilter ;
77
-
78
- /**
79
- * @var \Magento\Catalog\Model\Product\LinkTypeProvider
80
- */
81
- private $ linkTypeProvider ;
82
77
83
78
/**
84
79
* Helper constructor.
@@ -88,25 +83,21 @@ class Helper
88
83
* @param ProductLinks $productLinks
89
84
* @param \Magento\Backend\Helper\Js $jsHelper
90
85
* @param \Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter
91
- * @param \Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider
92
86
*/
93
87
public function __construct (
94
88
\Magento \Framework \App \RequestInterface $ request ,
95
89
\Magento \Store \Model \StoreManagerInterface $ storeManager ,
96
90
StockDataFilter $ stockFilter ,
97
91
\Magento \Catalog \Model \Product \Initialization \Helper \ProductLinks $ productLinks ,
98
92
\Magento \Backend \Helper \Js $ jsHelper ,
99
- \Magento \Framework \Stdlib \DateTime \Filter \Date $ dateFilter ,
100
- \Magento \Catalog \Model \Product \LinkTypeProvider $ linkTypeProvider = null
93
+ \Magento \Framework \Stdlib \DateTime \Filter \Date $ dateFilter
101
94
) {
102
95
$ this ->request = $ request ;
103
96
$ this ->storeManager = $ storeManager ;
104
97
$ this ->stockFilter = $ stockFilter ;
105
98
$ this ->productLinks = $ productLinks ;
106
99
$ this ->jsHelper = $ jsHelper ;
107
100
$ this ->dateFilter = $ dateFilter ;
108
- $ this ->linkTypeProvider = $ linkTypeProvider ?: \Magento \Framework \App \ObjectManager::getInstance ()
109
- ->get (\Magento \Catalog \Model \Product \LinkTypeProvider::class);
110
101
}
111
102
112
103
/**
@@ -208,18 +199,14 @@ public function initializeFromData(\Magento\Catalog\Model\Product $product, arra
208
199
$ customOptions = [];
209
200
foreach ($ options as $ customOptionData ) {
210
201
if (empty ($ customOptionData ['is_delete ' ])) {
211
- if (empty ($ customOptionData ['option_id ' ])) {
212
- $ customOptionData ['option_id ' ] = null ;
213
- }
214
-
215
202
if (isset ($ customOptionData ['values ' ])) {
216
203
$ customOptionData ['values ' ] = array_filter ($ customOptionData ['values ' ], function ($ valueData ) {
217
204
return empty ($ valueData ['is_delete ' ]);
218
205
});
219
206
}
220
-
221
207
$ customOption = $ this ->getCustomOptionFactory ()->create (['data ' => $ customOptionData ]);
222
208
$ customOption ->setProductSku ($ product ->getSku ());
209
+ $ customOption ->setOptionId (null );
223
210
$ customOptions [] = $ customOption ;
224
211
}
225
212
}
@@ -260,17 +247,11 @@ protected function setProductLinks(\Magento\Catalog\Model\Product $product)
260
247
261
248
$ product = $ this ->productLinks ->initializeLinks ($ product , $ links );
262
249
$ productLinks = $ product ->getProductLinks ();
263
- $ linkTypes = [];
264
-
265
- /** @var \Magento\Catalog\Api\Data\ProductLinkTypeInterface $linkTypeObject */
266
- foreach ($ this ->linkTypeProvider ->getItems () as $ linkTypeObject ) {
267
- $ linkTypes [$ linkTypeObject ->getName ()] = $ product ->getData ($ linkTypeObject ->getName () . '_readonly ' );
268
- }
269
-
270
- // skip linkTypes that were already processed on initializeLinks plugins
271
- foreach ($ productLinks as $ productLink ) {
272
- unset($ linkTypes [$ productLink ->getLinkType ()]);
273
- }
250
+ $ linkTypes = [
251
+ 'related ' => $ product ->getRelatedReadonly (),
252
+ 'upsell ' => $ product ->getUpsellReadonly (),
253
+ 'crosssell ' => $ product ->getCrosssellReadonly ()
254
+ ];
274
255
275
256
foreach ($ linkTypes as $ linkType => $ readonly ) {
276
257
if (isset ($ links [$ linkType ]) && !$ readonly ) {
@@ -334,59 +315,21 @@ public function mergeProductOptions($productOptions, $overwriteOptions)
334
315
return $ productOptions ;
335
316
}
336
317
337
- foreach ($ productOptions as $ optionIndex => $ option ) {
318
+ foreach ($ productOptions as $ index => $ option ) {
338
319
$ optionId = $ option ['option_id ' ];
339
- $ option = $ this ->overwriteValue (
340
- $ optionId ,
341
- $ option ,
342
- $ overwriteOptions
343
- );
344
320
345
- if (isset ($ option ['values ' ]) && isset ($ overwriteOptions [$ optionId ]['values ' ])) {
346
- foreach ($ option ['values ' ] as $ valueIndex => $ value ) {
347
- if (isset ($ value ['option_type_id ' ])) {
348
- $ valueId = $ value ['option_type_id ' ];
349
- $ value = $ this ->overwriteValue (
350
- $ valueId ,
351
- $ value ,
352
- $ overwriteOptions [$ optionId ]['values ' ]
353
- );
354
-
355
- $ option ['values ' ][$ valueIndex ] = $ value ;
356
- }
357
- }
321
+ if (!isset ($ overwriteOptions [$ optionId ])) {
322
+ continue ;
358
323
}
359
324
360
- $ productOptions [$ optionIndex ] = $ option ;
361
- }
362
-
363
- return $ productOptions ;
364
- }
365
-
366
- /**
367
- * Overwrite values of fields to default, if there are option id and field
368
- * name in array overwriteOptions.
369
- *
370
- * @param int $optionId
371
- * @param array $option
372
- * @param array $overwriteOptions
373
- *
374
- * @return array
375
- */
376
- private function overwriteValue ($ optionId , $ option , $ overwriteOptions )
377
- {
378
- if (isset ($ overwriteOptions [$ optionId ])) {
379
325
foreach ($ overwriteOptions [$ optionId ] as $ fieldName => $ overwrite ) {
380
326
if ($ overwrite && isset ($ option [$ fieldName ]) && isset ($ option ['default_ ' . $ fieldName ])) {
381
- $ option [$ fieldName ] = $ option ['default_ ' . $ fieldName ];
382
- if ('title ' == $ fieldName ) {
383
- $ option ['is_delete_store_title ' ] = 1 ;
384
- }
327
+ $ productOptions [$ index ][$ fieldName ] = $ option ['default_ ' . $ fieldName ];
385
328
}
386
329
}
387
330
}
388
331
389
- return $ option ;
332
+ return $ productOptions ;
390
333
}
391
334
392
335
/**
@@ -396,9 +339,8 @@ private function getCustomOptionFactory()
396
339
{
397
340
if (null === $ this ->customOptionFactory ) {
398
341
$ this ->customOptionFactory = \Magento \Framework \App \ObjectManager::getInstance ()
399
- ->get (\ Magento \Catalog \Api \Data \ProductCustomOptionInterfaceFactory::class );
342
+ ->get (' Magento\Catalog\Api\Data\ProductCustomOptionInterfaceFactory ' );
400
343
}
401
-
402
344
return $ this ->customOptionFactory ;
403
345
}
404
346
@@ -409,9 +351,8 @@ private function getProductLinkFactory()
409
351
{
410
352
if (null === $ this ->productLinkFactory ) {
411
353
$ this ->productLinkFactory = \Magento \Framework \App \ObjectManager::getInstance ()
412
- ->get (\ Magento \Catalog \Api \Data \ProductLinkInterfaceFactory::class );
354
+ ->get (' Magento\Catalog\Api\Data\ProductLinkInterfaceFactory ' );
413
355
}
414
-
415
356
return $ this ->productLinkFactory ;
416
357
}
417
358
@@ -422,9 +363,8 @@ private function getProductRepository()
422
363
{
423
364
if (null === $ this ->productRepository ) {
424
365
$ this ->productRepository = \Magento \Framework \App \ObjectManager::getInstance ()
425
- ->get ('\ Magento\Catalog\Api\ProductRepositoryInterface\Proxy ' );
366
+ ->get ('Magento\Catalog\Api\ProductRepositoryInterface\Proxy ' );
426
367
}
427
-
428
368
return $ this ->productRepository ;
429
369
}
430
370
@@ -437,7 +377,6 @@ private function getLinkResolver()
437
377
if (!is_object ($ this ->linkResolver )) {
438
378
$ this ->linkResolver = ObjectManager::getInstance ()->get (LinkResolver::class);
439
379
}
440
-
441
380
return $ this ->linkResolver ;
442
381
}
443
382
@@ -452,7 +391,6 @@ private function getDateTimeFilter()
452
391
$ this ->dateTimeFilter = \Magento \Framework \App \ObjectManager::getInstance ()
453
392
->get (\Magento \Framework \Stdlib \DateTime \Filter \DateTime::class);
454
393
}
455
-
456
394
return $ this ->dateTimeFilter ;
457
395
}
458
396
}
0 commit comments