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 \Initialization \Helper \ProductLinks ;
12
13
use Magento \Catalog \Model \Product \Link \Resolver as LinkResolver ;
14
+ use Magento \Catalog \Model \Product \LinkTypeProvider ;
13
15
use Magento \Framework \App \ObjectManager ;
16
+ use Magento \Framework \App \RequestInterface ;
17
+ use Magento \Framework \Stdlib \DateTime \Filter \Date as DateFilter ;
18
+ use Magento \Framework \Stdlib \DateTime \Filter \DateTime ;
19
+ use Magento \Store \Model \StoreManagerInterface ;
14
20
15
21
/**
16
22
* Class Helper
19
25
class Helper
20
26
{
21
27
/**
22
- * @var \Magento\Framework\App\ RequestInterface
28
+ * @var RequestInterface
23
29
*/
24
30
protected $ request ;
25
31
26
32
/**
27
- * @var \Magento\Store\Model\ StoreManagerInterface
33
+ * @var StoreManagerInterface
28
34
*/
29
35
protected $ storeManager ;
30
36
@@ -34,12 +40,12 @@ class Helper
34
40
protected $ stockFilter ;
35
41
36
42
/**
37
- * @var \Magento\Backend\Helper\ Js
43
+ * @var Js
38
44
*/
39
45
protected $ jsHelper ;
40
46
41
47
/**
42
- * @var \Magento\Framework\Stdlib\DateTime\Filter\ Date
48
+ * @var Date
43
49
*
44
50
* @deprecated
45
51
*/
@@ -71,42 +77,69 @@ class Helper
71
77
private $ linkResolver ;
72
78
73
79
/**
74
- * @var \Magento\Framework\Stdlib\DateTime\Filter\ DateTime
80
+ * @var DateTime
75
81
*/
76
82
private $ dateTimeFilter ;
77
83
78
84
/**
79
- * @var \Magento\Catalog\Model\Product\ LinkTypeProvider
85
+ * @var LinkTypeProvider
80
86
*/
81
87
private $ linkTypeProvider ;
82
88
83
89
/**
84
90
* Helper constructor.
85
- * @param \Magento\Framework\App\ RequestInterface $request
86
- * @param \Magento\Store\Model\ StoreManagerInterface $storeManager
91
+ * @param RequestInterface $request
92
+ * @param StoreManagerInterface $storeManager
87
93
* @param StockDataFilter $stockFilter
88
94
* @param ProductLinks $productLinks
89
- * @param \Magento\Backend\Helper\Js $jsHelper
90
- * @param \Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter
91
- * @param \Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider
95
+ * @param Js $jsHelper
96
+ * @param DateFilter $dateFilter
97
+ * @param LinkTypeProvider $linkTypeProvider
98
+ * @param CustomOptionFactory $customOptionFactory
99
+ * @param ProductLinkFactory $productLinkFactory
100
+ * @param ProductRepository $productRepository
101
+ * @param CustomOptionFactory $customOptionFactory
102
+ * @param DateTime $dateTimeFilter
92
103
*/
93
104
public function __construct (
94
- \ Magento \ Framework \ App \ RequestInterface $ request ,
95
- \ Magento \ Store \ Model \ StoreManagerInterface $ storeManager ,
105
+ RequestInterface $ request ,
106
+ StoreManagerInterface $ storeManager ,
96
107
StockDataFilter $ stockFilter ,
97
- \Magento \Catalog \Model \Product \Initialization \Helper \ProductLinks $ productLinks ,
98
- \Magento \Backend \Helper \Js $ jsHelper ,
99
- \Magento \Framework \Stdlib \DateTime \Filter \Date $ dateFilter ,
100
- \Magento \Catalog \Model \Product \LinkTypeProvider $ linkTypeProvider = null
108
+ ProductLinks $ productLinks ,
109
+ Js $ jsHelper ,
110
+ DateFilter $ dateFilter ,
111
+ LinkTypeProvider $ linkTypeProvider = null ,
112
+ CustomOptionFactory $ customOptionFactory ,
113
+ ProductLinkFactory $ productLinkFactory ,
114
+ ProductRepository $ productRepository ,
115
+ DateTime $ dateTimeFilter
101
116
) {
117
+ if (null === $ linkTypeProvider ) {
118
+ $ linkTypeProvider = ObjectManager::getInstance ()->get (LinkTypeProvider::class);
119
+ }
120
+ if (null === $ customOptionFactory ) {
121
+ $ customOptionFactory = ObjectManager::getInstance ()->get (CustomOptionFactory::class);
122
+ }
123
+ if (null === $ productLinkFactory ) {
124
+ $ productLinkFactory = ObjectManager::getInstance ()->get (ProductLinkFactory::class);
125
+ }
126
+ if (null === $ productRepository ) {
127
+ $ productRepository = ObjectManager::getInstance ()->get (ProductRepository::class);
128
+ }
129
+ if (null === $ dateTimeFilter ) {
130
+ $ dateTimeFilter = ObjectManager::getInstance ()->get (DateTime::class);
131
+ }
102
132
$ this ->request = $ request ;
103
133
$ this ->storeManager = $ storeManager ;
104
134
$ this ->stockFilter = $ stockFilter ;
105
135
$ this ->productLinks = $ productLinks ;
106
136
$ this ->jsHelper = $ jsHelper ;
107
137
$ this ->dateFilter = $ dateFilter ;
108
- $ this ->linkTypeProvider = $ linkTypeProvider ?: \Magento \Framework \App \ObjectManager::getInstance ()
109
- ->get (\Magento \Catalog \Model \Product \LinkTypeProvider::class);
138
+ $ this ->linkTypeProvider = $ linkTypeProvider ;
139
+ $ this ->customOptionFactory = $ customOptionFactory ;
140
+ $ this ->productLinkFactory = $ productLinkFactory ;
141
+ $ this ->productRepository = $ productRepository ;
142
+ $ this ->dateTimeFilter = $ dateTimeFilter ;
110
143
}
111
144
112
145
/**
@@ -158,7 +191,7 @@ public function initializeFromData(\Magento\Catalog\Model\Product $product, arra
158
191
foreach ($ attributes as $ attrKey => $ attribute ) {
159
192
if ($ attribute ->getBackend ()->getType () == 'datetime ' ) {
160
193
if (array_key_exists ($ attrKey , $ productData ) && $ productData [$ attrKey ] != '' ) {
161
- $ dateFieldFilters [$ attrKey ] = $ this ->getDateTimeFilter () ;
194
+ $ dateFieldFilters [$ attrKey ] = $ this ->dateTimeFilter ;
162
195
}
163
196
}
164
197
}
@@ -250,11 +283,12 @@ public function initialize(\Magento\Catalog\Model\Product $product)
250
283
*
251
284
* @param \Magento\Catalog\Model\Product $product
252
285
* @return \Magento\Catalog\Model\Product
286
+ * @throws \Magento\Framework\Exception\NoSuchEntityException
253
287
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
254
288
*/
255
289
protected function setProductLinks (\Magento \Catalog \Model \Product $ product )
256
290
{
257
- $ links = $ this ->getLinkResolver () ->getLinks ();
291
+ $ links = $ this ->linkResolver ->getLinks ();
258
292
259
293
$ product ->setProductLinks ([]);
260
294
@@ -279,8 +313,8 @@ protected function setProductLinks(\Magento\Catalog\Model\Product $product)
279
313
continue ;
280
314
}
281
315
282
- $ linkProduct = $ this ->getProductRepository () ->getById ($ linkData ['id ' ]);
283
- $ link = $ this ->getProductLinkFactory () ->create ();
316
+ $ linkProduct = $ this ->productRepository ->getById ($ linkData ['id ' ]);
317
+ $ link = $ this ->productLinkFactory ->create ();
284
318
$ link ->setSku ($ product ->getSku ())
285
319
->setLinkedProductSku ($ linkProduct ->getSku ())
286
320
->setLinkType ($ linkType )
@@ -387,71 +421,4 @@ private function overwriteValue($optionId, $option, $overwriteOptions)
387
421
388
422
return $ option ;
389
423
}
390
-
391
- /**
392
- * @return CustomOptionFactory
393
- */
394
- private function getCustomOptionFactory ()
395
- {
396
- if (null === $ this ->customOptionFactory ) {
397
- $ this ->customOptionFactory = \Magento \Framework \App \ObjectManager::getInstance ()
398
- ->get (\Magento \Catalog \Api \Data \ProductCustomOptionInterfaceFactory::class);
399
- }
400
-
401
- return $ this ->customOptionFactory ;
402
- }
403
-
404
- /**
405
- * @return ProductLinkFactory
406
- */
407
- private function getProductLinkFactory ()
408
- {
409
- if (null === $ this ->productLinkFactory ) {
410
- $ this ->productLinkFactory = \Magento \Framework \App \ObjectManager::getInstance ()
411
- ->get (\Magento \Catalog \Api \Data \ProductLinkInterfaceFactory::class);
412
- }
413
-
414
- return $ this ->productLinkFactory ;
415
- }
416
-
417
- /**
418
- * @return ProductRepository
419
- */
420
- private function getProductRepository ()
421
- {
422
- if (null === $ this ->productRepository ) {
423
- $ this ->productRepository = \Magento \Framework \App \ObjectManager::getInstance ()
424
- ->get (\Magento \Catalog \Api \ProductRepositoryInterface \Proxy::class);
425
- }
426
-
427
- return $ this ->productRepository ;
428
- }
429
-
430
- /**
431
- * @deprecated
432
- * @return LinkResolver
433
- */
434
- private function getLinkResolver ()
435
- {
436
- if (!is_object ($ this ->linkResolver )) {
437
- $ this ->linkResolver = ObjectManager::getInstance ()->get (LinkResolver::class);
438
- }
439
-
440
- return $ this ->linkResolver ;
441
- }
442
-
443
- /**
444
- * @return \Magento\Framework\Stdlib\DateTime\Filter\DateTime
445
- *
446
- * @deprecated
447
- */
448
- private function getDateTimeFilter ()
449
- {
450
- if ($ this ->dateTimeFilter === null ) {
451
- $ this ->dateTimeFilter = \Magento \Framework \App \ObjectManager::getInstance ()
452
- ->get (\Magento \Framework \Stdlib \DateTime \Filter \DateTime::class);
453
- }
454
-
455
- return $ this ->dateTimeFilter ;
456
- }
457
424
}
0 commit comments