Skip to content

Commit 11020c2

Browse files
committed
Add price calculation improvement for product option value price
1 parent 50f62cb commit 11020c2

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
namespace Magento\Catalog\Model\Product\Option;
1010

11+
use Magento\Catalog\Pricing\Price\BasePrice;
1112
use Magento\Framework\Model\AbstractModel;
1213
use Magento\Catalog\Model\Product;
1314
use Magento\Catalog\Model\Product\Option;
@@ -225,7 +226,7 @@ public function saveValues()
225226
public function getPrice($flag = false)
226227
{
227228
if ($flag && $this->getPriceType() == self::TYPE_PERCENT) {
228-
$basePrice = $this->getOption()->getProduct()->getFinalPrice();
229+
$basePrice = $this->getOption()->getProduct()->getPriceInfo()->getPrice(BasePrice::PRICE_CODE)->getValue();
229230
$price = $basePrice * ($this->_getData(self::KEY_PRICE) / 100);
230231
return $price;
231232
}

app/code/Magento/Catalog/Test/Unit/Model/Product/Option/ValueTest.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,30 @@ private function getMockedOption()
170170
private function getMockedProduct()
171171
{
172172
$mockBuilder = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
173-
->setMethods(['getFinalPrice', '__wakeup'])
173+
->setMethods(['getPriceInfo', '__wakeup'])
174174
->disableOriginalConstructor();
175175
$mock = $mockBuilder->getMock();
176176

177177
$mock->expects($this->any())
178178
->method('getFinalPrice')
179179
->will($this->returnValue(10));
180+
$priceInfoMock = $this->getMockForAbstractClass(
181+
\Magento\Framework\Pricing\PriceInfoInterface::class,
182+
[],
183+
'',
184+
false,
185+
false,
186+
true,
187+
['getPrice']
188+
);
189+
190+
$priceMock = $this->getMockForAbstractClass(\Magento\Framework\Pricing\Price\PriceInterface::class);
191+
192+
$priceInfoMock->expects($this->any())->method('getPrice')->willReturn($priceMock);
193+
194+
$mock->expects($this->any())->method('getPriceInfo')->willReturn($priceInfoMock);
195+
196+
$priceMock->expects($this->any())->method('getValue')->willReturn(10);
180197

181198
return $mock;
182199
}

0 commit comments

Comments
 (0)