Skip to content

Commit 499e951

Browse files
author
Dmytro Voskoboinikov
committed
MAGETWO-70377: [GitHub] Tier price saving percentage wrong when VAT is included in price #8833
1 parent 5712618 commit 499e951

File tree

2 files changed

+35
-16
lines changed

2 files changed

+35
-16
lines changed

app/code/Magento/Catalog/Pricing/Price/TierPrice.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,14 +215,21 @@ protected function getBasePrice()
215215
}
216216

217217
/**
218+
* Calculates savings percentage according to the given tier price amount
219+
* and related product price amount.
220+
*
218221
* @param AmountInterface $amount
222+
*
219223
* @return float
220224
*/
221225
public function getSavePercent(AmountInterface $amount)
222226
{
227+
$productPriceAmount = $this->priceInfo->getPrice(
228+
FinalPrice::PRICE_CODE
229+
)->getAmount();
230+
223231
return round(
224-
100 - ((100 / $this->priceInfo->getPrice(FinalPrice::PRICE_CODE)->getValue())
225-
* $amount->getBaseAmount())
232+
100 - ((100 / $productPriceAmount->getValue()) * $amount->getValue())
226233
);
227234
}
228235

app/code/Magento/Catalog/Test/Unit/Pricing/Price/TierPriceTest.php

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
use Magento\Catalog\Pricing\Price\TierPrice;
1212
use Magento\Catalog\Pricing\Price\FinalPrice;
13+
use Magento\Framework\Pricing\Amount\AmountInterface;
14+
use Magento\Framework\Pricing\Price\PriceInterface;
1315
use Magento\Customer\Model\Group;
1416
use Magento\Customer\Model\GroupManagement;
1517

@@ -250,7 +252,7 @@ public function testGetterTierPriceList($tierPrices, $basePrice, $expectedResult
250252
{
251253
$this->product->setData(TierPrice::PRICE_CODE, $tierPrices);
252254

253-
$price = $this->createMock(\Magento\Framework\Pricing\Price\PriceInterface::class);
255+
$price = $this->createMock(PriceInterface::class);
254256
$price->expects($this->any())->method('getValue')->will($this->returnValue($basePrice));
255257

256258
$this->calculator->expects($this->atLeastOnce())->method('getAmount')
@@ -341,27 +343,37 @@ public function providerForGetterTierPriceList()
341343
}
342344

343345
/**
344-
* @covers \Magento\Catalog\Pricing\Price\TierPrice::__construct
345-
* @covers \Magento\Catalog\Pricing\Price\TierPrice::getSavePercent
346-
* @covers \Magento\Catalog\Pricing\Price\TierPrice::getBasePrice
346+
* @param float $basePrice
347+
* @param float $tierPrice
348+
* @param float $savedPercent
349+
*
347350
* @dataProvider dataProviderGetSavePercent
348351
*/
349352
public function testGetSavePercent($basePrice, $tierPrice, $savedPercent)
350353
{
351-
$price = $this->createMock(\Magento\Framework\Pricing\Price\PriceInterface::class);
354+
/** @var AmountInterface|\PHPUnit_Framework_MockObject_MockObject $amount */
355+
$amount = $this->getMockForAbstractClass(AmountInterface::class);
352356

353-
$this->priceInfo->expects(static::atLeastOnce())
354-
->method('getPrice')
355-
->with(FinalPrice::PRICE_CODE)
356-
->willReturn($price);
357-
$price->expects(static::atLeastOnce())
357+
$amount->expects($this->any())
358+
->method('getValue')
359+
->willReturn($tierPrice);
360+
361+
$basePriceAmount = $this->getMockForAbstractClass(AmountInterface::class);
362+
363+
$basePriceAmount->expects($this->any())
358364
->method('getValue')
359365
->willReturn($basePrice);
360366

361-
$amount = $this->getMockForAbstractClass(\Magento\Framework\Pricing\Amount\AmountInterface::class);
362-
$amount->expects($this->atLeastOnce())
363-
->method('getBaseAmount')
364-
->will($this->returnValue($tierPrice));
367+
$price = $this->getMockForAbstractClass(PriceInterface::class);
368+
369+
$price->expects($this->any())
370+
->method('getAmount')
371+
->willReturn($basePriceAmount);
372+
373+
$this->priceInfo->expects($this->any())
374+
->method('getPrice')
375+
->with(FinalPrice::PRICE_CODE)
376+
->willReturn($price);
365377

366378
$this->assertEquals($savedPercent, $this->model->getSavePercent($amount));
367379
}

0 commit comments

Comments
 (0)