From 8ea824edd0376a2dc77e2e1cf89fb0d2a8271ce5 Mon Sep 17 00:00:00 2001 From: Ihor Sviziev Date: Thu, 14 Mar 2019 12:54:55 +0200 Subject: [PATCH 1/3] Custom option type select - Allow modify list of single selection option types --- .../Model/Product/Option/Type/Select.php | 20 +++++++++++++------ app/code/Magento/Catalog/etc/di.xml | 8 ++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Product/Option/Type/Select.php b/app/code/Magento/Catalog/Model/Product/Option/Type/Select.php index d88dd58362896..ca506fd451fb3 100644 --- a/app/code/Magento/Catalog/Model/Product/Option/Type/Select.php +++ b/app/code/Magento/Catalog/Model/Product/Option/Type/Select.php @@ -30,23 +30,35 @@ class Select extends \Magento\Catalog\Model\Product\Option\Type\DefaultType */ protected $string; + /** + * @var array + */ + private $singleSelectionTypes; + /** * @param \Magento\Checkout\Model\Session $checkoutSession * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig * @param \Magento\Framework\Stdlib\StringUtils $string * @param \Magento\Framework\Escaper $escaper * @param array $data + * @param array $singleSelectionTypes */ public function __construct( \Magento\Checkout\Model\Session $checkoutSession, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Framework\Stdlib\StringUtils $string, \Magento\Framework\Escaper $escaper, - array $data = [] + array $data = [], + array $singleSelectionTypes = [] ) { $this->string = $string; $this->_escaper = $escaper; parent::__construct($checkoutSession, $scopeConfig, $data); + + $this->singleSelectionTypes = $singleSelectionTypes ?: [ + \Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_TYPE_DROP_DOWN, + \Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_TYPE_RADIO, + ]; } /** @@ -310,10 +322,6 @@ public function getOptionSku($optionValue, $skuDelimiter) */ protected function _isSingleSelection() { - $single = [ - \Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_TYPE_DROP_DOWN, - \Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_TYPE_RADIO, - ]; - return in_array($this->getOption()->getType(), $single); + return in_array($this->getOption()->getType(), $this->singleSelectionTypes, true); } } diff --git a/app/code/Magento/Catalog/etc/di.xml b/app/code/Magento/Catalog/etc/di.xml index 7d2c3699ee2c2..1ece6b999111d 100644 --- a/app/code/Magento/Catalog/etc/di.xml +++ b/app/code/Magento/Catalog/etc/di.xml @@ -1164,4 +1164,12 @@ + + + + Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_TYPE_DROP_DOWN + Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_TYPE_RADIO + + + From 996cb1a70e25b663d8e3ee587649512fa3fa3139 Mon Sep 17 00:00:00 2001 From: nmalevanec Date: Fri, 12 Apr 2019 15:44:42 +0300 Subject: [PATCH 2/3] Fix static tests. --- app/code/Magento/Catalog/Model/Product/Option/Type/Select.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/code/Magento/Catalog/Model/Product/Option/Type/Select.php b/app/code/Magento/Catalog/Model/Product/Option/Type/Select.php index ca506fd451fb3..9c4a917926b59 100644 --- a/app/code/Magento/Catalog/Model/Product/Option/Type/Select.php +++ b/app/code/Magento/Catalog/Model/Product/Option/Type/Select.php @@ -10,6 +10,8 @@ /** * Catalog product option select type + * + * @SuppressWarnings(PHPMD.CookieAndSessionMisuse) */ class Select extends \Magento\Catalog\Model\Product\Option\Type\DefaultType { From 03cfa3706f6fb3c48a926f7ed8b19334bb1992f4 Mon Sep 17 00:00:00 2001 From: Ihor Sviziev Date: Wed, 17 Apr 2019 17:12:38 +0300 Subject: [PATCH 3/3] Custom option type select - Allow modify list of single selection options type Make associative array as a default value in constructor --- app/code/Magento/Catalog/Model/Product/Option/Type/Select.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Product/Option/Type/Select.php b/app/code/Magento/Catalog/Model/Product/Option/Type/Select.php index 9c4a917926b59..31e178f0bd9b4 100644 --- a/app/code/Magento/Catalog/Model/Product/Option/Type/Select.php +++ b/app/code/Magento/Catalog/Model/Product/Option/Type/Select.php @@ -58,8 +58,8 @@ public function __construct( parent::__construct($checkoutSession, $scopeConfig, $data); $this->singleSelectionTypes = $singleSelectionTypes ?: [ - \Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_TYPE_DROP_DOWN, - \Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_TYPE_RADIO, + 'drop_down' => \Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_TYPE_DROP_DOWN, + 'radio' => \Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_TYPE_RADIO, ]; }