Skip to content
Snippets Groups Projects
Commit 9d722633 authored by David Manners's avatar David Manners
Browse files

MAGETWO-85643: Add price calculation improvement for product option value price #11563

 - Merge Pull Request magento/magento2#11563 from marinagociu/magento2:fix-custom-option-price
 - Merged commits:
   1. 33aa293e
   2. 7ff22bf3
parents 3839c0fc 7ff22bf3
No related merge requests found
...@@ -11,6 +11,7 @@ namespace Magento\Catalog\Model\Product\Option; ...@@ -11,6 +11,7 @@ namespace Magento\Catalog\Model\Product\Option;
use Magento\Catalog\Model\Product; use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\Product\Option; use Magento\Catalog\Model\Product\Option;
use Magento\Framework\Model\AbstractModel; use Magento\Framework\Model\AbstractModel;
use Magento\Catalog\Pricing\Price\BasePrice;
/** /**
* Catalog product option select type model * Catalog product option select type model
...@@ -224,7 +225,7 @@ class Value extends AbstractModel implements \Magento\Catalog\Api\Data\ProductCu ...@@ -224,7 +225,7 @@ class Value extends AbstractModel implements \Magento\Catalog\Api\Data\ProductCu
public function getPrice($flag = false) public function getPrice($flag = false)
{ {
if ($flag && $this->getPriceType() == self::TYPE_PERCENT) { if ($flag && $this->getPriceType() == self::TYPE_PERCENT) {
$basePrice = $this->getOption()->getProduct()->getFinalPrice(); $basePrice = $this->getOption()->getProduct()->getPriceInfo()->getPrice(BasePrice::PRICE_CODE)->getValue();
$price = $basePrice * ($this->_getData(self::KEY_PRICE) / 100); $price = $basePrice * ($this->_getData(self::KEY_PRICE) / 100);
return $price; return $price;
} }
......
...@@ -164,13 +164,27 @@ class ValueTest extends \PHPUnit\Framework\TestCase ...@@ -164,13 +164,27 @@ class ValueTest extends \PHPUnit\Framework\TestCase
private function getMockedProduct() private function getMockedProduct()
{ {
$mockBuilder = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) $mockBuilder = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
->setMethods(['getFinalPrice', '__wakeup']) ->setMethods(['getPriceInfo', '__wakeup'])
->disableOriginalConstructor(); ->disableOriginalConstructor();
$mock = $mockBuilder->getMock(); $mock = $mockBuilder->getMock();
$mock->expects($this->any()) $priceInfoMock = $this->getMockForAbstractClass(
->method('getFinalPrice') \Magento\Framework\Pricing\PriceInfoInterface::class,
->will($this->returnValue(10)); [],
'',
false,
false,
true,
['getPrice']
);
$priceMock = $this->getMockForAbstractClass(\Magento\Framework\Pricing\Price\PriceInterface::class);
$priceInfoMock->expects($this->any())->method('getPrice')->willReturn($priceMock);
$mock->expects($this->any())->method('getPriceInfo')->willReturn($priceInfoMock);
$priceMock->expects($this->any())->method('getValue')->willReturn(10);
return $mock; return $mock;
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment