Billing.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Multishipping\Block\Checkout;
  7. /**
  8. * Multishipping billing information
  9. *
  10. * @api
  11. * @author Magento Core Team <core@magentocommerce.com>
  12. * @since 100.0.2
  13. */
  14. class Billing extends \Magento\Payment\Block\Form\Container
  15. {
  16. /**
  17. * @var \Magento\Multishipping\Model\Checkout\Type\Multishipping
  18. */
  19. protected $_multishipping;
  20. /**
  21. * @var \Magento\Checkout\Model\Session
  22. */
  23. protected $_checkoutSession;
  24. /**
  25. * @var \Magento\Payment\Model\Method\SpecificationInterface
  26. */
  27. protected $paymentSpecification;
  28. /**
  29. * @param \Magento\Framework\View\Element\Template\Context $context
  30. * @param \Magento\Payment\Helper\Data $paymentHelper
  31. * @param \Magento\Payment\Model\Checks\SpecificationFactory $methodSpecificationFactory
  32. * @param \Magento\Multishipping\Model\Checkout\Type\Multishipping $multishipping
  33. * @param \Magento\Checkout\Model\Session $checkoutSession
  34. * @param \Magento\Payment\Model\Method\SpecificationInterface $paymentSpecification
  35. * @param array $data
  36. * @param array $additionalChecks
  37. */
  38. public function __construct(
  39. \Magento\Framework\View\Element\Template\Context $context,
  40. \Magento\Payment\Helper\Data $paymentHelper,
  41. \Magento\Payment\Model\Checks\SpecificationFactory $methodSpecificationFactory,
  42. \Magento\Multishipping\Model\Checkout\Type\Multishipping $multishipping,
  43. \Magento\Checkout\Model\Session $checkoutSession,
  44. \Magento\Payment\Model\Method\SpecificationInterface $paymentSpecification,
  45. array $data = [],
  46. array $additionalChecks = []
  47. ) {
  48. $this->_multishipping = $multishipping;
  49. $this->_checkoutSession = $checkoutSession;
  50. $this->paymentSpecification = $paymentSpecification;
  51. parent::__construct($context, $paymentHelper, $methodSpecificationFactory, $data, $additionalChecks);
  52. $this->_isScopePrivate = true;
  53. }
  54. /**
  55. * Prepare children blocks
  56. *
  57. * @return $this
  58. */
  59. protected function _prepareLayout()
  60. {
  61. $this->pageConfig->getTitle()->set(
  62. __('Billing Information - %1', $this->pageConfig->getTitle()->getDefault())
  63. );
  64. return parent::_prepareLayout();
  65. }
  66. /**
  67. * Check payment method model
  68. *
  69. * @param \Magento\Payment\Model\Method\AbstractMethod|null $method
  70. * @return bool
  71. */
  72. protected function _canUseMethod($method)
  73. {
  74. return $method && $this->paymentSpecification->isSatisfiedBy(
  75. $method->getCode()
  76. ) && parent::_canUseMethod(
  77. $method
  78. );
  79. }
  80. /**
  81. * Retrieve code of current payment method
  82. *
  83. * @return mixed
  84. */
  85. public function getSelectedMethodCode()
  86. {
  87. $method = $this->getQuote()->getPayment()->getMethod();
  88. if ($method) {
  89. return $method;
  90. }
  91. return false;
  92. }
  93. /**
  94. * Retrieve billing address
  95. *
  96. * @return \Magento\Quote\Model\Quote\Address
  97. */
  98. public function getAddress()
  99. {
  100. $address = $this->getData('address');
  101. if ($address === null) {
  102. $address = $this->_multishipping->getQuote()->getBillingAddress();
  103. $this->setData('address', $address);
  104. }
  105. return $address;
  106. }
  107. /**
  108. * Retrieve quote model object
  109. *
  110. * @return \Magento\Quote\Model\Quote
  111. */
  112. public function getQuote()
  113. {
  114. return $this->_checkoutSession->getQuote();
  115. }
  116. /**
  117. * Getter
  118. *
  119. * @return float
  120. */
  121. public function getQuoteBaseGrandTotal()
  122. {
  123. return (double)$this->getQuote()->getBaseGrandTotal();
  124. }
  125. /**
  126. * Retrieve url for select billing address
  127. *
  128. * @return string
  129. */
  130. public function getSelectAddressUrl()
  131. {
  132. return $this->getUrl('*/checkout_address/selectBilling');
  133. }
  134. /**
  135. * Retrieve data post destination url
  136. *
  137. * @return string
  138. */
  139. public function getPostActionUrl()
  140. {
  141. return $this->getUrl('*/*/overview');
  142. }
  143. /**
  144. * Retrieve back url
  145. *
  146. * @return string
  147. */
  148. public function getBackUrl()
  149. {
  150. return $this->getUrl('*/*/backtoshipping');
  151. }
  152. }