Skip to content

Commit 1ca8772

Browse files
committed
Merge branch 'MC-34322' of github.com:magento-engcom/magento2ce into async-opetation-status-issue
2 parents 22de8dc + 692af26 commit 1ca8772

File tree

14 files changed

+121
-704
lines changed

14 files changed

+121
-704
lines changed

app/code/Magento/Catalog/Block/Product/View/Options/AbstractOptions.php

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
declare(strict_types=1);
6+
7+
/**
8+
* Product options abstract type block
9+
*
10+
* @author Magento Core Team <core@magentocommerce.com>
11+
*/
712

813
namespace Magento\Catalog\Block\Product\View\Options;
914

10-
use Magento\Catalog\Pricing\Price\BasePrice;
11-
use Magento\Catalog\Pricing\Price\CalculateCustomOptionCatalogRule;
1215
use Magento\Catalog\Pricing\Price\CustomOptionPriceInterface;
13-
use Magento\Framework\App\ObjectManager;
1416

1517
/**
1618
* Product options section abstract block.
@@ -45,29 +47,20 @@ abstract class AbstractOptions extends \Magento\Framework\View\Element\Template
4547
*/
4648
protected $_catalogHelper;
4749

48-
/**
49-
* @var CalculateCustomOptionCatalogRule
50-
*/
51-
private $calculateCustomOptionCatalogRule;
52-
5350
/**
5451
* @param \Magento\Framework\View\Element\Template\Context $context
5552
* @param \Magento\Framework\Pricing\Helper\Data $pricingHelper
5653
* @param \Magento\Catalog\Helper\Data $catalogData
5754
* @param array $data
58-
* @param CalculateCustomOptionCatalogRule $calculateCustomOptionCatalogRule
5955
*/
6056
public function __construct(
6157
\Magento\Framework\View\Element\Template\Context $context,
6258
\Magento\Framework\Pricing\Helper\Data $pricingHelper,
6359
\Magento\Catalog\Helper\Data $catalogData,
64-
array $data = [],
65-
CalculateCustomOptionCatalogRule $calculateCustomOptionCatalogRule = null
60+
array $data = []
6661
) {
6762
$this->pricingHelper = $pricingHelper;
6863
$this->_catalogHelper = $catalogData;
69-
$this->calculateCustomOptionCatalogRule = $calculateCustomOptionCatalogRule
70-
?? ObjectManager::getInstance()->get(CalculateCustomOptionCatalogRule::class);
7164
parent::__construct($context, $data);
7265
}
7366

@@ -168,15 +161,6 @@ protected function _formatPrice($value, $flag = true)
168161
$priceStr = $sign;
169162

