Skip to content

Commit 8ea824e

Browse files
committed
Custom option type select - Allow modify list of single selection option types
1 parent 6d8e725 commit 8ea824e

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

app/code/Magento/Catalog/Model/Product/Option/Type/Select.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,35 @@ class Select extends \Magento\Catalog\Model\Product\Option\Type\DefaultType
3030
*/
3131
protected $string;
3232

33+
/**
34+
* @var array
35+
*/
36+
private $singleSelectionTypes;
37+
3338
/**
3439
* @param \Magento\Checkout\Model\Session $checkoutSession
3540
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
3641
* @param \Magento\Framework\Stdlib\StringUtils $string
3742
* @param \Magento\Framework\Escaper $escaper
3843
* @param array $data
44+
* @param array $singleSelectionTypes
3945
*/
4046
public function __construct(
4147
\Magento\Checkout\Model\Session $checkoutSession,
4248
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
4349
\Magento\Framework\Stdlib\StringUtils $string,
4450
\Magento\Framework\Escaper $escaper,
45-
array $data = []
51+
array $data = [],
52+
array $singleSelectionTypes = []
4653
) {
4754
$this->string = $string;
4855
$this->_escaper = $escaper;
4956
parent::__construct($checkoutSession, $scopeConfig, $data);
57+
58+
$this->singleSelectionTypes = $singleSelectionTypes ?: [
59+
\Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_TYPE_DROP_DOWN,
60+
\Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_TYPE_RADIO,
61+
];
5062
}
5163

5264
/**
@@ -310,10 +322,6 @@ public function getOptionSku($optionValue, $skuDelimiter)
310322
*/
311323
protected function _isSingleSelection()
312324
{
313-
$single = [
314-
\Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_TYPE_DROP_DOWN,
315-
\Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_TYPE_RADIO,
316-
];
317-
return in_array($this->getOption()->getType(), $single);
325+
return in_array($this->getOption()->getType(), $this->singleSelectionTypes, true);
318326
}
319327
}

app/code/Magento/Catalog/etc/di.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,4 +1164,12 @@
11641164
</argument>
11651165
</arguments>
11661166
</type>
1167+
<type name="Magento\Catalog\Model\Product\Option\Type\Select">
1168+
<arguments>
1169+
<argument name="singleSelectionTypes" xsi:type="array">
1170+
<item name="drop_down" xsi:type="const">Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_TYPE_DROP_DOWN</item>
1171+
<item name="radio" xsi:type="const">Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_TYPE_RADIO</item>
1172+
</argument>
1173+
</arguments>
1174+
</type>
11671175
</config>

0 commit comments

Comments
 (0)