Skip to content

Commit 02e1c6b

Browse files
author
Oleksii Korshenko
authored
Merge pull request #762 from magento-okapis/MAGETWO-61120-Tax-Configuration
Fixed issues: - MAGETWO-61120: Tax and Order total not correct when discount is applied
2 parents 47c3696 + 67c3f20 commit 02e1c6b

File tree

14 files changed

+1099
-123
lines changed

14 files changed

+1099
-123
lines changed

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ 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_APPLY_DISCOUNT = 'tax/notification/ignore_apply_discount';
27+
2628
const XML_PATH_TAX_NOTIFICATION_INFO_URL = 'tax/notification/info_url';
2729

2830
// tax classes
@@ -68,6 +70,7 @@ class Config
6870

6971
const XML_PATH_DISPLAY_CART_SHIPPING = 'tax/cart_display/shipping';
7072

73+
/** @deprecated */
7174
const XML_PATH_DISPLAY_CART_DISCOUNT = 'tax/cart_display/discount';
7275

7376
const XML_PATH_DISPLAY_CART_GRANDTOTAL = 'tax/cart_display/grandtotal';
@@ -85,6 +88,7 @@ class Config
8588

8689
const XML_PATH_DISPLAY_SALES_SHIPPING = 'tax/sales_display/shipping';
8790

91+
/** @deprecated */
8892
const XML_PATH_DISPLAY_SALES_DISCOUNT = 'tax/sales_display/discount';
8993

