7
7
8
8
namespace Magento \Bundle \Model \Option ;
9
9
10
+ use Magento \Bundle \Api \Data \LinkInterface ;
10
11
use Magento \Bundle \Api \Data \OptionInterface ;
11
12
use Magento \Bundle \Model \ResourceModel \Option ;
12
13
use Magento \Catalog \Api \Data \ProductInterface ;
14
+ use Magento \Framework \App \ObjectManager ;
13
15
use Magento \Framework \EntityManager \MetadataPool ;
14
16
use Magento \Framework \Exception \CouldNotSaveException ;
15
17
use Magento \Bundle \Model \Product \Type ;
@@ -51,20 +53,21 @@ class SaveAction
51
53
* @param MetadataPool $metadataPool
52
54
* @param Type $type
53
55
* @param ProductLinkManagementInterface $linkManagement
54
- * @param StoreManagerInterface $storeManager
56
+ * @param StoreManagerInterface|null $storeManager
55
57
*/
56
58
public function __construct (
57
59
Option $ optionResource ,
58
60
MetadataPool $ metadataPool ,
59
61
Type $ type ,
60
62
ProductLinkManagementInterface $ linkManagement ,
61
- StoreManagerInterface $ storeManager
63
+ ? StoreManagerInterface $ storeManager = null
62
64
) {
63
65
$ this ->optionResource = $ optionResource ;
64
66
$ this ->metadataPool = $ metadataPool ;
65
67
$ this ->type = $ type ;
66
68
$ this ->linkManagement = $ linkManagement ;
67
- $ this ->storeManager = $ storeManager ;
69
+ $ this ->storeManager = $ storeManager
70
+ ?: ObjectManager::getInstance ()->get (StoreManagerInterface::class);
68
71
}
69
72
70
73
/**
@@ -78,7 +81,7 @@ public function __construct(
78
81
*/
79
82
public function save (ProductInterface $ bundleProduct , OptionInterface $ option )
80
83
{
81
- $ metadata = $ this ->metadataPool ->getMetadata (\ Magento \ Catalog \ Api \ Data \ ProductInterface::class);
84
+ $ metadata = $ this ->metadataPool ->getMetadata (ProductInterface::class);
82
85
83
86
$ option ->setStoreId ($ bundleProduct ->getStoreId ());
84
87
$ parentId = $ bundleProduct ->getData ($ metadata ->getLinkField ());
@@ -117,7 +120,7 @@ public function save(ProductInterface $bundleProduct, OptionInterface $option)
117
120
throw new CouldNotSaveException (__ ("The option couldn't be saved. " ), $ e );
118
121
}
119
122
120
- /** @var \Magento\Bundle\Api\Data\ LinkInterface $linkedProduct */
123
+ /** @var LinkInterface $linkedProduct */
121
124
foreach ($ linksToAdd as $ linkedProduct ) {
122
125
$ this ->linkManagement ->addChild ($ bundleProduct , $ option ->getOptionId (), $ linkedProduct );
123
126
}
@@ -130,8 +133,8 @@ public function save(ProductInterface $bundleProduct, OptionInterface $option)
130
133
/**
131
134
* Update option selections
132
135
*
133
- * @param \Magento\Catalog\Api\Data\ ProductInterface $product
134
- * @param \Magento\Bundle\Api\Data\ OptionInterface $option
136
+ * @param ProductInterface $product
137
+ * @param OptionInterface $option
135
138
* @return void
136
139
*/
137
140
private function updateOptionSelection (ProductInterface $ product , OptionInterface $ option )
@@ -151,7 +154,7 @@ private function updateOptionSelection(ProductInterface $product, OptionInterfac
151
154
$ linksToUpdate [] = $ productLink ;
152
155
}
153
156
}
154
- /** @var \Magento\Bundle\Api\Data\ LinkInterface[] $linksToDelete */
157
+ /** @var LinkInterface[] $linksToDelete */
155
158
$ linksToDelete = $ this ->compareLinks ($ existingLinks , $ linksToUpdate );
156
159
}
157
160
foreach ($ linksToUpdate as $ linkedProduct ) {
@@ -172,8 +175,8 @@ private function updateOptionSelection(ProductInterface $product, OptionInterfac
172
175
/**
173
176
* Compute the difference between given arrays.
174
177
*
175
- * @param \Magento\Bundle\Api\Data\ LinkInterface[] $firstArray
176
- * @param \Magento\Bundle\Api\Data\ LinkInterface[] $secondArray
178
+ * @param LinkInterface[] $firstArray
179
+ * @param LinkInterface[] $secondArray
177
180
*
178
181
* @return array
179
182
*/
0 commit comments