Skip to content

Commit 1815df9

Browse files
Merge pull request #3610 from magento-qwerty/2.2.8-bugfixes-180119
Fixed issues: - MAGETWO-90516: Wrong custom option behavior - MAGETWO-97066: Fixed incorrect behavior of catalog attributes actions
2 parents 8dcc1b4 + 83a3200 commit 1815df9

File tree

9 files changed

+421
-498
lines changed

9 files changed

+421
-498
lines changed

app/code/Magento/Catalog/Block/Adminhtml/Product/Attribute/Edit.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,23 @@ protected function _construct()
9191
if (!$entityAttribute || !$entityAttribute->getIsUserDefined()) {
9292
$this->buttonList->remove('delete');
9393
} else {
94-
$this->buttonList->update('delete', 'label', __('Delete Attribute'));
94+
$this->buttonList->update(
95+
'delete',
96+
'onclick',
97+
sprintf(
98+
"deleteConfirm('%s','%s', %s)",
99+
__('Are you sure you want to do this?'),
100+
$this->getDeleteUrl(),
101+
json_encode(
102+
[
103+
'action' => '',
104+
'data' => [
105+
'form_key' => $this->getFormKey()
106+
]
107+
]
108+
)
109+
)
110+
);
95111
}
96112
}
97113

app/code/Magento/Catalog/Block/Product/View/Options/Type/Select.php

Lines changed: 56 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,17 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Catalog\Block\Product\View\Options\Type;
78

