Skip to content

Commit ff5fe6e

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

File tree

5 files changed

+182
-405
lines changed

5 files changed

+182
-405
lines changed

app/code/Magento/Tax/Model/Config.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Config
2323

2424
const XML_PATH_TAX_NOTIFICATION_IGNORE_PRICE_DISPLAY = 'tax/notification/ignore_price_display';
2525

26-
const XML_PATH_TAX_NOTIFICATION_IGNORE_PRICE_EXCLUDING_TAX_SETTINGS = 'tax/notification/ignore_price_excluding_tax';
26+
const XML_PATH_TAX_NOTIFICATION_IGNORE_APPLY_DISCOUNT = 'tax/notification/ignore_apply_discount';
2727

2828
const XML_PATH_TAX_NOTIFICATION_INFO_URL = 'tax/notification/info_url';
2929

@@ -764,18 +764,19 @@ public function crossBorderTradeEnabled($store = null)
764764
}
765765

766766
/**
767-
* Check if admin notification about possible issues related to tax display settings should be ignored.
767+
* Check if admin notification related to misconfiguration of "Apply Discount On Prices" should be ignored.
768768
*
769-
* For the case when prices under "Calculation Settings" are set to "Excluding Tax"
770-
* and at the same time some of price display settings are set to "Including Tax"
769+
* Warning is displayed in case when "Catalog Prices" = "Excluding Tax"
770+
* AND "Apply Discount On Prices" = "Including Tax"
771+
* AND "Apply Customer Tax" = "After Discount"
771772
*
772773
* @param null|string|Store $store
773774
* @return bool
774775
*/
775-
public function isWrongPriceExcludingTaxSettingsIgnored($store = null)
776+
public function isWrongApplyDiscountSettingIgnored($store = null)
776777
{
777778
return (bool)$this->_scopeConfig->getValue(
778-
self::XML_PATH_TAX_NOTIFICATION_IGNORE_PRICE_EXCLUDING_TAX_SETTINGS,
779+
self::XML_PATH_TAX_NOTIFICATION_IGNORE_APPLY_DISCOUNT,
779780
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
780781
$store
781782
);

app/code/Magento/Tax/Model/Config/Notification.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function afterSave()
5252
if ($this->isValueChanged()) {
5353
$this->_resetNotificationFlag(Config::XML_PATH_TAX_NOTIFICATION_IGNORE_DISCOUNT);
5454
$this->_resetNotificationFlag(Config::XML_PATH_TAX_NOTIFICATION_IGNORE_PRICE_DISPLAY);
55-
$this->_resetNotificationFlag(Config::XML_PATH_TAX_NOTIFICATION_IGNORE_PRICE_EXCLUDING_TAX_SETTINGS);
55+
$this->_resetNotificationFlag(Config::XML_PATH_TAX_NOTIFICATION_IGNORE_APPLY_DISCOUNT);
5656
}
5757
return parent::afterSave();
5858
}

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

Lines changed: 14 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
use Magento\Tax\Model\Config;
99

