Shipping.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. use Magento\Framework\Pricing\PriceCurrencyInterface;
  8. use Magento\Quote\Model\Quote\Address;
  9. /**
  10. * Mustishipping checkout shipping
  11. *
  12. * @api
  13. * @author Magento Core Team <core@magentocommerce.com>
  14. * @since 100.0.2
  15. */
  16. class Shipping extends \Magento\Sales\Block\Items\AbstractItems
  17. {
  18. /**
  19. * @var \Magento\Framework\Filter\DataObject\GridFactory
  20. */
  21. protected $_filterGridFactory;
  22. /**
  23. * @var \Magento\Tax\Helper\Data
  24. */
  25. protected $_taxHelper;
  26. /**
  27. * @var PriceCurrencyInterface
  28. */
  29. protected $priceCurrency;
  30. /**
  31. * @param \Magento\Framework\View\Element\Template\Context $context
  32. * @param \Magento\Framework\Filter\DataObject\GridFactory $filterGridFactory
  33. * @param \Magento\Multishipping\Model\Checkout\Type\Multishipping $multishipping
  34. * @param \Magento\Tax\Helper\Data $taxHelper
  35. * @param PriceCurrencyInterface $priceCurrency
  36. * @param array $data
  37. */
  38. public function __construct(
  39. \Magento\Framework\View\Element\Template\Context $context,
  40. \Magento\Framework\Filter\DataObject\GridFactory $filterGridFactory,
  41. \Magento\Multishipping\Model\Checkout\Type\Multishipping $multishipping,
  42. \Magento\Tax\Helper\Data $taxHelper,
  43. PriceCurrencyInterface $priceCurrency,
  44. array $data = []
  45. ) {
  46. $this->priceCurrency = $priceCurrency;
  47. $this->_taxHelper = $taxHelper;
  48. $this->_filterGridFactory = $filterGridFactory;
  49. $this->_multishipping = $multishipping;
  50. parent::__construct($context, $data);
  51. $this->_isScopePrivate = true;
  52. }
  53. /**
  54. * Get multishipping checkout model
  55. *
  56. * @return \Magento\Multishipping\Model\Checkout\Type\Multishipping
  57. */
  58. public function getCheckout()
  59. {
  60. return $this->_multishipping;
  61. }
  62. /**
  63. * @return $this
  64. */
  65. protected function _prepareLayout()
  66. {
  67. $this->pageConfig->getTitle()->set(
  68. __('Shipping Methods') . ' - ' . $this->pageConfig->getTitle()->getDefault()
  69. );
  70. return parent::_prepareLayout();
  71. }
  72. /**
  73. * @return Address[]
  74. */
  75. public function getAddresses()
  76. {
  77. return $this->getCheckout()->getQuote()->getAllShippingAddresses();
  78. }
  79. /**
  80. * @return mixed
  81. */
  82. public function getAddressCount()
  83. {
  84. $count = $this->getData('address_count');
  85. if ($count === null) {
  86. $count = count($this->getAddresses());
  87. $this->setData('address_count', $count);
  88. }
  89. return $count;
  90. }
  91. /**
  92. * @param Address $address
  93. * @return \Magento\Framework\DataObject[]
  94. */
  95. public function getAddressItems($address)
  96. {
  97. $items = [];
  98. foreach ($address->getAllItems() as $item) {
  99. if ($item->getParentItemId()) {
  100. continue;
  101. }
  102. $item->setQuoteItem($this->getCheckout()->getQuote()->getItemById($item->getQuoteItemId()));
  103. $items[] = $item;
  104. }
  105. $itemsFilter = $this->_filterGridFactory->create();
  106. $itemsFilter->addFilter(new \Magento\Framework\Filter\Sprintf('%d'), 'qty');
  107. return $itemsFilter->filter($items);
  108. }
  109. /**
  110. * @param Address $address
  111. * @return mixed
  112. */
  113. public function getAddressShippingMethod($address)
  114. {
  115. return $address->getShippingMethod();
  116. }
  117. /**
  118. * @param Address $address
  119. * @return mixed
  120. */
  121. public function getShippingRates($address)
  122. {
  123. $groups = $address->getGroupedAllShippingRates();
  124. return $groups;
  125. }
  126. /**
  127. * @param string $carrierCode
  128. * @return string
  129. */
  130. public function getCarrierName($carrierCode)
  131. {
  132. if ($name = $this->_scopeConfig->getValue(
  133. 'carriers/' . $carrierCode . '/title',
  134. \Magento\Store\Model\ScopeInterface::SCOPE_STORE
  135. )
  136. ) {
  137. return $name;
  138. }
  139. return $carrierCode;
  140. }
  141. /**
  142. * @param Address $address
  143. * @return string
  144. */
  145. public function getAddressEditUrl($address)
  146. {
  147. return $this->getUrl('*/checkout_address/editShipping', ['id' => $address->getCustomerAddressId()]);
  148. }
  149. /**
  150. * @return string
  151. */
  152. public function getItemsEditUrl()
  153. {
  154. return $this->getUrl('*/*/backToAddresses');
  155. }
  156. /**
  157. * @return string
  158. */
  159. public function getPostActionUrl()
  160. {
  161. return $this->getUrl('*/*/shippingPost');
  162. }
  163. /**
  164. * @return string
  165. */
  166. public function getBackUrl()
  167. {
  168. return $this->getUrl('*/*/backtoaddresses');
  169. }
  170. /**
  171. * @param Address $address
  172. * @param float $price
  173. * @param bool $flag
  174. * @return float
  175. */
  176. public function getShippingPrice($address, $price, $flag)
  177. {
  178. return $this->priceCurrency->convertAndFormat(
  179. $this->_taxHelper->getShippingPrice($price, $flag, $address),
  180. true,
  181. PriceCurrencyInterface::DEFAULT_PRECISION,
  182. $address->getQuote()->getStore()
  183. );
  184. }
  185. /**
  186. * Retrieve text for items box
  187. *
  188. * @param \Magento\Framework\DataObject $addressEntity
  189. * @return string
  190. *
  191. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  192. */
  193. public function getItemsBoxTextAfter(\Magento\Framework\DataObject $addressEntity)
  194. {
  195. return '';
  196. }
  197. }