Overview.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  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. * Multishipping checkout overview information
  11. *
  12. * @api
  13. * @author Magento Core Team <core@magentocommerce.com>
  14. * @since 100.0.2
  15. */
  16. class Overview extends \Magento\Sales\Block\Items\AbstractItems
  17. {
  18. /**
  19. * Block alias fallback
  20. */
  21. const DEFAULT_TYPE = 'default';
  22. /**
  23. * @var \Magento\Multishipping\Model\Checkout\Type\Multishipping
  24. */
  25. protected $_multishipping;
  26. /**
  27. * @var \Magento\Tax\Helper\Data
  28. */
  29. protected $_taxHelper;
  30. /**
  31. * @var PriceCurrencyInterface
  32. */
  33. protected $priceCurrency;
  34. /**
  35. * @var \Magento\Quote\Model\Quote\TotalsCollector
  36. */
  37. protected $totalsCollector;
  38. /**
  39. * @var \Magento\Quote\Model\Quote\TotalsReader
  40. */
  41. protected $totalsReader;
  42. /**
  43. * @param \Magento\Framework\View\Element\Template\Context $context
  44. * @param \Magento\Multishipping\Model\Checkout\Type\Multishipping $multishipping
  45. * @param \Magento\Tax\Helper\Data $taxHelper
  46. * @param PriceCurrencyInterface $priceCurrency
  47. * @param \Magento\Quote\Model\Quote\TotalsCollector $totalsCollector
  48. * @param \Magento\Quote\Model\Quote\TotalsReader $totalsReader
  49. * @param array $data
  50. */
  51. public function __construct(
  52. \Magento\Framework\View\Element\Template\Context $context,
  53. \Magento\Multishipping\Model\Checkout\Type\Multishipping $multishipping,
  54. \Magento\Tax\Helper\Data $taxHelper,
  55. PriceCurrencyInterface $priceCurrency,
  56. \Magento\Quote\Model\Quote\TotalsCollector $totalsCollector,
  57. \Magento\Quote\Model\Quote\TotalsReader $totalsReader,
  58. array $data = []
  59. ) {
  60. $this->_taxHelper = $taxHelper;
  61. $this->_multishipping = $multishipping;
  62. $this->priceCurrency = $priceCurrency;
  63. parent::__construct($context, $data);
  64. $this->_isScopePrivate = true;
  65. $this->totalsCollector = $totalsCollector;
  66. $this->totalsReader = $totalsReader;
  67. }
  68. /**
  69. * Initialize default item renderer
  70. *
  71. * @return $this
  72. */
  73. protected function _prepareLayout()
  74. {
  75. $this->pageConfig->getTitle()->set(
  76. __('Review Order - %1', $this->pageConfig->getTitle()->getDefault())
  77. );
  78. return parent::_prepareLayout();
  79. }
  80. /**
  81. * Get multishipping checkout model
  82. *
  83. * @return \Magento\Multishipping\Model\Checkout\Type\Multishipping
  84. */
  85. public function getCheckout()
  86. {
  87. return $this->_multishipping;
  88. }
  89. /**
  90. * @return Address
  91. */
  92. public function getBillingAddress()
  93. {
  94. return $this->getCheckout()->getQuote()->getBillingAddress();
  95. }
  96. /**
  97. * @return string
  98. */
  99. public function getPaymentHtml()
  100. {
  101. return $this->getChildHtml('payment_info');
  102. }
  103. /**
  104. * Get object with payment info posted data
  105. *
  106. * @return \Magento\Framework\DataObject
  107. */
  108. public function getPayment()
  109. {
  110. return $this->getCheckout()->getQuote()->getPayment();
  111. }
  112. /**
  113. * @return array
  114. */
  115. public function getShippingAddresses()
  116. {
  117. return $this->getCheckout()->getQuote()->getAllShippingAddresses();
  118. }
  119. /**
  120. * @return int|mixed
  121. */
  122. public function getShippingAddressCount()
  123. {
  124. $count = $this->getData('shipping_address_count');
  125. if ($count === null) {
  126. $count = count($this->getShippingAddresses());
  127. $this->setData('shipping_address_count', $count);
  128. }
  129. return $count;
  130. }
  131. /**
  132. * @param Address $address
  133. * @return bool
  134. * @SuppressWarnings(PHPMD.BooleanGetMethodName)
  135. */
  136. public function getShippingAddressRate($address)
  137. {
  138. $rate = $address->getShippingRateByCode($address->getShippingMethod());
  139. if ($rate) {
  140. return $rate;
  141. }
  142. return false;
  143. }
  144. /**
  145. * @param Address $address
  146. * @return mixed
  147. */
  148. public function getShippingPriceInclTax($address)
  149. {
  150. $exclTax = $address->getShippingAmount();
  151. $taxAmount = $address->getShippingTaxAmount();
  152. return $this->formatPrice($exclTax + $taxAmount);
  153. }
  154. /**
  155. * @param Address $address
  156. * @return mixed
  157. */
  158. public function getShippingPriceExclTax($address)
  159. {
  160. return $this->formatPrice($address->getShippingAmount());
  161. }
  162. /**
  163. * @param float $price
  164. * @return mixed
  165. *
  166. * @codeCoverageIgnore
  167. */
  168. public function formatPrice($price)
  169. {
  170. return $this->priceCurrency->format(
  171. $price,
  172. true,
  173. PriceCurrencyInterface::DEFAULT_PRECISION,
  174. $this->getQuote()->getStore()
  175. );
  176. }
  177. /**
  178. * @param Address $address
  179. * @return array
  180. */
  181. public function getShippingAddressItems($address): array
  182. {
  183. return $address->getAllVisibleItems();
  184. }
  185. /**
  186. * @param Address $address
  187. * @return mixed
  188. */
  189. public function getShippingAddressTotals($address)
  190. {
  191. $totals = $address->getTotals();
  192. foreach ($totals as $total) {
  193. if ($total->getCode() == 'grand_total') {
  194. if ($address->getAddressType() == Address::TYPE_BILLING) {
  195. $total->setTitle(__('Total'));
  196. } else {
  197. $total->setTitle(__('Total for this address'));
  198. }
  199. }
  200. }
  201. return $totals;
  202. }
  203. /**
  204. * @return float
  205. */
  206. public function getTotal()
  207. {
  208. return $this->getCheckout()->getQuote()->getGrandTotal();
  209. }
  210. /**
  211. * @return string
  212. */
  213. public function getAddressesEditUrl()
  214. {
  215. return $this->getUrl('*/*/backtoaddresses');
  216. }
  217. /**
  218. * @param Address $address
  219. * @return string
  220. */
  221. public function getEditShippingAddressUrl($address)
  222. {
  223. return $this->getUrl('*/checkout_address/editShipping', ['id' => $address->getCustomerAddressId()]);
  224. }
  225. /**
  226. * @param Address $address
  227. * @return string
  228. */
  229. public function getEditBillingAddressUrl($address)
  230. {
  231. return $this->getUrl('*/checkout_address/editBilling', ['id' => $address->getCustomerAddressId()]);
  232. }
  233. /**
  234. * @return string
  235. */
  236. public function getEditShippingUrl()
  237. {
  238. return $this->getUrl('*/*/backtoshipping');
  239. }
  240. /**
  241. * @return string
  242. */
  243. public function getPostActionUrl()
  244. {
  245. return $this->getUrl('*/*/overviewPost');
  246. }
  247. /**
  248. * @return string
  249. */
  250. public function getEditBillingUrl()
  251. {
  252. return $this->getUrl('*/*/backtobilling');
  253. }
  254. /**
  255. * @return string
  256. */
  257. public function getBackUrl()
  258. {
  259. return $this->getUrl('*/*/backtobilling');
  260. }
  261. /**
  262. * Retrieve virtual product edit url
  263. *
  264. * @return string
  265. */
  266. public function getVirtualProductEditUrl()
  267. {
  268. return $this->getUrl('checkout/cart');
  269. }
  270. /**
  271. * Retrieve virtual product collection array
  272. *
  273. * @return array
  274. */
  275. public function getVirtualItems()
  276. {
  277. return $this->getBillingAddress()->getAllVisibleItems();
  278. }
  279. /**
  280. * Retrieve quote
  281. *
  282. * @return \Magento\Quote\Model\Quote
  283. */
  284. public function getQuote()
  285. {
  286. return $this->getCheckout()->getQuote();
  287. }
  288. /**
  289. * @deprecated 100.2.3
  290. * typo in method name, see getBillingAddressTotals()
  291. * @return mixed
  292. */
  293. public function getBillinAddressTotals()
  294. {
  295. return $this->getBillingAddressTotals();
  296. }
  297. /**
  298. * @return mixed
  299. * @since 100.2.3
  300. */
  301. public function getBillingAddressTotals()
  302. {
  303. $address = $this->getQuote()->getBillingAddress();
  304. return $this->getShippingAddressTotals($address);
  305. }
  306. /**
  307. * @param mixed $totals
  308. * @param null $colspan
  309. * @return string
  310. */
  311. public function renderTotals($totals, $colspan = null)
  312. {
  313. if ($colspan === null) {
  314. $colspan = 3;
  315. }
  316. $totals = $this->getChildBlock(
  317. 'totals'
  318. )->setTotals(
  319. $totals
  320. )->renderTotals(
  321. '',
  322. $colspan
  323. ) . $this->getChildBlock(
  324. 'totals'
  325. )->setTotals(
  326. $totals
  327. )->renderTotals(
  328. 'footer',
  329. $colspan
  330. );
  331. return $totals;
  332. }
  333. /**
  334. * Return row-level item html
  335. *
  336. * @param \Magento\Framework\DataObject $item
  337. * @return string
  338. */
  339. public function getRowItemHtml(\Magento\Framework\DataObject $item)
  340. {
  341. $type = $this->_getItemType($item);
  342. $renderer = $this->_getRowItemRenderer($type)->setItem($item);
  343. $this->_prepareItem($renderer);
  344. return $renderer->toHtml();
  345. }
  346. /**
  347. * Retrieve renderer block for row-level item output
  348. *
  349. * @param string $type
  350. * @return \Magento\Framework\View\Element\AbstractBlock
  351. */
  352. protected function _getRowItemRenderer($type)
  353. {
  354. $renderer = $this->getItemRenderer($type);
  355. if ($renderer !== $this->getItemRenderer(self::DEFAULT_TYPE)) {
  356. $renderer->setTemplate($this->getRowRendererTemplate());
  357. }
  358. return $renderer;
  359. }
  360. }