5
5
*/
6
6
namespace Magento \BundleSampleData \Model ;
7
7
8
- use Magento \Framework \Setup \SampleData \Context as SampleDataContext ;
9
8
use Magento \Bundle \Api \Data \OptionInterfaceFactory as OptionFactory ;
10
9
use Magento \Bundle \Api \Data \LinkInterfaceFactory as LinkFactory ;
11
10
use Magento \Catalog \Api \ProductRepositoryInterface as ProductRepository ;
11
+ use \Magento \Framework \App \ObjectManager ;
12
12
13
13
/**
14
14
* Setup bundle product
@@ -23,54 +23,17 @@ class Product extends \Magento\CatalogSampleData\Model\Product
23
23
/**
24
24
* @var OptionFactory
25
25
*/
26
- protected $ optionFactory ;
26
+ private $ optionFactory ;
27
27
28
28
/**
29
29
* @var LinkFactory
30
30
*/
31
- protected $ linkFactory ;
31
+ private $ linkFactory ;
32
32
33
33
/**
34
34
* @var ProductRepository
35
35
*/
36
- protected $ productRepository ;
37
-
38
- /**
39
- * Product constructor.
40
- * @param SampleDataContext $sampleDataContext
41
- * @param \Magento\Catalog\Model\ProductFactory $productFactory
42
- * @param \Magento\Catalog\Model\ConfigFactory $catalogConfig
43
- * @param Product\Converter $converter
44
- * @param \Magento\CatalogSampleData\Model\Product\Gallery $gallery
45
- * @param \Magento\Store\Model\StoreManagerInterface $storeManager
46
- * @param \Magento\Eav\Model\Config $eavConfig
47
- */
48
- public function __construct (
49
- SampleDataContext $ sampleDataContext ,
50
- \Magento \Catalog \Model \ProductFactory $ productFactory ,
51
- \Magento \Catalog \Model \ConfigFactory $ catalogConfig ,
52
- \Magento \BundleSampleData \Model \Product \Converter $ converter ,
53
- \Magento \CatalogSampleData \Model \Product \Gallery $ gallery ,
54
- \Magento \Store \Model \StoreManagerInterface $ storeManager ,
55
- \Magento \Eav \Model \Config $ eavConfig ,
56
- OptionFactory $ optionFactory ,
57
- LinkFactory $ linkFactory ,
58
- ProductRepository $ productRepository
59
- ) {
60
- $ this ->eavConfig = $ eavConfig ;
61
- parent ::__construct (
62
- $ sampleDataContext ,
63
- $ productFactory ,
64
- $ catalogConfig ,
65
- $ converter ,
66
- $ gallery ,
67
- $ storeManager ,
68
- $ eavConfig
69
- );
70
- $ this ->optionFactory = $ optionFactory ;
71
- $ this ->linkFactory = $ linkFactory ;
72
- $ this ->productRepository = $ productRepository ;
73
- }
36
+ private $ productRepository ;
74
37
75
38
/**
76
39
* @inheritdoc
@@ -85,15 +48,15 @@ protected function prepareProduct($product, $data)
85
48
$ options = [];
86
49
foreach ($ bundleOptionsData as $ key => $ optionData ) {
87
50
88
- $ option = $ this ->optionFactory ->create (['data ' => $ optionData ]);
51
+ $ option = $ this ->getOptionFactory () ->create (['data ' => $ optionData ]);
89
52
$ option ->setSku ($ product ->getSku ());
90
53
$ option ->setOptionId (null );
91
54
92
55
$ links = [];
93
56
$ bundleLinks = $ product ->getBundleSelectionsData ();
94
57
foreach ($ bundleLinks [$ key ] as $ linkData ) {
95
- $ linkProduct = $ this ->productRepository ->getById ($ linkData ['product_id ' ]);
96
- $ link = $ this ->linkFactory ->create (['data ' => $ linkData ]);
58
+ $ linkProduct = $ this ->getProductRepository () ->getById ($ linkData ['product_id ' ]);
59
+ $ link = $ this ->getLinkFactory () ->create (['data ' => $ linkData ]);
97
60
$ link ->setSku ($ linkProduct ->getSku ());
98
61
$ link ->setQty ($ linkData ['selection_qty ' ]);
99
62
@@ -112,4 +75,58 @@ protected function prepareProduct($product, $data)
112
75
113
76
return $ this ;
114
77
}
78
+
79
+ /**
80
+ * Get option interface factory
81
+ *
82
+ * @deprecated
83
+ * @return \Magento\Bundle\Api\Data\OptionInterfaceFactory
84
+ */
85
+ private function getOptionFactory ()
86
+ {
87
+
88
+ if (!($ this ->optionFactory )) {
89
+ return ObjectManager::getInstance ()->get (
90
+ '\Magento\Catalog\Model\Product\Initialization\Helper\ProductLinks '
91
+ );
92
+ } else {
93
+ return $ this ->optionFactory ;
94
+ }
95
+ }
96
+
97
+ /**
98
+ * Get bundle link interface factory
99
+ *
100
+ * @deprecated
101
+ * @return \Magento\Bundle\Api\Data\LinkInterfaceFactory
102
+ */
103
+ private function getLinkFactory ()
104
+ {
105
+
106
+ if (!($ this ->linkFactory )) {
107
+ return ObjectManager::getInstance ()->get (
108
+ '\Magento\Catalog\Model\Product\Initialization\Helper\ProductLinks '
109
+ );
110
+ } else {
111
+ return $ this ->linkFactory ;
112
+ }
113
+ }
114
+
115
+ /**
116
+ * Get product repository
117
+ *
118
+ * @deprecated
119
+ * @return \Magento\Catalog\Api\ProductRepositoryInterface
120
+ */
121
+ private function getProductRepository ()
122
+ {
123
+
124
+ if (!($ this ->productRepository )) {
125
+ return ObjectManager::getInstance ()->get (
126
+ '\Magento\Catalog\Model\Product\Initialization\Helper\ProductLinks '
127
+ );
128
+ } else {
129
+ return $ this ->productRepository ;
130
+ }
131
+ }
115
132
}
0 commit comments