123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Multishipping\Block\Checkout;
- use Magento\Framework\Pricing\PriceCurrencyInterface;
- use Magento\Quote\Model\Quote\Address;
- /**
- * Mustishipping checkout shipping
- *
- * @api
- * @author Magento Core Team <core@magentocommerce.com>
- * @since 100.0.2
- */
- class Shipping extends \Magento\Sales\Block\Items\AbstractItems
- {
- /**
- * @var \Magento\Framework\Filter\DataObject\GridFactory
- */
- protected $_filterGridFactory;
- /**
- * @var \Magento\Tax\Helper\Data
- */
- protected $_taxHelper;
- /**
- * @var PriceCurrencyInterface
- */
- protected $priceCurrency;
- /**
- * @param \Magento\Framework\View\Element\Template\Context $context
- * @param \Magento\Framework\Filter\DataObject\GridFactory $filterGridFactory
- * @param \Magento\Multishipping\Model\Checkout\Type\Multishipping $multishipping
- * @param \Magento\Tax\Helper\Data $taxHelper
- * @param PriceCurrencyInterface $priceCurrency
- * @param array $data
- */
- public function __construct(
- \Magento\Framework\View\Element\Template\Context $context,
- \Magento\Framework\Filter\DataObject\GridFactory $filterGridFactory,
- \Magento\Multishipping\Model\Checkout\Type\Multishipping $multishipping,
- \Magento\Tax\Helper\Data $taxHelper,
- PriceCurrencyInterface $priceCurrency,
- array $data = []
- ) {
- $this->priceCurrency = $priceCurrency;
- $this->_taxHelper = $taxHelper;
- $this->_filterGridFactory = $filterGridFactory;
- $this->_multishipping = $multishipping;
- parent::__construct($context, $data);
- $this->_isScopePrivate = true;
- }
- /**
- * Get multishipping checkout model
- *
- * @return \Magento\Multishipping\Model\Checkout\Type\Multishipping
- */
- public function getCheckout()
- {
- return $this->_multishipping;
- }
- /**
- * @return $this
- */
- protected function _prepareLayout()
- {
- $this->pageConfig->getTitle()->set(
- __('Shipping Methods') . ' - ' . $this->pageConfig->getTitle()->getDefault()
- );
- return parent::_prepareLayout();
- }
- /**
- * @return Address[]
- */
- public function getAddresses()
- {
- return $this->getCheckout()->getQuote()->getAllShippingAddresses();
- }
- /**
- * @return mixed
- */
- public function getAddressCount()
- {
- $count = $this->getData('address_count');
- if ($count === null) {
- $count = count($this->getAddresses());
- $this->setData('address_count', $count);
- }
- return $count;
- }
- /**
- * @param Address $address
- * @return \Magento\Framework\DataObject[]
- */
- public function getAddressItems($address)
- {
- $items = [];
- foreach ($address->getAllItems() as $item) {
- if ($item->getParentItemId()) {
- continue;
- }
- $item->setQuoteItem($this->getCheckout()->getQuote()->getItemById($item->getQuoteItemId()));
- $items[] = $item;
- }
- $itemsFilter = $this->_filterGridFactory->create();
- $itemsFilter->addFilter(new \Magento\Framework\Filter\Sprintf('%d'), 'qty');
- return $itemsFilter->filter($items);
- }
- /**
- * @param Address $address
- * @return mixed
- */
- public function getAddressShippingMethod($address)
- {
- return $address->getShippingMethod();
- }
- /**
- * @param Address $address
- * @return mixed
- */
- public function getShippingRates($address)
- {
- $groups = $address->getGroupedAllShippingRates();
- return $groups;
- }
- /**
- * @param string $carrierCode
- * @return string
- */
- public function getCarrierName($carrierCode)
- {
- if ($name = $this->_scopeConfig->getValue(
- 'carriers/' . $carrierCode . '/title',
- \Magento\Store\Model\ScopeInterface::SCOPE_STORE
- )
- ) {
- return $name;
- }
- return $carrierCode;
- }
- /**
- * @param Address $address
- * @return string
- */
- public function getAddressEditUrl($address)
- {
- return $this->getUrl('*/checkout_address/editShipping', ['id' => $address->getCustomerAddressId()]);
- }
- /**
- * @return string
- */
- public function getItemsEditUrl()
- {
- return $this->getUrl('*/*/backToAddresses');
- }
- /**
- * @return string
- */
- public function getPostActionUrl()
- {
- return $this->getUrl('*/*/shippingPost');
- }
- /**
- * @return string
- */
- public function getBackUrl()
- {
- return $this->getUrl('*/*/backtoaddresses');
- }
- /**
- * @param Address $address
- * @param float $price
- * @param bool $flag
- * @return float
- */
- public function getShippingPrice($address, $price, $flag)
- {
- return $this->priceCurrency->convertAndFormat(
- $this->_taxHelper->getShippingPrice($price, $flag, $address),
- true,
- PriceCurrencyInterface::DEFAULT_PRECISION,
- $address->getQuote()->getStore()
- );
- }
- /**
- * Retrieve text for items box
- *
- * @param \Magento\Framework\DataObject $addressEntity
- * @return string
- *
- * @SuppressWarnings(PHPMD.UnusedFormalParameter)
- */
- public function getItemsBoxTextAfter(\Magento\Framework\DataObject $addressEntity)
- {
- return '';
- }
- }
|