WeeeConfigProvider.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Weee\Model;
  7. use Magento\Checkout\Model\ConfigProviderInterface;
  8. use Magento\Store\Model\StoreManagerInterface;
  9. use Magento\Weee\Helper\Data as WeeeHelper;
  10. use Magento\Weee\Model\Tax as WeeeDisplayConfig;
  11. class WeeeConfigProvider implements ConfigProviderInterface
  12. {
  13. /**
  14. * @var \Magento\Weee\Helper\Data
  15. */
  16. protected $weeeHelper;
  17. /**
  18. * @var StoreManagerInterface
  19. */
  20. protected $storeManager;
  21. /**
  22. * @var Config
  23. */
  24. protected $weeeConfig;
  25. /**
  26. * @param WeeeHelper $weeeHelper
  27. * @param StoreManagerInterface $storeManager
  28. * @param Config $weeeConfig
  29. */
  30. public function __construct(
  31. WeeeHelper $weeeHelper,
  32. StoreManagerInterface $storeManager,
  33. Config $weeeConfig
  34. ) {
  35. $this->weeeHelper = $weeeHelper;
  36. $this->storeManager = $storeManager;
  37. $this->weeeConfig = $weeeConfig;
  38. }
  39. /**
  40. * {@inheritdoc}
  41. */
  42. public function getConfig()
  43. {
  44. return [
  45. 'isDisplayPriceWithWeeeDetails' => $this->iDisplayPriceWithWeeeDetails(),
  46. 'isDisplayFinalPrice' => $this->isDisplayFinalPrice(),
  47. 'isWeeeEnabled' => $this->isWeeeEnabled(),
  48. 'isIncludedInSubtotal' => $this->isIncludedInSubtotal(),
  49. 'getIncludeWeeeFlag' => $this->getIncludeWeeeFlag()
  50. ];
  51. }
  52. /**
  53. * @return int
  54. */
  55. private function getStoreId()
  56. {
  57. return $this->storeManager->getStore()->getId();
  58. }
  59. /**
  60. * Whether to display weee details together with price
  61. *
  62. * @return bool
  63. */
  64. public function iDisplayPriceWithWeeeDetails()
  65. {
  66. if (!$this->weeeHelper->isEnabled($this->getStoreId())) {
  67. return false;
  68. }
  69. $displayWeeeDetails = $this->weeeHelper->typeOfDisplay(
  70. [WeeeDisplayConfig::DISPLAY_INCL_DESCR, WeeeDisplayConfig::DISPLAY_EXCL_DESCR_INCL],
  71. 'cart',
  72. $this->storeManager->getStore()->getId()
  73. );
  74. if (!$displayWeeeDetails) {
  75. return false;
  76. }
  77. return true;
  78. }
  79. /**
  80. * Whether to display final price that include Weee amounts
  81. *
  82. * @return bool
  83. */
  84. public function isDisplayFinalPrice()
  85. {
  86. $flag = $this->weeeHelper->typeOfDisplay(
  87. WeeeDisplayConfig::DISPLAY_EXCL_DESCR_INCL,
  88. 'cart',
  89. $this->storeManager->getStore()->getId()
  90. );
  91. if (!$flag) {
  92. return false;
  93. }
  94. return true;
  95. }
  96. /**
  97. * Check if fixed taxes are used in system
  98. *
  99. * @return bool
  100. */
  101. public function isWeeeEnabled()
  102. {
  103. return $this->weeeHelper->isEnabled($this->storeManager->getStore()->getId());
  104. }
  105. /**
  106. * Return the flag whether to include weee in the price
  107. *
  108. * @return bool|int
  109. */
  110. public function getIncludeWeeeFlag()
  111. {
  112. $includeWeee = $this->weeeHelper->typeOfDisplay(
  113. [WeeeDisplayConfig::DISPLAY_INCL_DESCR, WeeeDisplayConfig::DISPLAY_INCL],
  114. 'cart',
  115. $this->getStoreId()
  116. );
  117. return $includeWeee;
  118. }
  119. /**
  120. * Display FPT row in subtotal or not
  121. *
  122. * @return bool
  123. */
  124. public function isIncludedInSubtotal()
  125. {
  126. return $this->weeeConfig->isEnabled() && $this->weeeConfig->includeInSubtotal();
  127. }
  128. }