Skip to content

Commit 9a28b74

Browse files
committed
MC-35065: Catalog pricerules are not working with custom options as expected in Magento 2.3.0 product details page
1 parent 3db593b commit 9a28b74

File tree

8 files changed

+226
-98
lines changed

8 files changed

+226
-98
lines changed

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

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212

1313
namespace Magento\Catalog\Block\Product\View\Options;
1414

15+
use Magento\Catalog\Pricing\Price\BasePrice;
16+
use Magento\Catalog\Pricing\Price\CalculateCustomOptionCatalogRule;
1517
use Magento\Catalog\Pricing\Price\CustomOptionPriceInterface;
18+
use Magento\Framework\App\ObjectManager;
1619

1720
/**
1821
* Product options section abstract block.
@@ -47,20 +50,29 @@ abstract class AbstractOptions extends \Magento\Framework\View\Element\Template
4750
*/
4851
protected $_catalogHelper;
4952

53+
/**
54+
* @var CalculateCustomOptionCatalogRule
55+
*/
56+
private $calculateCustomOptionCatalogRule;
57+
5058
/**
5159
* @param \Magento\Framework\View\Element\Template\Context $context
5260
* @param \Magento\Framework\Pricing\Helper\Data $pricingHelper
5361
* @param \Magento\Catalog\Helper\Data $catalogData
5462
* @param array $data
63+
* @param CalculateCustomOptionCatalogRule $calculateCustomOptionCatalogRule
5564
*/
5665
public function __construct(
5766
\Magento\Framework\View\Element\Template\Context $context,
5867
\Magento\Framework\Pricing\Helper\Data $pricingHelper,
5968
\Magento\Catalog\Helper\Data $catalogData,
60-
array $data = []
69+
array $data = [],
70+
CalculateCustomOptionCatalogRule $calculateCustomOptionCatalogRule = null
6171
) {
6272
$this->pricingHelper = $pricingHelper;
6373
$this->_catalogHelper = $catalogData;
74+
$this->calculateCustomOptionCatalogRule = $calculateCustomOptionCatalogRule
75+
?? ObjectManager::getInstance()->get(CalculateCustomOptionCatalogRule::class);
6476
parent::__construct($context, $data);
6577
}
6678

@@ -112,7 +124,6 @@ public function getOption()
112124
* Retrieve formatted price
113125
*
114126
* @return string
115-
* @since 102.0.6
116127
*/
117128
public function getFormattedPrice()
118129
{
@@ -132,7 +143,7 @@ public function getFormattedPrice()
132143
*
133144
* @return string
134145
*
135-
* @deprecated 102.0.6
146+
* @deprecated
136147
* @see getFormattedPrice()
137148
*/
138149
public function getFormatedPrice()
@@ -162,6 +173,15 @@ protected function _formatPrice($value, $flag = true)
162173
$priceStr = $sign;
163174

164175
$customOptionPrice = $this->getProduct()->getPriceInfo()->getPrice('custom_option_price');
176+
177+
if (!$value['is_percent']) {
178+
$value['pricing_value'] = $this->calculateCustomOptionCatalogRule->execute(
179+
$this->getProduct(),
180+
(float)$value['pricing_value'],
181+
(bool)$value['is_percent']
182+
);
183+
}
184+
165185
$context = [CustomOptionPriceInterface::CONFIGURATION_OPTION_FLAG => true];
166186
$optionAmount = $customOptionPrice->getCustomAmount($value['pricing_value'], null, $context);
167187
$priceStr .= $this->getLayout()->getBlock('product.price.render.default')->renderAmount(

0 commit comments

Comments
 (0)