Skip to content

Commit d8b1a2f

Browse files
author
Alex Paliarush
committed
MAGETWO-61120: Tax and Order total not correct when discount is applied
1 parent ff5fe6e commit d8b1a2f

File tree

11 files changed

+116
-13
lines changed

11 files changed

+116
-13
lines changed

app/code/Magento/Tax/Model/System/Message/Notification/ApplyDiscountOnPrices.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function getText()
8282

8383
if ($this->isDisplayed()) {
8484
$messageDetails .= '<strong>';
85-
$messageDetails .= __('If you want to apply discount on prices including tax and apply customer tax after discount, you must set Catalog Prices to “Including Price”. ');
85+
$messageDetails .= __('To apply the discount on prices including tax and apply the tax after discount, set Catalog Prices to “Including Price”. ');
8686
$messageDetails .= '</strong><p>';
8787
$messageDetails .= __('Store(s) affected: ');
8888
$messageDetails .= implode(', ', $this->getStoresWithWrongSettings());

app/code/Magento/Tax/Model/System/Message/Notification/DiscountErrors.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,7 @@ public function getText()
8080

8181
if (!empty($this->getStoresWithWrongSettings()) && !$this->taxConfig->isWrongDiscountSettingsIgnored()) {
8282
$messageDetails .= '<strong>';
83-
$messageDetails .= __(
84-
'Warning tax discount configuration might result in different discounts than a customer might expect. '
85-
);
83+
$messageDetails .= __('With customer tax applied “Before Discount”, the final discount calculation may not match customers’ expectations. ');
8684
$messageDetails .= '</strong><p>';
8785
$messageDetails .= __('Store(s) affected: ');
8886
$messageDetails .= implode(', ', $this->getStoresWithWrongSettings());

app/code/Magento/Tax/Model/System/Message/Notification/RoundingErrors.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function getText()
7878

7979
if (!empty($this->getStoresWithWrongSettings()) && !$this->taxConfig->isWrongDisplaySettingsIgnored()) {
8080
$messageDetails .= '<strong>';
81-
$messageDetails .= __('Warning tax configuration can result in rounding errors. ');
81+
$messageDetails .= __('Your current tax configuration may result in rounding errors. ');
8282
$messageDetails .= '</strong><p>';
8383
$messageDetails .= __('Store(s) affected: ');
8484
$messageDetails .= implode(', ', $this->getStoresWithWrongSettings());

app/code/Magento/Tax/Model/System/Message/Notifications.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public function __construct(
7575
* Retrieve unique message identity
7676
*
7777
* @return string
78+
* @codeCoverageIgnore
7879
*/
7980
public function getIdentity()
8081
{
@@ -120,6 +121,7 @@ public function getText()
120121
* Retrieve message severity
121122
*
122123
* @return int
124+
* @codeCoverageIgnore
123125
*/
124126
public function getSeverity()
125127
{

app/code/Magento/Tax/Test/Unit/Model/ConfigTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,12 @@ public function dataProviderScopeConfigMethods()
360360
true,
361361
true
362362
],
363+
[
364+
'isWrongApplyDiscountSettingIgnored',
365+
Config::XML_PATH_TAX_NOTIFICATION_IGNORE_APPLY_DISCOUNT,
366+
true,
367+
true
368+
],
363369
[
364370
'getInfoUrl',
365371
Config::XML_PATH_TAX_NOTIFICATION_INFO_URL,

app/code/Magento/Tax/Test/Unit/Model/System/Message/Notification/ApplyDiscountOnPricesTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ public function testGetText()
150150
->willReturn('http://example.com');
151151
$this->applyDiscountOnPricesNotification->isDisplayed();
152152
$this->assertEquals(
153-
'<strong>If you want to apply discount on prices including tax and apply customer tax after discount, '
154-
. 'you must set Catalog Prices to “Including Price”. </strong><p>Store(s) affected: testWebsiteName '
153+
'<strong>To apply the discount on prices including tax and apply the tax after discount, '
154+
. 'set Catalog Prices to “Including Price”. </strong><p>Store(s) affected: testWebsiteName '
155155
. '(testStoreName)</p><p>Click on the link to '
156156
. '<a href="http://example.com">ignore this notification</a></p>',
157157
$this->applyDiscountOnPricesNotification->getText()

app/code/Magento/Tax/Test/Unit/Model/System/Message/Notification/DiscountErrorsTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ public function testGetText()
9494
->willReturn('http://example.com');
9595
$this->discountErrorsNotification->isDisplayed();
9696
$this->assertEquals(
97-
'<strong>Warning tax discount configuration might result in different discounts than a customer might '
98-
. 'expect. </strong><p>Store(s) affected: testWebsiteName (testStoreName)</p><p>Click on the link to '
99-
. '<a href="http://example.com">ignore this notification</a></p>',
97+
'<strong>With customer tax applied “Before Discount”, the final discount calculation may not match '
98+
. 'customers’ expectations. </strong><p>Store(s) affected: testWebsiteName (testStoreName)'
99+
. '</p><p>Click on the link to <a href="http://example.com">ignore this notification</a></p>',
100100
$this->discountErrorsNotification->getText()
101101
);
102102
}

app/code/Magento/Tax/Test/Unit/Model/System/Message/Notification/RoundingErrorsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public function testGetText()
133133
->willReturn('http://example.com');
134134
$this->roundingErrorsNotification->isDisplayed();
135135
$this->assertEquals(
136-
'<strong>Warning tax configuration can result in rounding errors. '
136+
'<strong>Your current tax configuration may result in rounding errors. '
137137
. '</strong><p>Store(s) affected: testWebsiteName (testStoreName)</p><p>Click on the link to '
138138
. '<a href="http://example.com">ignore this notification</a></p>',
139139
$this->roundingErrorsNotification->getText()
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Tax\Test\Unit\Model\System\Message;
8+
9+
use Magento\Tax\Model\Config as TaxConfig;
10+
use Magento\Tax\Model\System\Message\Notifications;
11+
use Magento\Store\Model\StoreManagerInterface;
12+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
13+
use Magento\Framework\UrlInterface;
14+
use Magento\Tax\Model\System\Message\NotificationInterface;
15+
16+
/**
17+
* Test class for @see \Magento\Tax\Model\System\Message\Notifications
18+
*/
19+
class NotificationsTest extends \PHPUnit_Framework_TestCase
20+
{
21+
/**
22+
* @var Notifications
23+
*/
24+
private $notifications;
25+
26+
/**
27+
* @var StoreManagerInterface | \PHPUnit_Framework_MockObject_MockObject
28+
*/
29+
private $storeManagerMock;
30+
31+
/**
32+
* @var UrlInterface | \PHPUnit_Framework_MockObject_MockObject
33+
*/
34+
private $urlBuilderMock;
35+
36+
/**
37+
* @var TaxConfig | \PHPUnit_Framework_MockObject_MockObject
38+
*/
39+
private $taxConfigMock;
40+
41+
/**
42+
* @var NotificationInterface | \PHPUnit_Framework_MockObject_MockObject
43+
*/
44+
private $notificationMock;
45+
46+
protected function setUp()
47+
{
48+
parent::setUp();
49+
50+
$this->storeManagerMock = $this->getMock(StoreManagerInterface::class, [], [], '', false);
51+
$this->urlBuilderMock = $this->getMock(UrlInterface::class, [], [], '', false);
52+
$this->taxConfigMock = $this->getMock(TaxConfig::class, [], [], '', false);
53+
$this->notificationMock = $this->getMock(NotificationInterface::class, [], [], '', false);
54+
$this->notifications = (new ObjectManager($this))->getObject(
55+
Notifications::class,
56+
[
57+
'storeManager' => $this->storeManagerMock,
58+
'urlBuilder' => $this->urlBuilderMock,
59+
'taxConfig' => $this->taxConfigMock,
60+
'notifications' => [$this->notificationMock]
61+
]
62+
);
63+
}
64+
65+
/**
66+
* @dataProvider dataProviderIsDisplayed
67+
*/
68+
public function testIsDisplayed(
69+
$isNotificationDisplayed,
70+
$expectedResult
71+
) {
72+
$this->notificationMock->expects($this->once())->method('isDisplayed')->willReturn($isNotificationDisplayed);
73+
$this->assertEquals($expectedResult, $this->notifications->isDisplayed());
74+
}
75+
76+
public function dataProviderIsDisplayed()
77+
{
78+
return [
79+
[true, true],
80+
[false, false]
81+
];
82+
}
83+
84+
public function testGetText()
85+
{
86+
$this->notificationMock->expects($this->once())->method('getText')->willReturn('Notification Text.');
87+
$this->taxConfigMock->expects($this->once())->method('getInfoUrl')->willReturn('http://info-url');
88+
$this->urlBuilderMock->expects($this->once())->method('getUrl')
89+
->with('adminhtml/system_config/edit/section/tax')->willReturn('http://tax-config-url');
90+
91+
$this->assertEquals(
92+
'Notification Text.<p>Please see <a href="http://info-url">documentation</a> for more details. '
93+
. 'Click here to go to <a href="http://tax-config-url">Tax Configuration</a> and change your settings.</p>',
94+
$this->notifications->getText()
95+
);
96+
}
97+
}

app/code/Magento/Tax/etc/adminhtml/di.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<argument name="notifications" xsi:type="array">
1919
<item name="roundingErrors" xsi:type="object">Magento\Tax\Model\System\Message\Notification\RoundingErrors</item>
2020
<item name="discountErrors" xsi:type="object">Magento\Tax\Model\System\Message\Notification\DiscountErrors</item>
21-
<item name="priceExcludingTaxErrors" xsi:type="object">Magento\Tax\Model\System\Message\Notification\AdminPriceExcludingTax</item>
21+
<item name="applyDiscountOnPrices" xsi:type="object">Magento\Tax\Model\System\Message\Notification\ApplyDiscountOnPrices</item>
2222
</argument>
2323
</arguments>
2424
</type>

0 commit comments

Comments
 (0)