Skip to content

Commit

Permalink
Merge pull request #762 from magento-okapis/MAGETWO-61120-Tax-Configu…
Browse files Browse the repository at this point in the history
…ration

Fixed issues:
 - MAGETWO-61120: Tax and Order total not correct when discount is applied
  • Loading branch information
Oleksii Korshenko committed Jan 26, 2017
2 parents 47c3696 + 67c3f20 commit 02e1c6b
Show file tree
Hide file tree
Showing 14 changed files with 1,099 additions and 123 deletions.
29 changes: 29 additions & 0 deletions app/code/Magento/Tax/Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class Config

const XML_PATH_TAX_NOTIFICATION_IGNORE_PRICE_DISPLAY = 'tax/notification/ignore_price_display';

const XML_PATH_TAX_NOTIFICATION_IGNORE_APPLY_DISCOUNT = 'tax/notification/ignore_apply_discount';

const XML_PATH_TAX_NOTIFICATION_INFO_URL = 'tax/notification/info_url';

// tax classes
Expand Down Expand Up @@ -68,6 +70,7 @@ class Config

const XML_PATH_DISPLAY_CART_SHIPPING = 'tax/cart_display/shipping';

/** @deprecated */
const XML_PATH_DISPLAY_CART_DISCOUNT = 'tax/cart_display/discount';

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

const XML_PATH_DISPLAY_SALES_SHIPPING = 'tax/sales_display/shipping';

/** @deprecated */
const XML_PATH_DISPLAY_SALES_DISCOUNT = 'tax/sales_display/discount';