9+
use Magento\Catalog\Api\Data\ProductCustomOptionInterface;
10+
use Magento\Catalog\Block\Product\View\Options\Type\Select\CheckableFactory;
11+
use Magento\Catalog\Block\Product\View\Options\Type\Select\MultipleFactory;
12+
use Magento\Framework\App\ObjectManager;
13+
use Magento\Framework\View\Element\Template\Context;
14+
use Magento\Framework\Pricing\Helper\Data;
15+
use Magento\Catalog\Helper\Data as CatalogHelper;
16+
817
/**
918
* Product options text type block
1019
*
@@ -13,169 +22,64 @@
1322
*/
1423
class Select extends \Magento\Catalog\Block\Product\View\Options\AbstractOptions
1524
{
25+
/**
26+
* @var CheckableFactory
27+
*/
28+
private $checkableFactory;
29+
30+
/**
31+
* @var MultipleFactory
32+
*/
33+
private $multipleFactory;
34+
35+
/**
36+
* Select constructor.
37+
* @param Context $context
38+
* @param Data $pricingHelper
39+
* @param CatalogHelper $catalogData
40+
* @param array $data
41+
* @param CheckableFactory|null $checkableFactory
42+
* @param MultipleFactory|null $multipleFactory
43+
*/
44+
public function __construct(
45+
Context $context,
46+
Data $pricingHelper,
47+
CatalogHelper $catalogData,
48+
array $data = [],
49+
CheckableFactory $checkableFactory = null,
50+
MultipleFactory $multipleFactory = null
51+
) {
52+
parent::__construct($context, $pricingHelper, $catalogData, $data);
53+
$this->checkableFactory = $checkableFactory ?: ObjectManager::getInstance()->get(CheckableFactory::class);
54+
$this->multipleFactory = $multipleFactory ?: ObjectManager::getInstance()->get(MultipleFactory::class);
55+
}
56+
1657
/**
1758
* Return html for control element
1859
*
1960
* @return string
20-
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
21-
* @SuppressWarnings(PHPMD.NPathComplexity)
22-
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
2361
*/
24-
public function getValuesHtml()
62+
public function getValuesHtml(): string
2563
{
26-
$_option = $this->getOption();
27-
$configValue = $this->getProduct()->getPreconfiguredValues()->getData('options/' . $_option->getId());
28-
$store = $this->getProduct()->getStore();
29-
30-
$this->setSkipJsReloadPrice(1);
31-
// Remove inline prototype onclick and onchange events
64+
$option = $this->getOption();
65+
$optionType = $option->getType();
3266

33-
if ($_option->getType() == \Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_TYPE_DROP_DOWN ||
34-
$_option->getType() == \Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_TYPE_MULTIPLE
67+
if ($optionType === ProductCustomOptionInterface::OPTION_TYPE_DROP_DOWN ||
68+
$optionType === ProductCustomOptionInterface::OPTION_TYPE_MULTIPLE
3569
) {
36-
$require = $_option->getIsRequire() ? ' required' : '';
37-
$extraParams = '';
38-
$select = $this->getLayout()->createBlock(
39-
\Magento\Framework\View\Element\Html\Select::class
40-
)->setData(
41-
[
42-
'id' => 'select_' . $_option->getId(),
43-
'class' => $require . ' product-custom-option admin__control-select'
44-
]
45-
);
46-
if ($_option->getType() == \Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_TYPE_DROP_DOWN) {
47-
$select->setName('options[' . $_option->getId() . ']')->addOption('', __('-- Please Select --'));
48-
} else {
49-
$select->setName('options[' . $_option->getId() . '][]');
50-
$select->setClass('multiselect admin__control-multiselect' . $require . ' product-custom-option');
51-
}
52-
foreach ($_option->getValues() as $_value) {
53-
$priceStr = $this->_formatPrice(
54-
[
55-
'is_percent' => $_value->getPriceType() == 'percent',
56-
'pricing_value' => $_value->getPrice($_value->getPriceType() == 'percent'),
57-
],
58-
false
59-
);
60-
$select->addOption(
61-
$_value->getOptionTypeId(),
62-
$_value->getTitle() . ' ' . strip_tags($priceStr) . '',
63-
['price' => $this->pricingHelper->currencyByStore($_value->getPrice(true), $store, false)]
64-
);
65-
}
66-
if ($_option->getType() == \Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_TYPE_MULTIPLE) {
67-
$extraParams = ' multiple="multiple"';
68-
}
69-
if (!$this->getSkipJsReloadPrice()) {
70-
$extraParams .= ' onchange="opConfig.reloadPrice()"';
71-
}
72-
$extraParams .= ' data-selector="' . $select->getName() . '"';
73-
$select->setExtraParams($extraParams);
74-
75-
if ($configValue) {
76-
$select->setValue($configValue);
77-
}
78-
79-
return $select->getHtml();
70+
$optionBlock = $this->multipleFactory->create();
8071
}
8172

82-
if ($_option->getType() == \Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_TYPE_RADIO ||
83-
$_option->getType() == \Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_TYPE_CHECKBOX
73+
if ($optionType === ProductCustomOptionInterface::OPTION_TYPE_RADIO ||
74+
$optionType === ProductCustomOptionInterface::OPTION_TYPE_CHECKBOX
8475
) {
85-
$selectHtml = '<div class="options-list nested" id="options-' . $_option->getId() . '-list">';
86-
$require = $_option->getIsRequire() ? ' required' : '';
87-
$arraySign = '';
88-
switch ($_option->getType()) {
89-
case \Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_TYPE_RADIO:
90-
$type = 'radio';
91-
$class = 'radio admin__control-radio';
92-
if (!$_option->getIsRequire()) {
93-
$selectHtml .= '<div class="field choice admin__field admin__field-option">' .
94-
'<input type="radio" id="options_' .
95-
$_option->getId() .
96-
'" class="' .
97-
$class .
98-
' product-custom-option" name="options[' .
99-
$_option->getId() .
100-
']"' .
101-
' data-selector="options[' . $_option->getId() . ']"' .
102-
($this->getSkipJsReloadPrice() ? '' : ' onclick="opConfig.reloadPrice()"') .
103-
' value="" checked="checked" /><label class="label admin__field-label" for="options_' .
104-
$_option->getId() .
105-
'"><span>' .
106-
__('None') . '</span></label></div>';
107-
}
108-
break;
109-
case \Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_TYPE_CHECKBOX:
110-
$type = 'checkbox';
111-
$class = 'checkbox admin__control-checkbox';
112-
$arraySign = '[]';
113-
break;
114-
}
115-
$count = 1;
116-
foreach ($_option->getValues() as $_value) {
117-
$count++;
118-
119-
$priceStr = $this->_formatPrice(
120-
[
121-
'is_percent' => $_value->getPriceType() == 'percent',
122-
'pricing_value' => $_value->getPrice($_value->getPriceType() == 'percent'),
123-
]
124-
);
125-
126-
$htmlValue = $_value->getOptionTypeId();
127-
if ($arraySign) {
128-
$checked = is_array($configValue) && in_array($htmlValue, $configValue) ? 'checked' : '';
129-
} else {
130-
$checked = $configValue == $htmlValue ? 'checked' : '';
131-
}
132-
133-
$dataSelector = 'options[' . $_option->getId() . ']';
134-
if ($arraySign) {
135-
$dataSelector .= '[' . $htmlValue . ']';
136-
}
137-
138-
$selectHtml .= '<div class="field choice admin__field admin__field-option' .
139-
$require .
140-
'">' .
141-
'<input type="' .
142-
$type .
143-
'" class="' .
144-
$class .
145-
' ' .
146-
$require .
147-
' product-custom-option"' .
148-
($this->getSkipJsReloadPrice() ? '' : ' onclick="opConfig.reloadPrice()"') .
149-
' name="options[' .
150-
$_option->getId() .
151-
']' .
152-
$arraySign .
153-
'" id="options_' .
154-
$_option->getId() .
155-
'_' .
156-
$count .
157-
'" value="' .
158-
$htmlValue .
159-
'" ' .
160-
$checked .
161-
' data-selector="' . $dataSelector . '"' .
162-
' price="' .
163-
$this->pricingHelper->currencyByStore($_value->getPrice(true), $store, false) .
164-
'" />' .
165-
'<label class="label admin__field-label" for="options_' .
166-
$_option->getId() .
167-
'_' .
168-
$count .
169-
'"><span>' .
170-
$_value->getTitle() .
171-
'</span> ' .
172-
$priceStr .
173-
'</label>';
174-
$selectHtml .= '</div>';
175-
}
176-
$selectHtml .= '</div>';
177-
178-
return $selectHtml;
76+
$optionBlock = $this->checkableFactory->create();
17977
}
78+
79+
return $optionBlock
80+
->setOption($option)
81+
->setProduct($this->getProduct())
82+
->setSkipJsReloadPrice(1)
83+
->_toHtml();
18084
}
18185
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Block\Product\View\Options\Type\Select;
8+
9+
use Magento\Catalog\Api\Data\ProductCustomOptionValuesInterface;
10+
use Magento\Catalog\Block\Product\View\Options\AbstractOptions;
11+
12+
/**
13+
* Represent necessary logic for checkbox and radio button option type
14+
*/
15+
class Checkable extends AbstractOptions
16+
{
17+
protected $_template = 'Magento_Catalog::product/composite/fieldset/options/view/checkable.phtml';
18+
19+
/**
20+
* @param $value
21+
* @return string
22+
*/
23+
public function formatPrice(ProductCustomOptionValuesInterface $value) : string
24+
{
25+
26+
return parent::_formatPrice(
27+
[
28+
'is_percent' => $value->getPriceType() === 'percent',
29+
'pricing_value' => $value->getPrice($value->getPriceType() === 'percent')
30+
]
31+
);
32+
}
33+
34+
/**
35+
* @param $value
36+
* @return float
37+
*/
38+
public function getCurrencyByStore(ProductCustomOptionValuesInterface $value) : float
39+
{
40+
return $this->pricingHelper->currencyByStore(
41+
$value->getPrice(true),
42+
$this->getProduct()->getStore(),
43+
false
44+
);
45+
}
46+
47+
/**
48+
* @param $option
49+
* @return string|array|null
50+
*/
51+
public function getPreconfiguredValue($option)
52+
{
53+
return $this->getProduct()->getPreconfiguredValues()->getData('options/' . $option->getId());
54+
}
55+
}

0 commit comments

Comments
 (0)