Skip to content

Commit 78d5ab5

Browse files
ENGCOM-4588: Custom option type select - Allow modify list of single selection option types #21744
- Merge Pull Request #21744 from ihor-sviziev/magento2:custom-option-select-allow-modify-single-selection-list - Merged commits: 1. 8ea824e 2. 996cb1a 3. 03cfa37
2 parents d3fdecf + 03cfa37 commit 78d5ab5

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
/**
1212
* Catalog product option select type
13+
*
14+
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
1315
*/
1416
class Select extends \Magento\Catalog\Model\Product\Option\Type\DefaultType
1517
{
@@ -30,23 +32,35 @@ class Select extends \Magento\Catalog\Model\Product\Option\Type\DefaultType
3032
*/
3133
protected $string;
3234

35+
/**
36+
* @var array
37+
*/
38+
private $singleSelectionTypes;
39+
3340
/**
3441
* @param \Magento\Checkout\Model\Session $checkoutSession
3542
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
3643
* @param \Magento\Framework\Stdlib\StringUtils $string
3744
* @param \Magento\Framework\Escaper $escaper
3845
* @param array $data
46+
* @param array $singleSelectionTypes
3947
*/
4048
public function __construct(
4149
\Magento\Checkout\Model\Session $checkoutSession,
4250
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
4351
\Magento\Framework\Stdlib\StringUtils $string,
4452
\Magento\Framework\Escaper $escaper,
45-
array $data = []
53+
array $data = [],
54+
array $singleSelectionTypes = []
4655
) {
4756
$this->string = $string;
4857
$this->_escaper = $escaper;
4958
parent::__construct($checkoutSession, $scopeConfig, $data);
59+
60+
$this->singleSelectionTypes = $singleSelectionTypes ?: [
61+
'drop_down' => \Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_TYPE_DROP_DOWN,
62+
'radio' => \Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_TYPE_RADIO,
63+
];
5064
}
5165

5266
/**
@@ -310,10 +324,6 @@ public function getOptionSku($optionValue, $skuDelimiter)
310324
*/
311325
protected function _isSingleSelection()
312326
{
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);
327+
return in_array($this->getOption()->getType(), $this->singleSelectionTypes, true);
318328
}
319329
}

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

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

0 commit comments

Comments
 (0)