Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
RoundingErrors.php
Go to the documentation of this file.
1 <?php
7 
14 {
18  private $storeManager;
19 
23  private $urlBuilder;
24 
28  private $taxConfig;
29 
35  private $storesWithInvalidSettings;
36 
42  public function __construct(
43  \Magento\Store\Model\StoreManagerInterface $storeManager,
44  \Magento\Framework\UrlInterface $urlBuilder,
45  \Magento\Tax\Model\Config $taxConfig
46  ) {
47  $this->storeManager = $storeManager;
48  $this->urlBuilder = $urlBuilder;
49  $this->taxConfig = $taxConfig;
50  }
51 
56  public function getIdentity()
57  {
58  return 'TAX_NOTIFICATION_ROUNDING_ERRORS';
59  }
60 
64  public function isDisplayed()
65  {
66  if (!$this->taxConfig->isWrongDisplaySettingsIgnored() && $this->getStoresWithWrongSettings()) {
67  return true;
68  }
69  return false;
70  }
71 
75  public function getText()
76  {
77  $messageDetails = '';
78 
79  if (!empty($this->getStoresWithWrongSettings()) && !$this->taxConfig->isWrongDisplaySettingsIgnored()) {
80  $messageDetails .= '<strong>';
81  $messageDetails .= __('Your current tax configuration may result in rounding errors. ');
82  $messageDetails .= '</strong><p>';
83  $messageDetails .= __('Store(s) affected: ');
84  $messageDetails .= implode(', ', $this->getStoresWithWrongSettings());
85  $messageDetails .= '</p><p>';
86  $messageDetails .= __(
87  'Click on the link to <a href="%1">ignore this notification</a>',
88  $this->urlBuilder->getUrl('tax/tax/ignoreTaxNotification', ['section' => 'price_display'])
89  );
90  $messageDetails .= "</p>";
91  }
92 
93  return $messageDetails;
94  }
95 
100  public function getSeverity()
101  {
103  }
104 
115  private function checkSettings($store = null)
116  {
117  if ($this->taxConfig->getAlgorithm($store) == \Magento\Tax\Model\Calculation::CALC_UNIT_BASE) {
118  return true;
119  }
120  return $this->taxConfig->getPriceDisplayType($store) != \Magento\Tax\Model\Config::DISPLAY_TYPE_BOTH
121  && $this->taxConfig->getShippingPriceDisplayType($store) != \Magento\Tax\Model\Config::DISPLAY_TYPE_BOTH
122  && !$this->taxConfig->displayCartPricesBoth($store)
123  && !$this->taxConfig->displayCartSubtotalBoth($store)
124  && !$this->taxConfig->displayCartShippingBoth($store)
125  && !$this->taxConfig->displaySalesPricesBoth($store)
126  && !$this->taxConfig->displaySalesSubtotalBoth($store)
127  && !$this->taxConfig->displaySalesShippingBoth($store);
128  }
129 
136  private function getStoresWithWrongSettings()
137  {
138  if (null !== $this->storesWithInvalidSettings) {
139  return $this->storesWithInvalidSettings;
140  }
141  $this->storesWithInvalidSettings = [];
142  $storeCollection = $this->storeManager->getStores(true);
143  foreach ($storeCollection as $store) {
144  if (!$this->checkSettings($store)) {
145  $website = $store->getWebsite();
146  $this->storesWithInvalidSettings[] = $website->getName() . ' (' . $store->getName() . ')';
147  }
148  }
149  return $this->storesWithInvalidSettings;
150  }
151 }
$storeManager
__()
Definition: __.php:13
__construct(\Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\UrlInterface $urlBuilder, \Magento\Tax\Model\Config $taxConfig)