5
5
*/
6
6
namespace Magento \Catalog \Controller \Adminhtml \Product \Initialization ;
7
7
8
+ use Magento \Backend \Helper \Js ;
8
9
use Magento \Catalog \Api \Data \ProductCustomOptionInterfaceFactory as CustomOptionFactory ;
9
10
use Magento \Catalog \Api \Data \ProductLinkInterfaceFactory as ProductLinkFactory ;
10
11
use Magento \Catalog \Api \ProductRepositoryInterface \Proxy as ProductRepository ;
11
12
use Magento \Catalog \Model \Product ;
12
13
use Magento \Catalog \Model \Product \Initialization \Helper \ProductLinks ;
13
14
use Magento \Catalog \Model \Product \Link \Resolver as LinkResolver ;
15
+ use Magento \Catalog \Model \Product \LinkTypeProvider ;
14
16
use Magento \Framework \App \ObjectManager ;
17
+ use Magento \Framework \App \RequestInterface ;
18
+ use Magento \Framework \Stdlib \DateTime \Filter \Date as DateFilter ;
19
+ use Magento \Framework \Stdlib \DateTime \Filter \DateTime ;
20
+ use Magento \Store \Model \StoreManagerInterface ;
15
21
16
22
/**
17
23
* Class Helper
20
26
class Helper
21
27
{
22
28
/**
23
- * @var \Magento\Framework\App\ RequestInterface
29
+ * @var RequestInterface
24
30
*/
25
31
protected $ request ;
26
32
27
33
/**
28
- * @var \Magento\Store\Model\ StoreManagerInterface
34
+ * @var StoreManagerInterface
29
35
*/
30
36
protected $ storeManager ;
31
37
@@ -35,12 +41,12 @@ class Helper
35
41
protected $ stockFilter ;
36
42
37
43
/**
38
- * @var \Magento\Backend\Helper\ Js
44
+ * @var Js
39
45
*/
40
46
protected $ jsHelper ;
41
47
42
48
/**
43
- * @var \Magento\Framework\Stdlib\DateTime\Filter\ Date
49
+ * @var Date
44
50
*
45
51
* @deprecated
46
52
*/
@@ -72,42 +78,76 @@ class Helper
72
78
private $ linkResolver ;
73
79
74
80
/**
75
- * @var \Magento\Framework\Stdlib\DateTime\Filter\ DateTime
81
+ * @var DateTime
76
82
*/
77
83
private $ dateTimeFilter ;
78
84
79
85
/**
80
- * @var \Magento\Catalog\Model\Product\ LinkTypeProvider
86
+ * @var LinkTypeProvider
81
87
*/
82
88
private $ linkTypeProvider ;
83
89
84
90
/**
85
91
* Helper constructor.
86
- * @param \Magento\Framework\App\ RequestInterface $request
87
- * @param \Magento\Store\Model\ StoreManagerInterface $storeManager
92
+ * @param RequestInterface $request
93
+ * @param StoreManagerInterface $storeManager
88
94
* @param StockDataFilter $stockFilter
89
95
* @param ProductLinks $productLinks
90
- * @param \Magento\Backend\Helper\Js $jsHelper
91
- * @param \Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter
92
- * @param \Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider
96
+ * @param Js $jsHelper
97
+ * @param DateFilter $dateFilter
98
+ * @param LinkTypeProvider|null $linkTypeProvider
99
+ * @param CustomOptionFactory|null $customOptionFactory
100
+ * @param ProductLinkFactory|null $productLinkFactory
101
+ * @param ProductRepository|null $productRepository
102
+ * @param DateTime|null $dateTimeFilter
103
+ * @param LinkResolver|null $linkResolver
104
+ * @throws \RuntimeException
105
+ * @SuppressWarnings(PHPMD.ExcessiveParameterList)
93
106
*/
94
107
public function __construct (
95
- \ Magento \ Framework \ App \ RequestInterface $ request ,
96
- \ Magento \ Store \ Model \ StoreManagerInterface $ storeManager ,
108
+ RequestInterface $ request ,
109
+ StoreManagerInterface $ storeManager ,
97
110
StockDataFilter $ stockFilter ,
98
- \Magento \Catalog \Model \Product \Initialization \Helper \ProductLinks $ productLinks ,
99
- \Magento \Backend \Helper \Js $ jsHelper ,
100
- \Magento \Framework \Stdlib \DateTime \Filter \Date $ dateFilter ,
101
- \Magento \Catalog \Model \Product \LinkTypeProvider $ linkTypeProvider = null
111
+ ProductLinks $ productLinks ,
112
+ Js $ jsHelper ,
113
+ DateFilter $ dateFilter ,
114
+ LinkTypeProvider $ linkTypeProvider = null ,
115
+ CustomOptionFactory $ customOptionFactory = null ,
116
+ ProductLinkFactory $ productLinkFactory = null ,
117
+ ProductRepository $ productRepository = null ,
118
+ DateTime $ dateTimeFilter = null ,
119
+ LinkResolver $ linkResolver = null
102
120
) {
121
+ if (null === $ linkTypeProvider ) {
122
+ $ linkTypeProvider = ObjectManager::getInstance ()->get (LinkTypeProvider::class);
123
+ }
124
+ if (null === $ customOptionFactory ) {
125
+ $ customOptionFactory = ObjectManager::getInstance ()->get (CustomOptionFactory::class);
126
+ }
127
+ if (null === $ productLinkFactory ) {
128
+ $ productLinkFactory = ObjectManager::getInstance ()->get (ProductLinkFactory::class);
129
+ }
130
+ if (null === $ productRepository ) {
131
+ $ productRepository = ObjectManager::getInstance ()->get (ProductRepository::class);
132
+ }
133
+ if (null === $ dateTimeFilter ) {
134
+ $ dateTimeFilter = ObjectManager::getInstance ()->get (DateTime::class);
135
+ }
136
+ if (null === $ linkResolver ) {
137
+ $ linkResolver = ObjectManager::getInstance ()->get (LinkResolver::class);
138
+ }
103
139
$ this ->request = $ request ;
104
140
$ this ->storeManager = $ storeManager ;
105
141
$ this ->stockFilter = $ stockFilter ;
106
142
$ this ->productLinks = $ productLinks ;
107
143
$ this ->jsHelper = $ jsHelper ;
108
144
$ this ->dateFilter = $ dateFilter ;
109
- $ this ->linkTypeProvider = $ linkTypeProvider ?: \Magento \Framework \App \ObjectManager::getInstance ()
110
- ->get (\Magento \Catalog \Model \Product \LinkTypeProvider::class);
145
+ $ this ->linkTypeProvider = $ linkTypeProvider ;
146
+ $ this ->customOptionFactory = $ customOptionFactory ;
147
+ $ this ->productLinkFactory = $ productLinkFactory ;
148
+ $ this ->productRepository = $ productRepository ;
149
+ $ this ->dateTimeFilter = $ dateTimeFilter ;
150
+ $ this ->linkResolver = $ linkResolver ;
111
151
}
112
152
113
153
/**
@@ -159,7 +199,7 @@ public function initializeFromData(Product $product, array $productData)
159
199
foreach ($ attributes as $ attrKey => $ attribute ) {
160
200
if ($ attribute ->getBackend ()->getType () == 'datetime ' ) {
161
201
if (array_key_exists ($ attrKey , $ productData ) && $ productData [$ attrKey ] != '' ) {
162
- $ dateFieldFilters [$ attrKey ] = $ this ->getDateTimeFilter () ;
202
+ $ dateFieldFilters [$ attrKey ] = $ this ->dateTimeFilter ;
163
203
}
164
204
}
165
205
}
@@ -222,11 +262,12 @@ public function initialize(Product $product)
222
262
*
223
263
* @param Product $product
224
264
* @return Product
265
+ * @throws \Magento\Framework\Exception\NoSuchEntityException
225
266
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
226
267
*/
227
268
protected function setProductLinks (Product $ product )
228
269
{
229
- $ links = $ this ->getLinkResolver () ->getLinks ();
270
+ $ links = $ this ->linkResolver ->getLinks ();
230
271
231
272
$ product ->setProductLinks ([]);
232
273
@@ -251,8 +292,8 @@ protected function setProductLinks(Product $product)
251
292
continue ;
252
293
}
253
294
254
- $ linkProduct = $ this ->getProductRepository () ->getById ($ linkData ['id ' ]);
255
- $ link = $ this ->getProductLinkFactory () ->create ();
295
+ $ linkProduct = $ this ->productRepository ->getById ($ linkData ['id ' ]);
296
+ $ link = $ this ->productLinkFactory ->create ();
256
297
$ link ->setSku ($ product ->getSku ())
257
298
->setLinkedProductSku ($ linkProduct ->getSku ())
258
299
->setLinkType ($ linkType )
@@ -360,73 +401,6 @@ private function overwriteValue($optionId, $option, $overwriteOptions)
360
401
return $ option ;
361
402
}
362
403
363
- /**
364
- * @return CustomOptionFactory
365
- */
366
- private function getCustomOptionFactory ()
367
- {
368
- if (null === $ this ->customOptionFactory ) {
369
- $ this ->customOptionFactory = \Magento \Framework \App \ObjectManager::getInstance ()
370
- ->get (\Magento \Catalog \Api \Data \ProductCustomOptionInterfaceFactory::class);
371
- }
372
-
373
- return $ this ->customOptionFactory ;
374
- }
375
-
376
- /**
377
- * @return ProductLinkFactory
378
- */
379
- private function getProductLinkFactory ()
380
- {
381
- if (null === $ this ->productLinkFactory ) {
382
- $ this ->productLinkFactory = \Magento \Framework \App \ObjectManager::getInstance ()
383
- ->get (\Magento \Catalog \Api \Data \ProductLinkInterfaceFactory::class);
384
- }
385
-
386
- return $ this ->productLinkFactory ;
387
- }
388
-
389
- /**
390
- * @return ProductRepository
391
- */
392
- private function getProductRepository ()
393
- {
394
- if (null === $ this ->productRepository ) {
395
- $ this ->productRepository = \Magento \Framework \App \ObjectManager::getInstance ()
396
- ->get (\Magento \Catalog \Api \ProductRepositoryInterface \Proxy::class);
397
- }
398
-
399
- return $ this ->productRepository ;
400
- }
401
-
402
- /**
403
- * @deprecated
404
- * @return LinkResolver
405
- */
406
- private function getLinkResolver ()
407
- {
408
- if (!is_object ($ this ->linkResolver )) {
409
- $ this ->linkResolver = ObjectManager::getInstance ()->get (LinkResolver::class);
410
- }
411
-
412
- return $ this ->linkResolver ;
413
- }
414
-
415
- /**
416
- * @return \Magento\Framework\Stdlib\DateTime\Filter\DateTime
417
- *
418
- * @deprecated
419
- */
420
- private function getDateTimeFilter ()
421
- {
422
- if ($ this ->dateTimeFilter === null ) {
423
- $ this ->dateTimeFilter = \Magento \Framework \App \ObjectManager::getInstance ()
424
- ->get (\Magento \Framework \Stdlib \DateTime \Filter \DateTime::class);
425
- }
426
-
427
- return $ this ->dateTimeFilter ;
428
- }
429
-
430
404
/**
431
405
* Fills $product with options from $productOptions array
432
406
*
@@ -464,7 +438,7 @@ function ($valueData) {
464
438
}
465
439
);
466
440
}
467
- $ customOption = $ this ->getCustomOptionFactory () ->create (
441
+ $ customOption = $ this ->customOptionFactory ->create (
468
442
['data ' => $ customOptionData ]
469
443
);
470
444
$ customOption ->setProductSku ($ product ->getSku ());
0 commit comments