1010
/**
11-
* Class allows to show admin notification about possible issues related to tax calculation and display settings.
11+
* Class allows to show admin notification about possible issues related to "Apply Discount On Prices" setting.
1212
*
13-
* For the case when prices under "Calculation Settings" are set to "Excluding Tax"
14-
* and at the same time some of price display settings are set to "Including Tax"
13+
* Warning is displayed in case when "Catalog Prices" = "Excluding Tax"
14+
* AND "Apply Discount On Prices" = "Including Tax"
15+
* AND "Apply Customer Tax" = "After Discount"
1516
*/
16-
class AdminPriceExcludingTax implements \Magento\Tax\Model\System\Message\NotificationInterface
17+
class ApplyDiscountOnPrices implements \Magento\Tax\Model\System\Message\NotificationInterface
1718
{
1819
/**
1920
* @var \Magento\Store\Model\StoreManagerInterface
@@ -58,15 +59,15 @@ public function __construct(
5859
*/
5960
public function getIdentity()
6061
{
61-
return 'TAX_NOTIFICATION_PRICE_EXCLUDING_TAX';
62+
return 'TAX_NOTIFICATION_APPLY_DISCOUNT';
6263
}
6364

6465
/**
6566
* {@inheritdoc}
6667
*/
6768
public function isDisplayed()
6869
{
69-
if (!$this->taxConfig->isWrongPriceExcludingTaxSettingsIgnored() && $this->getStoresWithWrongSettings()) {
70+
if (!$this->taxConfig->isWrongApplyDiscountSettingIgnored() && $this->getStoresWithWrongSettings()) {
7071
return true;
7172
}
7273
return false;
@@ -81,14 +82,14 @@ public function getText()
8182

8283
if ($this->isDisplayed()) {
8384
$messageDetails .= '<strong>';
84-
$messageDetails .= __('Current tax configuration can result in rounding errors and discount calculation errors. ');
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”. ');
8586
$messageDetails .= '</strong><p>';
8687
$messageDetails .= __('Store(s) affected: ');
8788
$messageDetails .= implode(', ', $this->getStoresWithWrongSettings());
8889
$messageDetails .= '</p><p>';
8990
$messageDetails .= __(
9091
'Click on the link to <a href="%1">ignore this notification</a>',
91-
$this->urlBuilder->getUrl('tax/tax/ignoreTaxNotification', ['section' => 'price_excluding_tax'])
92+
$this->urlBuilder->getUrl('tax/tax/ignoreTaxNotification', ['section' => 'apply_discount'])
9293
);
9394
$messageDetails .= "</p>";
9495
}
@@ -106,7 +107,7 @@ public function getSeverity()
106107
}
107108

108109
/**
109-
* Return list of store names which have incompatible tax calculation and tax display settings.
110+
* Return list of store names which have invalid settings.
110111
*
111112
* @return array
112113
*/
@@ -127,56 +128,15 @@ private function getStoresWithWrongSettings()
127128
}
128129

129130
/**
130-
* Check if tax calculation and tax display settings are compatible.
131+
* Check if settings are valid.
131132
*
132133
* @param null|int|bool|string|\Magento\Store\Model\Store $store $store
133134
* @return bool false if settings are incorrect
134135
*/
135136
private function checkSettings($store = null)
136137
{
137-
$adminCatalogPricesExcludeTax = !$this->taxConfig->priceIncludesTax($store)
138-
|| !$this->taxConfig->shippingPriceIncludesTax($store);
139-
$displayPricesWhichIncludeTax = $this->hasCatalogDisplaySettingsWhichIncludeTax($store)
140-
|| $this->hasCartDisplaySettingsWhichIncludeTax($store)
141-
|| $this->hasSalesDisplaySettingsWhichIncludeTax($store);
142-
return !($adminCatalogPricesExcludeTax && $displayPricesWhichIncludeTax);
143-
}
144-
145-
/**
146-
* Check if there are any price display settings for catalog with values other than "Excluding tax"
147-
*
148-
* @param null|int|bool|string|\Magento\Store\Model\Store $store $store
149-
* @return bool
150-
*/
151-
private function hasCatalogDisplaySettingsWhichIncludeTax($store = null)
152-
{
153-
return $this->taxConfig->getPriceDisplayType($store) !== Config::DISPLAY_TYPE_EXCLUDING_TAX
154-
|| $this->taxConfig->getShippingPriceDisplayType($store) !== Config::DISPLAY_TYPE_EXCLUDING_TAX;
155-
}
156-
157-
/**
158-
* Check if there are any price display settings for cart with values other than "Excluding tax"
159-
*
160-
* @param null|int|bool|string|\Magento\Store\Model\Store $store $store
161-
* @return bool
162-
*/
163-
private function hasCartDisplaySettingsWhichIncludeTax($store = null)
164-
{
165-
return !$this->taxConfig->displayCartPricesExclTax($store)
166-
|| !$this->taxConfig->displayCartSubtotalExclTax($store)
167-
|| !$this->taxConfig->displayCartShippingExclTax($store);
168-
}
169-
170-
/**
171-
* Check if there are any price display settings for orders, invoices, credit memos with values not "Excluding tax"
172-
*
173-
* @param null|int|bool|string|\Magento\Store\Model\Store $store $store
174-
* @return bool
175-
*/
176-
private function hasSalesDisplaySettingsWhichIncludeTax($store = null)
177-
{
178-
return !$this->taxConfig->displaySalesPricesExclTax($store)
179-
|| !$this->taxConfig->displaySalesSubtotalExclTax($store)
180-
|| !$this->taxConfig->displaySalesShippingExclTax($store);
138+
return $this->taxConfig->priceIncludesTax($store)
139+
|| !$this->taxConfig->applyTaxAfterDiscount($store)
140+
|| !$this->taxConfig->discountTax($store);
181141
}
182142
}

0 commit comments

Comments
 (0)