const XML_PATH_DISPLAY_SALES_GRANDTOTAL = 'tax/sales_display/grandtotal';
Expand Down Expand Up @@ -468,6 +472,7 @@ public function displayCartShippingBoth($store = null)
/**
* @param null|string|bool|int|Store $store
* @return bool
* @deprecated
*/
public function displayCartDiscountInclTax($store = null)
{
Expand All @@ -481,6 +486,7 @@ public function displayCartDiscountInclTax($store = null)
/**
* @param null|string|bool|int|Store $store
* @return bool
* @deprecated
*/
public function displayCartDiscountExclTax($store = null)
{
Expand All @@ -494,6 +500,7 @@ public function displayCartDiscountExclTax($store = null)
/**
* @param null|string|bool|int|Store $store
* @return bool
* @deprecated
*/
public function displayCartDiscountBoth($store = null)
{
Expand Down Expand Up @@ -663,6 +670,7 @@ public function displaySalesShippingBoth($store = null)
/**
* @param null|string|bool|int|Store $store
* @return bool
* @deprecated
*/
public function displaySalesDiscountInclTax($store = null)
{
Expand All @@ -676,6 +684,7 @@ public function displaySalesDiscountInclTax($store = null)
/**
* @param null|string|bool|int|Store $store
* @return bool
* @deprecated
*/
public function displaySalesDiscountExclTax($store = null)
{
Expand All @@ -689,6 +698,7 @@ public function displaySalesDiscountExclTax($store = null)
/**
* @param null|string|bool|int|Store $store
* @return bool
* @deprecated
*/
public function displaySalesDiscountBoth($store = null)
{
Expand Down Expand Up @@ -753,6 +763,25 @@ public function crossBorderTradeEnabled($store = null)
);
}

/**
* Check if admin notification related to misconfiguration of "Apply Discount On Prices" should be ignored.
*
* Warning is displayed in case when "Catalog Prices" = "Excluding Tax"
* AND "Apply Discount On Prices" = "Including Tax"
* AND "Apply Customer Tax" = "After Discount"
*
* @param null|string|Store $store
* @return bool
*/
public function isWrongApplyDiscountSettingIgnored($store = null)
{
return (bool)$this->_scopeConfig->getValue(
self::XML_PATH_TAX_NOTIFICATION_IGNORE_APPLY_DISCOUNT,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
$store
);
}

/**
* Check if do not show notification about wrong display settings
*
Expand Down
6 changes: 4 additions & 2 deletions app/code/Magento/Tax/Model/Config/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace Magento\Tax\Model\Config;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Tax\Model\Config;

/**
* Tax Config Notification
Expand Down Expand Up @@ -49,8 +50,9 @@ public function __construct(
public function afterSave()
{
if ($this->isValueChanged()) {
$this->_resetNotificationFlag(\Magento\Tax\Model\Config::XML_PATH_TAX_NOTIFICATION_IGNORE_DISCOUNT);
$this->_resetNotificationFlag(\Magento\Tax\Model\Config::XML_PATH_TAX_NOTIFICATION_IGNORE_PRICE_DISPLAY);
$this->_resetNotificationFlag(Config::XML_PATH_TAX_NOTIFICATION_IGNORE_DISCOUNT);
$this->_resetNotificationFlag(Config::XML_PATH_TAX_NOTIFICATION_IGNORE_PRICE_DISPLAY);
$this->_resetNotificationFlag(Config::XML_PATH_TAX_NOTIFICATION_IGNORE_APPLY_DISCOUNT);
}
return parent::afterSave();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
<?php
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Tax\Model\System\Message\Notification;

use Magento\Tax\Model\Config;

/**
* Class allows to show admin notification about possible issues related to "Apply Discount On Prices" setting.
*
* Warning is displayed in case when "Catalog Prices" = "Excluding Tax"
* AND "Apply Discount On Prices" = "Including Tax"
* AND "Apply Customer Tax" = "After Discount"
*/
class ApplyDiscountOnPrices implements \Magento\Tax\Model\System\Message\NotificationInterface
{
/**
* @var \Magento\Store\Model\StoreManagerInterface
*/
private $storeManager;

/**
* @var \Magento\Framework\UrlInterface
*/
private $urlBuilder;

/**
* @var Config
*/
private $taxConfig;

/**
* Stores with invalid display settings
*
* @var array
*/
private $storesWithInvalidSettings;

/**
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Framework\UrlInterface $urlBuilder
* @param Config $taxConfig
*/
public function __construct(
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Framework\UrlInterface $urlBuilder,
Config $taxConfig
) {
$this->storeManager = $storeManager;
$this->urlBuilder = $urlBuilder;
$this->taxConfig = $taxConfig;
}

/**
* {@inheritdoc}
* @codeCoverageIgnore
*/
public function getIdentity()
{
return 'TAX_NOTIFICATION_APPLY_DISCOUNT';
}

/**
* {@inheritdoc}
*/
public function isDisplayed()
{
if (!$this->taxConfig->isWrongApplyDiscountSettingIgnored() && $this->getStoresWithWrongSettings()) {
return true;
}
return false;
}

/**
* {@inheritdoc}
*/
public function getText()
{
$messageDetails = '';

if ($this->isDisplayed()) {
$messageDetails .= '<strong>';
$messageDetails .= __('To apply the discount on prices including tax and apply the tax after discount, set Catalog Prices to “Including Tax”. ');
$messageDetails .= '</strong><p>';
$messageDetails .= __('Store(s) affected: ');
$messageDetails .= implode(', ', $this->getStoresWithWrongSettings());
$messageDetails .= '</p><p>';
$messageDetails .= __(
'Click on the link to <a href="%1">ignore this notification</a>',
$this->urlBuilder->getUrl('tax/tax/ignoreTaxNotification', ['section' => 'apply_discount'])
);
$messageDetails .= "</p>";
}

return $messageDetails;
}

/**
* {@inheritdoc}
* @codeCoverageIgnore
*/
public function getSeverity()
{
return self::SEVERITY_CRITICAL;
}

/**
* Return list of store names which have invalid settings.
*
* @return array
*/
private function getStoresWithWrongSettings()
{
if (null !== $this->storesWithInvalidSettings) {
return $this->storesWithInvalidSettings;
}
$this->storesWithInvalidSettings = [];
$storeCollection = $this->storeManager->getStores(true);
foreach ($storeCollection as $store) {
if (!$this->checkSettings($store)) {
$website = $store->getWebsite();
$this->storesWithInvalidSettings[] = $website->getName() . ' (' . $store->getName() . ')';
}
}
return $this->storesWithInvalidSettings;
}

/**
* Check if settings are valid.
*
* @param null|int|bool|string|\Magento\Store\Model\Store $store $store
* @return bool false if settings are incorrect
*/
private function checkSettings($store = null)
{
return $this->taxConfig->priceIncludesTax($store)
|| !$this->taxConfig->applyTaxAfterDiscount($store)
|| !$this->taxConfig->discountTax($store);
}
}

0 comments on commit 02e1c6b

Please sign in to comment.