123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Tax\Model\System\Message;
- /**
- * Notifications class
- */
- class Notifications implements \Magento\Framework\Notification\MessageInterface
- {
- /**
- * Store manager object
- *
- * @var \Magento\Store\Model\StoreManagerInterface
- * @deprecated 100.1.0
- */
- protected $storeManager;
- /**
- * @var \Magento\Framework\UrlInterface
- */
- protected $urlBuilder;
- /**
- * Tax configuration object
- *
- * @var \Magento\Tax\Model\Config
- */
- protected $taxConfig;
- /**
- * Stores with invalid display settings
- *
- * @var array
- * @deprecated 100.1.0
- * @see \Magento\Tax\Model\System\Message\Notification\RoundingErrors
- */
- protected $storesWithInvalidDisplaySettings;
- /**
- * Websites with invalid discount settings
- *
- * @var array
- * @deprecated 100.1.0
- * @see \Magento\Tax\Model\System\Message\Notification\DiscountErrors
- */
- protected $storesWithInvalidDiscountSettings;
- /**
- * @var NotificationInterface[]
- */
- private $notifications = [];
- /**
- * @param \Magento\Store\Model\StoreManagerInterface $storeManager
- * @param \Magento\Framework\UrlInterface $urlBuilder
- * @param \Magento\Tax\Model\Config $taxConfig
- * @param NotificationInterface[] $notifications
- */
- public function __construct(
- \Magento\Store\Model\StoreManagerInterface $storeManager,
- \Magento\Framework\UrlInterface $urlBuilder,
- \Magento\Tax\Model\Config $taxConfig,
- $notifications = []
- ) {
- $this->storeManager = $storeManager;
- $this->urlBuilder = $urlBuilder;
- $this->taxConfig = $taxConfig;
- $this->notifications = $notifications;
- }
- /**
- * Retrieve unique message identity
- *
- * @return string
- * @codeCoverageIgnore
- */
- public function getIdentity()
- {
- return md5('TAX_NOTIFICATION');
- }
- /**
- * {@inheritdoc}
- */
- public function isDisplayed()
- {
- foreach ($this->notifications as $notification) {
- if ($notification->isDisplayed()) {
- return true;
- }
- }
- return false;
- }
- /**
- * {@inheritdoc}
- */
- public function getText()
- {
- $messageDetails = '';
- foreach ($this->notifications as $notification) {
- $messageDetails .= $notification->getText();
- }
- $messageDetails .= '<p>';
- $messageDetails .= __('Please see <a href="%1">documentation</a> for more details. ', $this->getInfoUrl());
- $messageDetails .= __(
- 'Click here to go to <a href="%1">Tax Configuration</a> and change your settings.',
- $this->getManageUrl()
- );
- $messageDetails .= '</p>';
- return $messageDetails;
- }
- /**
- * Retrieve message severity
- *
- * @return int
- * @codeCoverageIgnore
- */
- public function getSeverity()
- {
- return self::SEVERITY_CRITICAL;
- }
- /**
- * Get URL for the tax notification documentation
- *
- * @return string
- */
- public function getInfoUrl()
- {
- return $this->taxConfig->getInfoUrl();
- }
- /**
- * Get URL to the admin tax configuration page
- *
- * @return string
- */
- public function getManageUrl()
- {
- return $this->urlBuilder->getUrl('adminhtml/system_config/edit/section/tax');
- }
- /**
- * Check if tax calculation type and price display settings are compatible
- *
- * Invalid settings if
- * Tax Calculation Method Based On 'Total' or 'Row'
- * and at least one Price Display Settings has 'Including and Excluding Tax' value
- *
- * @param null|int|bool|string|\Magento\Store\Model\Store $store $store
- * @return bool
- * @deprecated 100.1.3
- * @see \Magento\Tax\Model\System\Message\Notification\RoundingErrors::checkSettings
- */
- public function checkDisplaySettings($store = null)
- {
- if ($this->taxConfig->getAlgorithm($store) == \Magento\Tax\Model\Calculation::CALC_UNIT_BASE) {
- return true;
- }
- return $this->taxConfig->getPriceDisplayType($store) != \Magento\Tax\Model\Config::DISPLAY_TYPE_BOTH
- && $this->taxConfig->getShippingPriceDisplayType($store) != \Magento\Tax\Model\Config::DISPLAY_TYPE_BOTH
- && !$this->taxConfig->displayCartPricesBoth($store)
- && !$this->taxConfig->displayCartSubtotalBoth($store)
- && !$this->taxConfig->displayCartShippingBoth($store)
- && !$this->taxConfig->displaySalesPricesBoth($store)
- && !$this->taxConfig->displaySalesSubtotalBoth($store)
- && !$this->taxConfig->displaySalesShippingBoth($store);
- }
- /**
- * Check if tax discount settings are compatible
- *
- * Matrix for invalid discount settings is as follows:
- * Before Discount / Excluding Tax
- * Before Discount / Including Tax
- *
- * @param null|int|bool|string|\Magento\Store\Model\Store $store $store
- * @return bool
- * @deprecated 100.1.3
- * @see \Magento\Tax\Model\System\Message\Notification\DiscountErrors::checkSettings
- */
- public function checkDiscountSettings($store = null)
- {
- return $this->taxConfig->applyTaxAfterDiscount($store);
- }
- /**
- * Get URL to ignore tax notifications
- *
- * @param string $section
- * @return string
- * @deprecated 100.1.3
- */
- public function getIgnoreTaxNotificationUrl($section)
- {
- return $this->urlBuilder->getUrl('tax/tax/ignoreTaxNotification', ['section' => $section]);
- }
- /**
- * Return list of store names which have not compatible tax calculation type and price display settings.
- * Return true if settings are wrong for default store.
- *
- * @return array
- * @deprecated 100.1.3
- * @see \Magento\Tax\Model\System\Message\Notification\RoundingErrors::getStoresWithWrongSettings
- */
- public function getStoresWithWrongDisplaySettings()
- {
- $storeNames = [];
- $storeCollection = $this->storeManager->getStores(true);
- foreach ($storeCollection as $store) {
- if (!$this->checkDisplaySettings($store)) {
- $website = $store->getWebsite();
- $storeNames[] = $website->getName() . '(' . $store->getName() . ')';
- }
- }
- return $storeNames;
- }
- /**
- * Return list of store names where tax discount settings are compatible.
- * Return true if settings are wrong for default store.
- *
- * @return array
- * @deprecated 100.1.3
- * @see \Magento\Tax\Model\System\Message\Notification\DiscountErrors::getStoresWithWrongSettings
- */
- public function getStoresWithWrongDiscountSettings()
- {
- $storeNames = [];
- $storeCollection = $this->storeManager->getStores(true);
- foreach ($storeCollection as $store) {
- if (!$this->checkDiscountSettings($store)) {
- $website = $store->getWebsite();
- $storeNames[] = $website->getName() . '(' . $store->getName() . ')';
- }
- }
- return $storeNames;
- }
- }
|