9094
const XML_PATH_DISPLAY_SALES_GRANDTOTAL = 'tax/sales_display/grandtotal';
@@ -468,6 +472,7 @@ public function displayCartShippingBoth($store = null)
468472
/**
469473
* @param null|string|bool|int|Store $store
470474
* @return bool
475+
* @deprecated
471476
*/
472477
public function displayCartDiscountInclTax($store = null)
473478
{
@@ -481,6 +486,7 @@ public function displayCartDiscountInclTax($store = null)
481486
/**
482487
* @param null|string|bool|int|Store $store
483488
* @return bool
489+
* @deprecated
484490
*/
485491
public function displayCartDiscountExclTax($store = null)
486492
{
@@ -494,6 +500,7 @@ public function displayCartDiscountExclTax($store = null)
494500
/**
495501
* @param null|string|bool|int|Store $store
496502
* @return bool
503+
* @deprecated
497504
*/
498505
public function displayCartDiscountBoth($store = null)
499506
{
@@ -663,6 +670,7 @@ public function displaySalesShippingBoth($store = null)
663670
/**
664671
* @param null|string|bool|int|Store $store
665672
* @return bool
673+
* @deprecated
666674
*/
667675
public function displaySalesDiscountInclTax($store = null)
668676
{
@@ -676,6 +684,7 @@ public function displaySalesDiscountInclTax($store = null)
676684
/**
677685
* @param null|string|bool|int|Store $store
678686
* @return bool
687+
* @deprecated
679688
*/
680689
public function displaySalesDiscountExclTax($store = null)
681690
{
@@ -689,6 +698,7 @@ public function displaySalesDiscountExclTax($store = null)
689698
/**
690699
* @param null|string|bool|int|Store $store
691700
* @return bool
701+
* @deprecated
692702
*/
693703
public function displaySalesDiscountBoth($store = null)
694704
{
@@ -753,6 +763,25 @@ public function crossBorderTradeEnabled($store = null)
753763
);
754764
}
755765

766+
/**
767+
* Check if admin notification related to misconfiguration of "Apply Discount On Prices" should be ignored.
768+
*
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"
772+
*
773+
* @param null|string|Store $store
774+
* @return bool
775+
*/
776+
public function isWrongApplyDiscountSettingIgnored($store = null)
777+
{
778+
return (bool)$this->_scopeConfig->getValue(
779+
self::XML_PATH_TAX_NOTIFICATION_IGNORE_APPLY_DISCOUNT,
780+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
781+
$store
782+
);
783+
}
784+
756785
/**
757786
* Check if do not show notification about wrong display settings
758787
*

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\Tax\Model\Config;
77

88
use Magento\Framework\App\Config\ScopeConfigInterface;
9+
use Magento\Tax\Model\Config;
910

1011
/**
1112
* Tax Config Notification
@@ -49,8 +50,9 @@ public function __construct(
4950
public function afterSave()
5051
{
5152
if ($this->isValueChanged()) {
52-
$this->_resetNotificationFlag(\Magento\Tax\Model\Config::XML_PATH_TAX_NOTIFICATION_IGNORE_DISCOUNT);
53-
$this->_resetNotificationFlag(\Magento\Tax\Model\Config::XML_PATH_TAX_NOTIFICATION_IGNORE_PRICE_DISPLAY);
53+
$this->_resetNotificationFlag(Config::XML_PATH_TAX_NOTIFICATION_IGNORE_DISCOUNT);
54+
$this->_resetNotificationFlag(Config::XML_PATH_TAX_NOTIFICATION_IGNORE_PRICE_DISPLAY);
55+
$this->_resetNotificationFlag(Config::XML_PATH_TAX_NOTIFICATION_IGNORE_APPLY_DISCOUNT);
5456
}
5557
return parent::afterSave();
5658
}
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Tax\Model\System\Message\Notification;
7+
8+
use Magento\Tax\Model\Config;
9+
10+
/**
11+
* Class allows to show admin notification about possible issues related to "Apply Discount On Prices" setting.
12+
*
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"
16+
*/
17+
class ApplyDiscountOnPrices implements \Magento\Tax\Model\System\Message\NotificationInterface
18+
{
19+
/**
20+
* @var \Magento\Store\Model\StoreManagerInterface
21+
*/
22+
private $storeManager;
23+
24+
/**
25+
* @var \Magento\Framework\UrlInterface
26+
*/
27+
private $urlBuilder;
28+
29+
/**
30+
* @var Config
31+
*/
32+
private $taxConfig;
33+
34+
/**
35+
* Stores with invalid display settings
36+
*
37+
* @var array
38+
*/
39+
private $storesWithInvalidSettings;
40+
41+
/**
42+
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
43+
* @param \Magento\Framework\UrlInterface $urlBuilder
44+
* @param Config $taxConfig
45+
*/
46+
public function __construct(
47+
\Magento\Store\Model\StoreManagerInterface $storeManager,
48+
\Magento\Framework\UrlInterface $urlBuilder,
49+
Config $taxConfig
50+
) {
51+
$this->storeManager = $storeManager;
52+
$this->urlBuilder = $urlBuilder;
53+
$this->taxConfig = $taxConfig;
54+
}
55+
56+
/**
57+
* {@inheritdoc}
58+
* @codeCoverageIgnore
59+
*/
60+
public function getIdentity()
61+
{
62+
return 'TAX_NOTIFICATION_APPLY_DISCOUNT';
63+
}
64+
65+
/**
66+
* {@inheritdoc}
67+
*/
68+
public function isDisplayed()
69+
{
70+
if (!$this->taxConfig->isWrongApplyDiscountSettingIgnored() && $this->getStoresWithWrongSettings()) {
71+
return true;
72+
}
73+
return false;
74+
}
75+
76+
/**
77+
* {@inheritdoc}
78+
*/
79+
public function getText()
80+
{
81+
$messageDetails = '';
82+
83+
if ($this->isDisplayed()) {
84+
$messageDetails .= '<strong>';
85+
$messageDetails .= __('To apply the discount on prices including tax and apply the tax after discount, set Catalog Prices to “Including Tax”. ');
86+
$messageDetails .= '</strong><p>';
87+
$messageDetails .= __('Store(s) affected: ');
88+
$messageDetails .= implode(', ', $this->getStoresWithWrongSettings());
89+
$messageDetails .= '</p><p>';
90+
$messageDetails .= __(
91+
'Click on the link to <a href="%1">ignore this notification</a>',
92+
$this->urlBuilder->getUrl('tax/tax/ignoreTaxNotification', ['section' => 'apply_discount'])
93+
);
94+
$messageDetails .= "</p>";
95+
}
96+
97+
return $messageDetails;
98+
}
99+
100+
/**
101+
* {@inheritdoc}
102+
* @codeCoverageIgnore
103+
*/
104+
public function getSeverity()
105+
{
106+
return self::SEVERITY_CRITICAL;
107+
}
108+
109+
/**
110+
* Return list of store names which have invalid settings.
111+
*
112+
* @return array
113+
*/
114+
private function getStoresWithWrongSettings()
115+
{
116+
if (null !== $this->storesWithInvalidSettings) {
117+
return $this->storesWithInvalidSettings;
118+
}
119+
$this->storesWithInvalidSettings = [];
120+
$storeCollection = $this->storeManager->getStores(true);
121+
foreach ($storeCollection as $store) {
122+
if (!$this->checkSettings($store)) {
123+
$website = $store->getWebsite();
124+
$this->storesWithInvalidSettings[] = $website->getName() . ' (' . $store->getName() . ')';
125+
}
126+
}
127+
return $this->storesWithInvalidSettings;
128+
}
129+
130+
/**
131+
* Check if settings are valid.
132+
*
133+
* @param null|int|bool|string|\Magento\Store\Model\Store $store $store
134+
* @return bool false if settings are incorrect
135+
*/
136+
private function checkSettings($store = null)
137+
{
138+
return $this->taxConfig->priceIncludesTax($store)
139+
|| !$this->taxConfig->applyTaxAfterDiscount($store)
140+
|| !$this->taxConfig->discountTax($store);
141+
}
142+
}

0 commit comments

Comments
 (0)