Skip to content

Commit 867552e

Browse files
author
Yu Tang
committed
MAGETWO-43291: Incl tax prices on Product and catalog pages include tax on FPT
- Do not add weee tax in the case display price excludes tax
1 parent 5f44c5c commit 867552e

File tree

2 files changed

+207
-2
lines changed

2 files changed

+207
-2
lines changed

app/code/Magento/Weee/Pricing/TaxAdjustment.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Framework\Pricing\SaleableInterface;
1212
use Magento\Framework\Pricing\PriceCurrencyInterface;
1313
use Magento\Weee\Helper\Data as WeeeHelper;
14+
use Magento\Tax\Helper\Data as TaxHelper;
1415

1516
/**
1617
* Weee tax pricing adjustment
@@ -29,6 +30,11 @@ class TaxAdjustment implements AdjustmentInterface
2930
*/
3031
protected $weeeHelper;
3132

33+
/**
34+
* @var TaxHelper
35+
*/
36+
protected $taxHelper;
37+
3238
/**
3339
* Sort order
3440
*
@@ -48,9 +54,14 @@ class TaxAdjustment implements AdjustmentInterface
4854
* @param PriceCurrencyInterface $priceCurrency
4955
* @param int $sortOrder
5056
*/
51-
public function __construct(WeeeHelper $weeeHelper, PriceCurrencyInterface $priceCurrency, $sortOrder = null)
52-
{
57+
public function __construct(
58+
WeeeHelper $weeeHelper,
59+
TaxHelper $taxHelper,
60+
PriceCurrencyInterface $priceCurrency,
61+
$sortOrder = null
62+
) {
5363
$this->weeeHelper = $weeeHelper;
64+
$this->taxHelper = $taxHelper;
5465
$this->priceCurrency = $priceCurrency;
5566
$this->sortOrder = $sortOrder;
5667
}
@@ -83,6 +94,9 @@ public function isIncludedInBasePrice()
8394
*/
8495
public function isIncludedInDisplayPrice()
8596
{
97+
if ($this->taxHelper->displayPriceExcludingTax()) {
98+
return false;
99+
}
86100
if ($this->weeeHelper->isEnabled() == true &&
87101
$this->weeeHelper->isTaxable() == true &&
88102
$this->weeeHelper->typeOfDisplay([\Magento\Weee\Model\Tax::DISPLAY_EXCL]) == false) {
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
// @codingStandardsIgnoreFile
8+
9+
namespace Magento\Weee\Test\Unit\Pricing;
10+
11+
use \Magento\Weee\Pricing\TaxAdjustment;
12+
13+
14+
class TaxAdjustmentTest extends \PHPUnit_Framework_TestCase
15+
{
16+
/**
17+
* @var TaxAdjustment
18+
*/
19+
protected $adjustment;
20+
21+
/**
22+
* @var \Magento\Weee\Helper\Data | \PHPUnit_Framework_MockObject_MockObject
23+
*/
24+
protected $weeeHelperMock;
25+
26+
/**
27+
* @var \Magento\Tax\Helper\Data | \PHPUnit_Framework_MockObject_MockObject
28+
*/
29+
protected $taxHelperMock;
30+
31+
/**
32+
* @var \Magento\Framework\Pricing\PriceCurrencyInterface|\PHPUnit_Framework_MockObject_MockObject
33+
*/
34+
protected $priceCurrencyMock;
35+
36+
/**
37+
* @var int
38+
*/
39+
protected $sortOrder = 5;
40+
41+
public function setUp()
42+
{
43+
$this->weeeHelperMock = $this->getMock('Magento\Weee\Helper\Data', [], [], '', false);
44+
$this->taxHelperMock = $this->getMock('Magento\Tax\Helper\Data', [], [], '', false);
45+
$this->priceCurrencyMock = $this->getMock('\Magento\Framework\Pricing\PriceCurrencyInterface');
46+
$this->priceCurrencyMock->expects($this->any())
47+
->method('convertAndRound')
48+
->will($this->returnCallback(
49+
function ($arg) {
50+
return round($arg * 0.5, 2);
51+
}
52+
)
53+
);
54+
$this->priceCurrencyMock->expects($this->any())
55+
->method('convert')
56+
->will($this->returnCallback(
57+
function ($arg) {
58+
return $arg * 0.5;
59+
}
60+
)
61+
);
62+
63+
$this->adjustment = new TaxAdjustment(
64+
$this->weeeHelperMock,
65+
$this->taxHelperMock,
66+
$this->priceCurrencyMock,
67+
$this->sortOrder
68+
);
69+
}
70+
71+
public function testGetAdjustmentCode()
72+
{
73+
$this->assertEquals(TaxAdjustment::ADJUSTMENT_CODE, $this->adjustment->getAdjustmentCode());
74+
}
75+
76+
public function testIsIncludedInBasePrice()
77+
{
78+
$this->assertFalse($this->adjustment->isIncludedInBasePrice());
79+
}
80+
81+
/**
82+
* @param bool $taxDisplayExclTax
83+
* @param bool $isWeeeTaxable
84+
* @param bool $weeeDisplayConfig
85+
* @param bool $expectedResult
86+
* @dataProvider isIncludedInDisplayPriceDataProvider
87+
*/
88+
public function testIsIncludedInDisplayPrice(
89+
$taxDisplayExclTax,
90+
$isWeeeTaxable,
91+
$weeeDisplayConfig,
92+
$expectedResult
93+
)
94+
{
95+
$this->weeeHelperMock->expects($this->any())
96+
->method('isEnabled')
97+
->willReturn(true);
98+
$this->weeeHelperMock->expects($this->any())
99+
->method('isTaxable')
100+
->willReturn($isWeeeTaxable);
101+
$this->taxHelperMock->expects($this->any())
102+
->method('displayPriceExcludingTax')
103+
->willReturn($taxDisplayExclTax);
104+
105+
$displayTypes = [
106+
\Magento\Weee\Model\Tax::DISPLAY_EXCL,
107+
];
108+
$this->weeeHelperMock->expects($this->any())
109+
->method('typeOfDisplay')
110+
->with($displayTypes)
111+
->will($this->returnValue($weeeDisplayConfig));
112+
113+
$this->assertEquals($expectedResult, $this->adjustment->isIncludedInDisplayPrice());
114+
}
115+
116+
/**
117+
* @return array
118+
*/
119+
public function isIncludedInDisplayPriceDataProvider()
120+
{
121+
return [
122+
'display_incl_tax' => [
123+
'tax_display_excl_tax' => false,
124+
'is_weee_taxable' => true,
125+
'weee_display_config' => false,
126+
'expected_result' => true,
127+
],
128+
'display_incl_tax_excl_weee' => [
129+
'tax_display_excl_tax' => false,
130+
'is_weee_taxable' => true,
131+
'weee_display_config' => true,
132+
'expected_result' => false,
133+
],
134+
'display_excl_tax' => [
135+
'tax_display_excl_tax' => true,
136+
'is_weee_taxable' => true,
137+
'weee_display_config' => true,
138+
'expected_result' => false,
139+
],
140+
'display_excl_tax_incl_weee' => [
141+
'tax_display_excl_tax' => true,
142+
'is_weee_taxable' => true,
143+
'weee_display_config' => false,
144+
'expected_result' => false,
145+
],
146+
];
147+
}
148+
149+
/**
150+
* @param float $amount
151+
* @param \Magento\Framework\DataObject[] $weeeAttributes
152+
* @param float $expectedResult
153+
* @dataProvider applyAdjustmentDataProvider
154+
*/
155+
public function testApplyAdjustment($amount, $weeeAttributes, $expectedResult)
156+
{
157+
$object = $this->getMockForAbstractClass('Magento\Framework\Pricing\SaleableInterface');
158+
159+
$this->weeeHelperMock->expects($this->any())
160+
->method('getProductWeeeAttributes')
161+
->will($this->returnValue($weeeAttributes));
162+
163+
$this->assertEquals($expectedResult, $this->adjustment->applyAdjustment($amount, $object));
164+
}
165+
166+
/**
167+
* @return array
168+
*/
169+
public function applyAdjustmentDataProvider()
170+
{
171+
return [
172+
[
173+
'amount' => 10,
174+
'weee_attributes' => [
175+
new \Magento\Framework\DataObject(
176+
[
177+
'tax_amount' => 5,
178+
]
179+
),
180+
new \Magento\Framework\DataObject(
181+
[
182+
'tax_amount' => 2.5,
183+
]
184+
),
185+
186+
],
187+
'expected_result' => 13.75,
188+
],
189+
];
190+
}
191+
}

0 commit comments

Comments
 (0)