Shipping.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Tax\Block\Checkout;
  7. /**
  8. * Subtotal Total Row Renderer
  9. */
  10. class Shipping extends \Magento\Checkout\Block\Total\DefaultTotal
  11. {
  12. /**
  13. * Template path
  14. *
  15. * @var string
  16. */
  17. protected $_template = 'Magento_Tax::checkout/shipping.phtml';
  18. /**
  19. * @var \Magento\Tax\Model\Config
  20. */
  21. protected $_taxConfig;
  22. /**
  23. * @param \Magento\Framework\View\Element\Template\Context $context
  24. * @param \Magento\Customer\Model\Session $customerSession
  25. * @param \Magento\Checkout\Model\Session $checkoutSession
  26. * @param \Magento\Sales\Model\Config $salesConfig
  27. * @param \Magento\Tax\Model\Config $taxConfig
  28. * @param array $layoutProcessors
  29. * @param array $data
  30. */
  31. public function __construct(
  32. \Magento\Framework\View\Element\Template\Context $context,
  33. \Magento\Customer\Model\Session $customerSession,
  34. \Magento\Checkout\Model\Session $checkoutSession,
  35. \Magento\Sales\Model\Config $salesConfig,
  36. \Magento\Tax\Model\Config $taxConfig,
  37. array $layoutProcessors = [],
  38. array $data = []
  39. ) {
  40. $this->_taxConfig = $taxConfig;
  41. parent::__construct($context, $customerSession, $checkoutSession, $salesConfig, $layoutProcessors, $data);
  42. $this->_isScopePrivate = true;
  43. }
  44. /**
  45. * Check if we need display shipping include and exclude tax
  46. *
  47. * @return bool
  48. */
  49. public function displayBoth()
  50. {
  51. return $this->_taxConfig->displayCartShippingBoth($this->getStore());
  52. }
  53. /**
  54. * Check if we need display shipping include tax
  55. *
  56. * @return bool
  57. */
  58. public function displayIncludeTax()
  59. {
  60. return $this->_taxConfig->displayCartShippingInclTax($this->getStore());
  61. }
  62. /**
  63. * Get shipping amount include tax
  64. *
  65. * @return float
  66. */
  67. public function getShippingIncludeTax()
  68. {
  69. return $this->getTotal()->getShippingInclTax();
  70. }
  71. /**
  72. * Get shipping amount exclude tax
  73. *
  74. * @return float
  75. */
  76. public function getShippingExcludeTax()
  77. {
  78. return $this->getTotal()->getValue();
  79. }
  80. /**
  81. * Get label for shipping include tax
  82. *
  83. * @return \Magento\Framework\Phrase
  84. */
  85. public function getIncludeTaxLabel()
  86. {
  87. return __(
  88. 'Shipping Incl. Tax (%1)',
  89. $this->escapeHtml($this->getQuote()->getShippingAddress()->getShippingDescription())
  90. );
  91. }
  92. /**
  93. * Get label for shipping exclude tax
  94. *
  95. * @return \Magento\Framework\Phrase
  96. */
  97. public function getExcludeTaxLabel()
  98. {
  99. return __(
  100. 'Shipping Excl. Tax (%1)',
  101. $this->escapeHtml($this->getQuote()->getShippingAddress()->getShippingDescription())
  102. );
  103. }
  104. /**
  105. * Determine shipping visibility based on selected method.
  106. *
  107. * @return bool
  108. */
  109. public function displayShipping()
  110. {
  111. if (!$this->getQuote()->getShippingAddress()->getShippingMethod()) {
  112. return false;
  113. }
  114. return true;
  115. }
  116. }