170163
$customOptionPrice = $this->getProduct()->getPriceInfo()->getPrice('custom_option_price');
171-
172-
if (!$value['is_percent']) {
173-
$value['pricing_value'] = $this->calculateCustomOptionCatalogRule->execute(
174-
$this->getProduct(),
175-
(float)$value['pricing_value'],
176-
(bool)$value['is_percent']
177-
);
178-
}
179-
180164
$context = [CustomOptionPriceInterface::CONFIGURATION_OPTION_FLAG => true];
181165
$optionAmount = $customOptionPrice->getCustomAmount($value['pricing_value'], null, $context);
182166
$priceStr .= $this->getLayout()->getBlock('product.price.render.default')->renderAmount(

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

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
declare(strict_types=1);
76

87
namespace Magento\Catalog\Model\Product;
98

@@ -17,10 +16,8 @@
1716
use Magento\Catalog\Model\Product\Option\Type\File;
1817
use Magento\Catalog\Model\Product\Option\Type\Select;
1918
use Magento\Catalog\Model\Product\Option\Type\Text;
20-
use Magento\Catalog\Model\Product\Option\Value;
2119
use Magento\Catalog\Model\ResourceModel\Product\Option\Value\Collection;
22-
use Magento\Catalog\Pricing\Price\CalculateCustomOptionCatalogRule;
23-
use Magento\Framework\App\ObjectManager;
20+
use Magento\Catalog\Pricing\Price\BasePrice;
2421
use Magento\Framework\EntityManager\MetadataPool;
2522
use Magento\Framework\Exception\LocalizedException;
2623
use Magento\Framework\Model\AbstractExtensibleModel;
@@ -126,11 +123,6 @@ class Option extends AbstractExtensibleModel implements ProductCustomOptionInter
126123
*/
127124
private $customOptionValuesFactory;
128125

129-
/**
130-
* @var CalculateCustomOptionCatalogRule
131-
*/
132-
private $calculateCustomOptionCatalogRule;
133-
134126
/**
135127
* @param \Magento\Framework\Model\Context $context
136128
* @param \Magento\Framework\Registry $registry
@@ -146,7 +138,6 @@ class Option extends AbstractExtensibleModel implements ProductCustomOptionInter
146138
* @param ProductCustomOptionValuesInterfaceFactory|null $customOptionValuesFactory
147139
* @param array $optionGroups
148140
* @param array $optionTypesToGroups
149-
* @param CalculateCustomOptionCatalogRule $calculateCustomOptionCatalogRule
150141
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
151142
*/
152143
public function __construct(
@@ -163,17 +154,14 @@ public function __construct(
163154
array $data = [],
164155
ProductCustomOptionValuesInterfaceFactory $customOptionValuesFactory = null,
165156
array $optionGroups = [],
166-
array $optionTypesToGroups = [],
167-
CalculateCustomOptionCatalogRule $calculateCustomOptionCatalogRule = null
157+
array $optionTypesToGroups = []
168158
) {
169159
$this->productOptionValue = $productOptionValue;
170160
$this->optionTypeFactory = $optionFactory;
171161
$this->string = $string;
172162
$this->validatorPool = $validatorPool;
173163
$this->customOptionValuesFactory = $customOptionValuesFactory ?:
174-
ObjectManager::getInstance()->get(ProductCustomOptionValuesInterfaceFactory::class);
175-
$this->calculateCustomOptionCatalogRule = $calculateCustomOptionCatalogRule ??
176-
ObjectManager::getInstance()->get(CalculateCustomOptionCatalogRule::class);
164+
\Magento\Framework\App\ObjectManager::getInstance()->get(ProductCustomOptionValuesInterfaceFactory::class);
177165
$this->optionGroups = $optionGroups ?: [
178166
self::OPTION_GROUP_DATE => Date::class,
179167
self::OPTION_GROUP_FILE => File::class,
@@ -474,12 +462,10 @@ public function afterSave()
474462
*/
475463
public function getPrice($flag = false)
476464
{
477-
if ($flag) {
478-
return $this->calculateCustomOptionCatalogRule->execute(
479-
$this->getProduct(),
480-
(float)$this->getData(self::KEY_PRICE),
481-
$this->getPriceType() === Value::TYPE_PERCENT
482-
);
465+
if ($flag && $this->getPriceType() == self::$typePercent) {
466+
$basePrice = $this->getProduct()->getPriceInfo()->getPrice(BasePrice::PRICE_CODE)->getValue();
467+
$price = $basePrice * ($this->_getData(self::KEY_PRICE) / 100);
468+
return $price;
483469
}
484470
return $this->_getData(self::KEY_PRICE);
485471
}
@@ -966,7 +952,7 @@ public function setExtensionAttributes(
966952
private function getOptionRepository()
967953
{
968954
if (null === $this->optionRepository) {
969-
$this->optionRepository = ObjectManager::getInstance()
955+
$this->optionRepository = \Magento\Framework\App\ObjectManager::getInstance()
970956
->get(\Magento\Catalog\Model\Product\Option\Repository::class);
971957
}
972958
return $this->optionRepository;
@@ -980,7 +966,7 @@ private function getOptionRepository()
980966
private function getMetadataPool()
981967
{
982968
if (null === $this->metadataPool) {
983-
$this->metadataPool = ObjectManager::getInstance()
969+
$this->metadataPool = \Magento\Framework\App\ObjectManager::getInstance()
984970
->get(\Magento\Framework\EntityManager\MetadataPool::class);
985971
}
986972
return $this->metadataPool;

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

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,16 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
declare(strict_types=1);
76

87
namespace Magento\Catalog\Model\Product\Option\Type;
98

9+
use Magento\Framework\Exception\LocalizedException;
1010
use Magento\Catalog\Api\Data\ProductCustomOptionInterface;
11+
use Magento\Catalog\Model\Product\Option;
1112
use Magento\Catalog\Model\Product;
12-
use Magento\Catalog\Model\Product\Configuration\Item\ItemInterface;
1313
use Magento\Catalog\Model\Product\Configuration\Item\Option\OptionInterface;
14-
use Magento\Catalog\Model\Product\Option;
14+
use Magento\Catalog\Model\Product\Configuration\Item\ItemInterface;
1515
use Magento\Catalog\Model\Product\Option\Value;
16-
use Magento\Catalog\Pricing\Price\CalculateCustomOptionCatalogRule;
17-
use Magento\Framework\App\ObjectManager;
18-
use Magento\Framework\Exception\LocalizedException;
1916

2017
/**
2118
* Catalog product option default type
@@ -63,30 +60,21 @@ class DefaultType extends \Magento\Framework\DataObject
6360
*/
6461
protected $_checkoutSession;
6562

66-
/**
67-
* @var CalculateCustomOptionCatalogRule
68-
*/
69-
private $calculateCustomOptionCatalogRule;
70-
7163
/**
7264
* Construct
7365
*
7466
* @param \Magento\Checkout\Model\Session $checkoutSession
7567
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
7668
* @param array $data
77-
* @param CalculateCustomOptionCatalogRule $calculateCustomOptionCatalogRule
7869
*/
7970
public function __construct(
8071
\Magento\Checkout\Model\Session $checkoutSession,
8172
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
82-
array $data = [],
83-
CalculateCustomOptionCatalogRule $calculateCustomOptionCatalogRule = null
73+
array $data = []
8474
) {
8575
$this->_checkoutSession = $checkoutSession;
8676
parent::__construct($data);
8777
$this->_scopeConfig = $scopeConfig;
88-
$this->calculateCustomOptionCatalogRule = $calculateCustomOptionCatalogRule ?? ObjectManager::getInstance()
89-
->get(CalculateCustomOptionCatalogRule::class);
9078
}
9179

9280
/**
@@ -104,12 +92,12 @@ public function setOption($option)
10492
/**
10593
* Option Instance getter
10694
*
107-
* @return Option
10895
* @throws \Magento\Framework\Exception\LocalizedException
96+
* @return Option
10997
*/
11098
public function getOption()
11199
{
112-
if ($this->_option instanceof Option) {
100+
if ($this->_option instanceof \Magento\Catalog\Model\Product\Option) {
113101
return $this->_option;
114102
}
115103
throw new LocalizedException(__('The option instance type in options group is incorrect.'));
@@ -130,8 +118,8 @@ public function setProduct($product)
130118
/**
131119
* Product Instance getter
132120
*
133-
* @return Product
134121
* @throws \Magento\Framework\Exception\LocalizedException
122+
* @return Product
135123
*/
136124
public function getProduct()
137125
{
@@ -169,8 +157,7 @@ public function getConfigurationItemOption()
169157
*/
170158
public function getConfigurationItem()
171159
{
172-
if ($this->_getData('configuration_item') instanceof ItemInterface
173-
) {
160+
if ($this->_getData('configuration_item') instanceof ItemInterface) {
174161
return $this->_getData('configuration_item');
175162
}
176163

@@ -354,11 +341,7 @@ public function getOptionPrice($optionValue, $basePrice)
354341
{
355342
$option = $this->getOption();
356343

357-
return $this->calculateCustomOptionCatalogRule->execute(
358-
$option->getProduct(),
359-
(float)$option->getPrice(),
360-
$option->getPriceType() === Value::TYPE_PERCENT
361-
);
344+
return $this->_getChargeableOptionPrice($option->getPrice(), $option->getPriceType() == 'percent', $basePrice);
362345
}
363346

364347
/**
@@ -419,7 +402,7 @@ public function getProductOptions()
419402
* @param float $basePrice For percent price type
420403
* @return float
421404
* @deprecated 102.0.4 typo in method name
422-
* @see CalculateCustomOptionCatalogRule::execute
405+
* @see _getChargeableOptionPrice
423406
*/
424407
protected function _getChargableOptionPrice($price, $isPercent, $basePrice)
425408
{
@@ -433,8 +416,6 @@ protected function _getChargableOptionPrice($price, $isPercent, $basePrice)
433416
* @param boolean $isPercent Price type - percent or fixed
434417
* @param float $basePrice For percent price type
435418
* @return float
436-
* @deprecated
437-
* @see CalculateCustomOptionCatalogRule::execute
438419
*/
439420
protected function _getChargeableOptionPrice($price, $isPercent, $basePrice)
440421
{

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

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,9 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
declare(strict_types=1);
76

87
namespace Magento\Catalog\Model\Product\Option\Type;
98

10-
use Magento\Catalog\Model\Product\Option\Value;
11-
use Magento\Catalog\Pricing\Price\CalculateCustomOptionCatalogRule;
12-
use Magento\Framework\App\ObjectManager;
139
use Magento\Framework\Exception\LocalizedException;
1410

1511
/**
@@ -41,28 +37,21 @@ class Select extends \Magento\Catalog\Model\Product\Option\Type\DefaultType
4137
*/
4238
private $singleSelectionTypes;
4339

44-
/**
45-
* @var CalculateCustomOptionCatalogRule
46-
*/
47-
private $calculateCustomOptionCatalogRule;
48-
4940
/**
5041
* @param \Magento\Checkout\Model\Session $checkoutSession
5142
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
5243
* @param \Magento\Framework\Stdlib\StringUtils $string
5344
* @param \Magento\Framework\Escaper $escaper
5445
* @param array $data
5546
* @param array $singleSelectionTypes
56-
* @param CalculateCustomOptionCatalogRule $calculateCustomOptionCatalogRule
5747
*/
5848
public function __construct(
5949
\Magento\Checkout\Model\Session $checkoutSession,
6050
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
6151
\Magento\Framework\Stdlib\StringUtils $string,
6252
\Magento\Framework\Escaper $escaper,
6353
array $data = [],
64-
array $singleSelectionTypes = [],
65-
CalculateCustomOptionCatalogRule $calculateCustomOptionCatalogRule = null
54+
array $singleSelectionTypes = []
6655
) {
6756
$this->string = $string;
6857
$this->_escaper = $escaper;
@@ -72,8 +61,6 @@ public function __construct(
7261
'drop_down' => \Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_TYPE_DROP_DOWN,
7362
'radio' => \Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_TYPE_RADIO,
7463
];
75-
$this->calculateCustomOptionCatalogRule = $calculateCustomOptionCatalogRule ?? ObjectManager::getInstance()
76-
->get(CalculateCustomOptionCatalogRule::class);
7764
}
7865

7966
/**
@@ -261,10 +248,10 @@ public function getOptionPrice($optionValue, $basePrice)
261248
foreach (explode(',', $optionValue) as $value) {
262249
$_result = $option->getValueById($value);
263250
if ($_result) {
264-
$result += $this->calculateCustomOptionCatalogRule->execute(
265-
$option->getProduct(),
266-
(float)$_result->getPrice(),
267-
$_result->getPriceType() === Value::TYPE_PERCENT
251+
$result += $this->_getChargeableOptionPrice(
252+
$_result->getPrice(),
253+
$_result->getPriceType() == 'percent',
254+
$basePrice
268255
);
269256
} else {
270257
if ($this->getListener()) {
@@ -276,10 +263,10 @@ public function getOptionPrice($optionValue, $basePrice)
276263
} elseif ($this->_isSingleSelection()) {
277264
$_result = $option->getValueById($optionValue);
278265
if ($_result) {
279-
$result = $this->calculateCustomOptionCatalogRule->execute(
280-
$option->getProduct(),
281-
(float)$_result->getPrice(),
282-
$_result->getPriceType() === Value::TYPE_PERCENT
266+
$result = $this->_getChargeableOptionPrice(
267+
$_result->getPrice(),
268+
$_result->getPriceType() == 'percent',
269+
$basePrice
283270
);
284271
} else {
285272
if ($this->getListener()) {

0 commit comments

Comments
 (0)