66
77namespace Magento \Bundle \Model \Product ;
88
9+ use Magento \Bundle \Model \Option ;
10+ use Magento \Bundle \Model \ResourceModel \Option \Collection ;
911use Magento \Bundle \Model \ResourceModel \Selection \Collection as Selections ;
1012use Magento \Bundle \Model \ResourceModel \Selection \Collection \FilterApplier as SelectionCollectionFilterApplier ;
1113use Magento \Catalog \Api \ProductRepositoryInterface ;
@@ -459,12 +461,12 @@ public function getOptionsIds($product)
459461 * Retrieve bundle option collection
460462 *
461463 * @param \Magento\Catalog\Model\Product $product
462- * @return \Magento\Bundle\Model\ResourceModel\Option\ Collection
464+ * @return Collection
463465 */
464466 public function getOptionsCollection ($ product )
465467 {
466468 if (!$ product ->hasData ($ this ->_keyOptionsCollection )) {
467- /** @var \Magento\Bundle\Model\ResourceModel\Option\ Collection $optionsCollection */
469+ /** @var Collection $optionsCollection */
468470 $ optionsCollection = $ this ->_bundleOption ->create ()
469471 ->getResourceCollection ();
470472 $ optionsCollection ->setProductIdFilter ($ product ->getEntityId ());
@@ -682,6 +684,11 @@ protected function _prepareProduct(\Magento\Framework\DataObject $buyRequest, $p
682684 $ options
683685 );
684686
687+ $ this ->validateRadioAndSelectOptions (
688+ $ optionsCollection ,
689+ $ options
690+ );
691+
685692 $ selectionIds = array_values ($ this ->arrayUtility ->flatten ($ options ));
686693 // If product has not been configured yet then $selections array should be empty
687694 if (!empty ($ selectionIds )) {
@@ -887,7 +894,7 @@ public function getSelectionsByIds($selectionIds, $product)
887894 *
888895 * @param array $optionIds
889896 * @param \Magento\Catalog\Model\Product $product
890- * @return \Magento\Bundle\Model\ResourceModel\Option\ Collection
897+ * @return Collection
891898 */
892899 public function getOptionsByIds ($ optionIds , $ product )
893900 {
@@ -1254,7 +1261,7 @@ protected function getBeforeQty($product, $selection)
12541261 *
12551262 * @param \Magento\Catalog\Model\Product $product
12561263 * @param bool $isStrictProcessMode
1257- * @param \Magento\Bundle\Model\ResourceModel\Option\ Collection $optionsCollection
1264+ * @param Collection $optionsCollection
12581265 * @param int[] $options
12591266 * @return void
12601267 * @throws \Magento\Framework\Exception\LocalizedException
@@ -1272,12 +1279,59 @@ protected function checkIsAllRequiredOptions($product, $isStrictProcessMode, $op
12721279 }
12731280 }
12741281
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+
12751329 /**
12761330 * Check if selection is salable
12771331 *
12781332 * @param \Magento\Bundle\Model\ResourceModel\Selection\Collection $selections
12791333 * @param bool $skipSaleableCheck
1280- * @param \Magento\Bundle\Model\ResourceModel\Option\ Collection $optionsCollection
1334+ * @param Collection $optionsCollection
12811335 * @param int[] $options
12821336 * @return void
12831337 * @throws \Magento\Framework\Exception\LocalizedException
0 commit comments