6
6
7
7
namespace Magento \Bundle \Model \Product ;
8
8
9
+ use Magento \Bundle \Model \Option ;
10
+ use Magento \Bundle \Model \ResourceModel \Option \Collection ;
9
11
use Magento \Bundle \Model \ResourceModel \Selection \Collection as Selections ;
10
12
use Magento \Bundle \Model \ResourceModel \Selection \Collection \FilterApplier as SelectionCollectionFilterApplier ;
11
13
use Magento \Catalog \Api \ProductRepositoryInterface ;
@@ -459,12 +461,12 @@ public function getOptionsIds($product)
459
461
* Retrieve bundle option collection
460
462
*
461
463
* @param \Magento\Catalog\Model\Product $product
462
- * @return \Magento\Bundle\Model\ResourceModel\Option\ Collection
464
+ * @return Collection
463
465
*/
464
466
public function getOptionsCollection ($ product )
465
467
{
466
468
if (!$ product ->hasData ($ this ->_keyOptionsCollection )) {
467
- /** @var \Magento\Bundle\Model\ResourceModel\Option\ Collection $optionsCollection */
469
+ /** @var Collection $optionsCollection */
468
470
$ optionsCollection = $ this ->_bundleOption ->create ()
469
471
->getResourceCollection ();
470
472
$ optionsCollection ->setProductIdFilter ($ product ->getEntityId ());
@@ -682,6 +684,11 @@ protected function _prepareProduct(\Magento\Framework\DataObject $buyRequest, $p
682
684
$ options
683
685
);
684
686
687
+ $ this ->validateRadioAndSelectOptions (
688
+ $ optionsCollection ,
689
+ $ options
690
+ );
691
+
685
692
$ selectionIds = array_values ($ this ->arrayUtility ->flatten ($ options ));
686
693
// If product has not been configured yet then $selections array should be empty
687
694
if (!empty ($ selectionIds )) {
@@ -887,7 +894,7 @@ public function getSelectionsByIds($selectionIds, $product)
887
894
*
888
895
* @param array $optionIds
889
896
* @param \Magento\Catalog\Model\Product $product
890
- * @return \Magento\Bundle\Model\ResourceModel\Option\ Collection
897
+ * @return Collection
891
898
*/
892
899
public function getOptionsByIds ($ optionIds , $ product )
893
900
{
@@ -1254,7 +1261,7 @@ protected function getBeforeQty($product, $selection)
1254
1261
*
1255
1262
* @param \Magento\Catalog\Model\Product $product
1256
1263
* @param bool $isStrictProcessMode
1257
- * @param \Magento\Bundle\Model\ResourceModel\Option\ Collection $optionsCollection
1264
+ * @param Collection $optionsCollection
1258
1265
* @param int[] $options
1259
1266
* @return void
1260
1267
* @throws \Magento\Framework\Exception\LocalizedException
@@ -1272,12 +1279,59 @@ protected function checkIsAllRequiredOptions($product, $isStrictProcessMode, $op
1272
1279
}
1273
1280
}
1274
1281
1282
+ /**
1283
+ * Validate Options for Radio and Select input types
1284
+ *
1285
+ * @param Collection $optionsCollection
1286
+ * @param int[] $options
1287
+ * @return void
1288
+ * @throws \Magento\Framework\Exception\LocalizedException
1289
+ */
1290
+ private function validateRadioAndSelectOptions ($ optionsCollection , $ options ): void
1291
+ {
1292
+ $ errorTypes = [];
1293
+
1294
+ if (is_array ($ optionsCollection ->getItems ())) {
1295
+ foreach ($ optionsCollection ->getItems () as $ option ) {
1296
+ if ($ this ->isSelectedOptionValid ($ option , $ options )) {
1297
+ $ errorTypes [] = $ option ->getType ();
1298
+ }
1299
+ }
1300
+ }
1301
+
1302
+ if (!empty ($ errorTypes )) {
1303
+ throw new \Magento \Framework \Exception \LocalizedException (
1304
+ __ (
1305
+ 'Option type (%types) should have only one element. ' ,
1306
+ ['types ' => implode (", " , $ errorTypes )]
1307
+ )
1308
+ );
1309
+ }
1310
+ }
1311
+
1312
+ /**
1313
+ * Check if selected option is valid
1314
+ *
1315
+ * @param Option $option
1316
+ * @param array $options
1317
+ * @return bool
1318
+ */
1319
+ private function isSelectedOptionValid ($ option , $ options ): bool
1320
+ {
1321
+ return (
1322
+ ($ option ->getType () == 'radio ' || $ option ->getType () == 'select ' ) &&
1323
+ isset ($ options [$ option ->getOptionId ()]) &&
1324
+ is_array ($ options [$ option ->getOptionId ()]) &&
1325
+ count ($ options [$ option ->getOptionId ()]) > 1
1326
+ );
1327
+ }
1328
+
1275
1329
/**
1276
1330
* Check if selection is salable
1277
1331
*
1278
1332
* @param \Magento\Bundle\Model\ResourceModel\Selection\Collection $selections
1279
1333
* @param bool $skipSaleableCheck
1280
- * @param \Magento\Bundle\Model\ResourceModel\Option\ Collection $optionsCollection
1334
+ * @param Collection $optionsCollection
1281
1335
* @param int[] $options
1282
1336
* @return void
1283
1337
* @throws \Magento\Framework\Exception\LocalizedException
0 commit comments