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,12 +194,13 @@ public function getJsonConfig()
193
194
$ options [$ optionId ]['selections ' ][$ configValue ]['qty ' ] = $ configQty ;
194
195
}
195
196
}
197
+ $ options = $ this ->processOptions ($ optionId , $ options , $ preConfiguredValues );
196
198
}
197
199
$ position ++;
198
200
}
199
201
$ config = $ this ->getConfigData ($ currentProduct , $ options );
200
202
201
- $ configObj = new \ Magento \ Framework \ DataObject (
203
+ $ configObj = new DataObject (
202
204
[
203
205
'config ' => $ config ,
204
206
]
@@ -403,4 +405,30 @@ private function getConfigData(Product $product, array $options)
403
405
];
404
406
return $ config ;
405
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
+ }
406
434
}
0 commit comments