8
8
use Magento \Bundle \Api \Data \OptionInterfaceFactory as OptionFactory ;
9
9
use Magento \Bundle \Api \Data \LinkInterfaceFactory as LinkFactory ;
10
10
use Magento \Catalog \Api \Data \ProductCustomOptionInterfaceFactory ;
11
+ use Magento \Catalog \Api \Data \ProductInterface ;
11
12
use Magento \Catalog \Api \ProductRepositoryInterface as ProductRepository ;
12
13
use Magento \Store \Model \StoreManagerInterface as StoreManager ;
13
14
use Magento \Framework \App \RequestInterface ;
14
15
15
16
/**
16
- * Class Bundle
17
+ * Plugin class to initialize Bundle product
18
+ *
17
19
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
18
20
*/
19
21
class Bundle
@@ -106,12 +108,14 @@ public function afterInitialize(
106
108
$ product ->setBundleOptionsData ($ result ['bundle_options ' ]);
107
109
}
108
110
111
+ if (!$ result ['bundle_selections ' ]) {
112
+ $ this ->resetBundleProductOptions ($ product );
113
+ }
114
+
109
115
$ this ->processBundleOptionsData ($ product );
110
116
$ this ->processDynamicOptionsData ($ product );
111
117
} elseif (!$ compositeReadonly ) {
112
- $ extension = $ product ->getExtensionAttributes ();
113
- $ extension ->setBundleProductOptions ([]);
114
- $ product ->setExtensionAttributes ($ extension );
118
+ $ this ->resetBundleProductOptions ($ product );
115
119
}
116
120
117
121
$ affectProductSelections = (bool )$ this ->request ->getPost ('affect_bundle_product_selections ' );
@@ -120,6 +124,8 @@ public function afterInitialize(
120
124
}
121
125
122
126
/**
127
+ * Process Bundle Options Data
128
+ *
123
129
* @param \Magento\Catalog\Model\Product $product
124
130
* @return void
125
131
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
@@ -161,10 +167,11 @@ protected function processBundleOptionsData(\Magento\Catalog\Model\Product $prod
161
167
$ extension = $ product ->getExtensionAttributes ();
162
168
$ extension ->setBundleProductOptions ($ options );
163
169
$ product ->setExtensionAttributes ($ extension );
164
- return ;
165
170
}
166
171
167
172
/**
173
+ * Process Dynamic Options Data
174
+ *
168
175
* @param \Magento\Catalog\Model\Product $product
169
176
* @return void
170
177
*/
@@ -198,9 +205,10 @@ protected function processDynamicOptionsData(\Magento\Catalog\Model\Product $pro
198
205
}
199
206
200
207
/**
208
+ * Build product link
209
+ *
201
210
* @param \Magento\Catalog\Model\Product $product
202
211
* @param array $linkData
203
- *
204
212
* @return \Magento\Bundle\Api\Data\LinkInterface
205
213
*/
206
214
private function buildLink (
@@ -228,4 +236,18 @@ private function buildLink(
228
236
229
237
return $ link ;
230
238
}
239
+
240
+ /**
241
+ * Resets bundle product options inside product extension attributes
242
+ *
243
+ * @param ProductInterface $product
244
+ * @return void
245
+ */
246
+ private function resetBundleProductOptions (ProductInterface $ product ) : void
247
+ {
248
+ $ extension = $ product ->getExtensionAttributes ();
249
+ $ extension ->setBundleProductOptions ([]);
250
+ $ product ->setExtensionAttributes ($ extension );
251
+ $ product ->setDropOptions (true );
252
+ }
231
253
}
0 commit comments