Skip to content

Commit aa965b9

Browse files
author
Oleksii Korshenko
authored
MAGETWO-85643: Add price calculation improvement for product option value price #11563
2 parents 3839c0f + 9d72263 commit aa965b9

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
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
@@ -11,6 +11,7 @@
1111
use Magento\Catalog\Model\Product;
1212
use Magento\Catalog\Model\Product\Option;
1313
use Magento\Framework\Model\AbstractModel;
14+
use Magento\Catalog\Pricing\Price\BasePrice;
1415

1516
/**
1617
* Catalog product option select type model
@@ -224,7 +225,7 @@ public function saveValues()
224225
public function getPrice($flag = false)
225226
{
226227
if ($flag && $this->getPriceType() == self::TYPE_PERCENT) {
227-
$basePrice = $this->getOption()->getProduct()->getFinalPrice();
228+
$basePrice = $this->getOption()->getProduct()->getPriceInfo()->getPrice(BasePrice::PRICE_CODE)->getValue();
228229
$price = $basePrice * ($this->_getData(self::KEY_PRICE) / 100);
229230
return $price;
230231
}

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,27 @@ private function getMockedOption()
164164
private function getMockedProduct()
165165
{
166166
$mockBuilder = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
167-
->setMethods(['getFinalPrice', '__wakeup'])
167+
->setMethods(['getPriceInfo', '__wakeup'])
168168
->disableOriginalConstructor();
169169
$mock = $mockBuilder->getMock();
170170

171-
$mock->expects($this->any())
172-
->method('getFinalPrice')
173-
->will($this->returnValue(10));
171+
$priceInfoMock = $this->getMockForAbstractClass(
172+
\Magento\Framework\Pricing\PriceInfoInterface::class,
173+
[],
174+
'',
175+
false,
176+
false,
177+
true,
178+
['getPrice']
179+
);
180+
181+
$priceMock = $this->getMockForAbstractClass(\Magento\Framework\Pricing\Price\PriceInterface::class);
182+
183+
$priceInfoMock->expects($this->any())->method('getPrice')->willReturn($priceMock);
184+
185+
$mock->expects($this->any())->method('getPriceInfo')->willReturn($priceInfoMock);
186+
187+
$priceMock->expects($this->any())->method('getValue')->willReturn(10);
174188

175189
return $mock;
176190
}

0 commit comments

Comments
 (0)