7
7
8
8
use Magento \Bundle \Model \Option ;
9
9
use Magento \Catalog \Model \Product ;
10
+ use Magento \Framework \DataObject ;
10
11
11
12
/**
12
13
* Catalog bundle product info block
@@ -170,7 +171,7 @@ public function getJsonConfig()
170
171
171
172
$ defaultValues = [];
172
173
$ preConfiguredFlag = $ currentProduct ->hasPreconfiguredValues ();
173
- /** @var \Magento\Framework\ DataObject|null $preConfiguredValues */
174
+ /** @var DataObject|null $preConfiguredValues */
174
175
$ preConfiguredValues = $ preConfiguredFlag ? $ currentProduct ->getPreconfiguredValues () : null ;
175
176
176
177
$ position = 0 ;
@@ -193,23 +194,13 @@ public function getJsonConfig()
193
194
$ options [$ optionId ]['selections ' ][$ configValue ]['qty ' ] = $ configQty ;
194
195
}
195
196
}
196
-
197
- $ preConfiguredQtys = $ preConfiguredValues ->getData ("bundle_option_qty/ $ {optionId}" ) ?? [];
198
- $ selections = $ options [$ optionId ]['selections ' ];
199
- array_walk ($ selections , function (&$ selection , $ selectionId ) use ($ preConfiguredQtys ) {
200
- if (is_array ($ preConfiguredQtys ) && isset ($ preConfiguredQtys [$ selectionId ])) {
201
- $ selection ['qty ' ] = $ preConfiguredQtys [$ selectionId ];
202
- } else if ((int )$ preConfiguredQtys > 0 ) {
203
- $ selection ['qty ' ] = $ preConfiguredQtys ;
204
- }
205
- });
206
- $ options [$ optionId ]['selections ' ] = $ selections ;
197
+ $ options = $ this ->processOptions ($ optionId , $ options , $ preConfiguredValues );
207
198
}
208
199
$ position ++;
209
200
}
210
201
$ config = $ this ->getConfigData ($ currentProduct , $ options );
211
202
212
- $ configObj = new \ Magento \ Framework \ DataObject (
203
+ $ configObj = new DataObject (
213
204
[
214
205
'config ' => $ config ,
215
206
]
@@ -414,4 +405,30 @@ private function getConfigData(Product $product, array $options)
414
405
];
415
406
return $ config ;
416
407
}
408
+
409
+ /**
410
+ * Set preconfigured quantities and selections to options.
411
+ *
412
+ * @param string $optionId
413
+ * @param array $options
414
+ * @param DataObject $preConfiguredValues
415
+ * @return array
416
+ */
417
+ private function processOptions (string $ optionId , array $ options , DataObject $ preConfiguredValues )
418
+ {
419
+ $ preConfiguredQtys = $ preConfiguredValues ->getData ("bundle_option_qty/ $ {optionId}" ) ?? [];
420
+ $ selections = $ options [$ optionId ]['selections ' ];
421
+ array_walk ($ selections , function (&$ selection , $ selectionId ) use ($ preConfiguredQtys ) {
422
+ if (is_array ($ preConfiguredQtys ) && isset ($ preConfiguredQtys [$ selectionId ])) {
423
+ $ selection ['qty ' ] = $ preConfiguredQtys [$ selectionId ];
424
+ } else {
425
+ if ((int )$ preConfiguredQtys > 0 ) {
426
+ $ selection ['qty ' ] = $ preConfiguredQtys ;
427
+ }
428
+ }
429
+ });
430
+ $ options [$ optionId ]['selections ' ] = $ selections ;
431
+
432
+ return $ options ;
433
+ }
417
434
}
0 commit comments