Skip to content

Commit aacc7fb

Browse files
committed
Merge remote-tracking branches 'local/ACP2E-1093', 'local/ACP2E-891', 'local/ACP2E-1080' and 'local/ACP2E-1206' into PR_combine
5 parents 28c7f79 + 52c267f + d33938b + b9d71a7 + f7ef6ae commit aacc7fb

23 files changed

+726
-197
lines changed

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -195,17 +195,6 @@ protected function _formatPrice($value, $flag = true)
195195
$customOptionPrice = $this->getProduct()->getPriceInfo()->getPrice('custom_option_price');
196196
$isPercent = (bool) $value['is_percent'];
197197

198-
if (!$isPercent) {
199-
$catalogPriceValue = $this->calculateCustomOptionCatalogRule->execute(
200-
$this->getProduct(),
201-
(float)$value['pricing_value'],
202-
$isPercent
203-
);
204-
if ($catalogPriceValue !== null) {
205-
$value['pricing_value'] = $catalogPriceValue;
206-
}
207-
}
208-
209198
$context = [CustomOptionPriceInterface::CONFIGURATION_OPTION_FLAG => true];
210199
$optionAmount = $isPercent
211200
? $this->calculator->getAmount(

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

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@
1616
use Magento\Catalog\Model\Product\Option\Type\File;
1717
use Magento\Catalog\Model\Product\Option\Type\Select;
1818
use Magento\Catalog\Model\Product\Option\Type\Text;
19-
use Magento\Catalog\Model\Product\Option\Value;
2019
use Magento\Catalog\Model\ResourceModel\Product\Option\Value\Collection;
2120
use Magento\Catalog\Pricing\Price\BasePrice;
22-
use Magento\Catalog\Pricing\Price\CalculateCustomOptionCatalogRule;
2321
use Magento\Framework\App\ObjectManager;
2422
use Magento\Framework\EntityManager\MetadataPool;
2523
use Magento\Framework\Exception\LocalizedException;
@@ -130,11 +128,6 @@ class Option extends AbstractExtensibleModel implements ProductCustomOptionInter
130128
*/
131129
private $customOptionValuesFactory;
132130

133-
/**
134-
* @var CalculateCustomOptionCatalogRule
135-
*/
136-
private $calculateCustomOptionCatalogRule;
137-
138131
/**
139132
* @param \Magento\Framework\Model\Context $context
140133
* @param \Magento\Framework\Registry $registry
@@ -150,7 +143,6 @@ class Option extends AbstractExtensibleModel implements ProductCustomOptionInter
150143
* @param ProductCustomOptionValuesInterfaceFactory|null $customOptionValuesFactory
151144
* @param array $optionGroups
152145
* @param array $optionTypesToGroups
153-
* @param CalculateCustomOptionCatalogRule|null $calculateCustomOptionCatalogRule
154146
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
155147
*/
156148
public function __construct(
@@ -167,17 +159,14 @@ public function __construct(
167159
array $data = [],
168160
ProductCustomOptionValuesInterfaceFactory $customOptionValuesFactory = null,
169161
array $optionGroups = [],
170-
array $optionTypesToGroups = [],
171-
CalculateCustomOptionCatalogRule $calculateCustomOptionCatalogRule = null
162+
array $optionTypesToGroups = []
172163
) {
173164
$this->productOptionValue = $productOptionValue;
174165
$this->optionTypeFactory = $optionFactory;
175166
$this->string = $string;
176167
$this->validatorPool = $validatorPool;
177168
$this->customOptionValuesFactory = $customOptionValuesFactory ?:
178169
ObjectManager::getInstance()->get(ProductCustomOptionValuesInterfaceFactory::class);
179-
$this->calculateCustomOptionCatalogRule = $calculateCustomOptionCatalogRule ??
180-
ObjectManager::getInstance()->get(CalculateCustomOptionCatalogRule::class);
181170
$this->optionGroups = $optionGroups ?: [
182171
self::OPTION_GROUP_DATE => Date::class,
183172
self::OPTION_GROUP_FILE => File::class,
@@ -212,7 +201,8 @@ public function __construct(
212201
* Get resource instance
213202
*
214203
* @return \Magento\Framework\Model\ResourceModel\Db\AbstractDb
215-
* @deprecated 102.0.0 because resource models should be used directly
204+
* @deprecated 102.0.0
205+
* @see resource models should be used directly
216206
*/
217207
protected function _getResource()
218208
{
@@ -478,21 +468,10 @@ public function afterSave()
478468
*/
479469
public function getPrice($flag = false)
480470
{
481-
if ($flag && $this->getPriceType() === self::$typePercent) {
482-
$price = $this->calculateCustomOptionCatalogRule->execute(
483-
$this->getProduct(),
484-
(float)$this->getData(self::KEY_PRICE),
485-
$this->getPriceType() === Value::TYPE_PERCENT
486-
);
487-
488-
if ($price === null) {
489-
$basePrice = $this->getProduct()->getPriceInfo()->getPrice(BasePrice::PRICE_CODE)->getValue();
490-
$price = $basePrice * ($this->_getData(self::KEY_PRICE) / 100);
491-
}
492-
493-
return $price;
471+
if ($flag && $this->getPriceType() == self::$typePercent) {
472+
$basePrice = $this->getProduct()->getPriceInfo()->getPrice(BasePrice::PRICE_CODE)->getValue();
473+
return $basePrice * ($this->_getData(self::KEY_PRICE) / 100);
494474
}
495-
496475
return $this->_getData(self::KEY_PRICE);
497476
}
498477

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

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
use Magento\Catalog\Model\Product\Configuration\Item\Option\OptionInterface;
1414
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;
1816

1917
/**
2018
* Catalog product option default type
@@ -49,43 +47,30 @@ class DefaultType extends \Magento\Framework\DataObject
4947
protected $_productOptions = [];
5048

5149
/**
52-
* Core store config
53-
*
5450
* @var \Magento\Framework\App\Config\ScopeConfigInterface
5551
*/
5652
protected $_scopeConfig;
5753

5854
/**
59-
* Checkout session
60-
*
6155
* @var \Magento\Checkout\Model\Session
6256
*/
6357
protected $_checkoutSession;
6458

65-
/**
66-
* @var CalculateCustomOptionCatalogRule
67-
*/
68-
private $calculateCustomOptionCatalogRule;
69-
7059
/**
7160
* Construct
7261
*
7362
* @param \Magento\Checkout\Model\Session $checkoutSession
7463
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
7564
* @param array $data
76-
* @param CalculateCustomOptionCatalogRule|null $calculateCustomOptionCatalogRule
7765
*/
7866
public function __construct(
7967
\Magento\Checkout\Model\Session $checkoutSession,
8068
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
81-
array $data = [],
82-
CalculateCustomOptionCatalogRule $calculateCustomOptionCatalogRule = null
69+
array $data = []
8370
) {
8471
$this->_checkoutSession = $checkoutSession;
8572
parent::__construct($data);
8673
$this->_scopeConfig = $scopeConfig;
87-
$this->calculateCustomOptionCatalogRule = $calculateCustomOptionCatalogRule ?? ObjectManager::getInstance()
88-
->get(CalculateCustomOptionCatalogRule::class);
8974
}
9075

9176
/**
@@ -352,20 +337,11 @@ public function getOptionPrice($optionValue, $basePrice)
352337
{
353338
$option = $this->getOption();
354339

355-
$catalogPriceValue = $this->calculateCustomOptionCatalogRule->execute(
356-
$option->getProduct(),
357-
(float)$option->getPrice(),
358-
$option->getPriceType() === Value::TYPE_PERCENT
340+
return $this->_getChargeableOptionPrice(
341+
$option->getPrice(),
342+
$option->getPriceType() === Value::TYPE_PERCENT,
343+
$basePrice
359344
);
360-
if ($catalogPriceValue !== null) {
361-
return $catalogPriceValue;
362-
} else {
363-
return $this->_getChargeableOptionPrice(
364-
$option->getPrice(),
365-
$option->getPriceType() === Value::TYPE_PERCENT,
366-
$basePrice
367-
);
368-
}
369345
}
370346

371347
/**

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

Lines changed: 10 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77
namespace Magento\Catalog\Model\Product\Option\Type;
88

99
use Magento\Catalog\Model\Product\Option\Value;
10-
use Magento\Catalog\Pricing\Price\CalculateCustomOptionCatalogRule;
11-
use Magento\Framework\App\ObjectManager;
1210
use Magento\Framework\Exception\LocalizedException;
13-
use Magento\Catalog\Model\Product\Option;
1411

1512
/**
1613
* Catalog product option select type
@@ -41,28 +38,21 @@ class Select extends \Magento\Catalog\Model\Product\Option\Type\DefaultType
4138
*/
4239
private $singleSelectionTypes;
4340

44-
/**
45-
* @var CalculateCustomOptionCatalogRule
46-
*/
47-
private $calculateCustomOptionCatalogRule;
48-
4941
/**
5042
* @param \Magento\Checkout\Model\Session $checkoutSession
5143
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
5244
* @param \Magento\Framework\Stdlib\StringUtils $string
5345
* @param \Magento\Framework\Escaper $escaper
5446
* @param array $data
5547
* @param array $singleSelectionTypes
56-
* @param CalculateCustomOptionCatalogRule|null $calculateCustomOptionCatalogRule
5748
*/
5849
public function __construct(
5950
\Magento\Checkout\Model\Session $checkoutSession,
6051
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
6152
\Magento\Framework\Stdlib\StringUtils $string,
6253
\Magento\Framework\Escaper $escaper,
6354
array $data = [],
64-
array $singleSelectionTypes = [],
65-
CalculateCustomOptionCatalogRule $calculateCustomOptionCatalogRule = null
55+
array $singleSelectionTypes = []
6656
) {
6757
$this->string = $string;
6858
$this->_escaper = $escaper;
@@ -72,8 +62,6 @@ public function __construct(
7262
'drop_down' => \Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_TYPE_DROP_DOWN,
7363
'radio' => \Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_TYPE_RADIO,
7464
];
75-
$this->calculateCustomOptionCatalogRule = $calculateCustomOptionCatalogRule ?? ObjectManager::getInstance()
76-
->get(CalculateCustomOptionCatalogRule::class);
7765
}
7866

7967
/**
@@ -265,7 +253,11 @@ public function getOptionPrice($optionValue, $basePrice)
265253
foreach (explode(',', (string)$optionValue) as $value) {
266254
$_result = $option->getValueById($value);
267255
if ($_result) {
268-
$result += $this->getCalculatedOptionValue($option, $_result, $basePrice);
256+
$result += $this->_getChargeableOptionPrice(
257+
$_result->getPrice(),
258+
$_result->getPriceType() === Value::TYPE_PERCENT,
259+
$basePrice
260+
);
269261
} else {
270262
if ($this->getListener()) {
271263
$this->getListener()->setHasError(true)->setMessage($this->_getWrongConfigurationMessage());
@@ -276,20 +268,11 @@ public function getOptionPrice($optionValue, $basePrice)
276268
} elseif ($this->_isSingleSelection()) {
277269
$_result = $option->getValueById($optionValue);
278270
if ($_result) {
279-
$catalogPriceValue = $this->calculateCustomOptionCatalogRule->execute(
280-
$option->getProduct(),
281-
(float)$_result->getPrice(),
282-
$_result->getPriceType() === Value::TYPE_PERCENT
271+
$result = $this->_getChargeableOptionPrice(
272+
$_result->getPrice(),
273+
$_result->getPriceType() === Value::TYPE_PERCENT,
274+
$basePrice
283275
);
284-
if ($catalogPriceValue !== null) {
285-
$result = $catalogPriceValue;
286-
} else {
287-
$result = $this->_getChargeableOptionPrice(
288-
$_result->getPrice(),
289-
$_result->getPriceType() == 'percent',
290-
$basePrice
291-
);
292-
}
293276
} else {
294277
if ($this->getListener()) {
295278
$this->getListener()->setHasError(true)->setMessage($this->_getWrongConfigurationMessage());
@@ -351,31 +334,4 @@ protected function _isSingleSelection()
351334
{
352335
return in_array($this->getOption()->getType(), $this->singleSelectionTypes, true);
353336
}
354-
355-
/**
356-
* Returns calculated price of option
357-
*
358-
* @param Option $option
359-
* @param Option\Value $result
360-
* @param float $basePrice
361-
* @return float
362-
*/
363-
protected function getCalculatedOptionValue(Option $option, Value $result, float $basePrice) : float
364-
{
365-
$catalogPriceValue = $this->calculateCustomOptionCatalogRule->execute(
366-
$option->getProduct(),
367-
(float)$result->getPrice(),
368-
$result->getPriceType() === Value::TYPE_PERCENT
369-
);
370-
if ($catalogPriceValue !== null) {
371-
$optionCalculatedValue = $catalogPriceValue;
372-
} else {
373-
$optionCalculatedValue = $this->_getChargeableOptionPrice(
374-
$result->getPrice(),
375-
$result->getPriceType() === Value::TYPE_PERCENT,
376-
$basePrice
377-
);
378-
}
379-
return $optionCalculatedValue;
380-
}
381337
}

0 commit comments

Comments
 (0)