PageRenderTime 41ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/magento/module-multishipping/Block/Checkout/Overview.php

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