Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Shipping.php
Go to the documentation of this file.
1 <?php
7 
10 
19 {
24 
28  protected $_taxHelper;
29 
33  protected $priceCurrency;
34 
43  public function __construct(
44  \Magento\Framework\View\Element\Template\Context $context,
45  \Magento\Framework\Filter\DataObject\GridFactory $filterGridFactory,
46  \Magento\Multishipping\Model\Checkout\Type\Multishipping $multishipping,
47  \Magento\Tax\Helper\Data $taxHelper,
49  array $data = []
50  ) {
51  $this->priceCurrency = $priceCurrency;
52  $this->_taxHelper = $taxHelper;
53  $this->_filterGridFactory = $filterGridFactory;
54  $this->_multishipping = $multishipping;
55  parent::__construct($context, $data);
56  $this->_isScopePrivate = true;
57  }
58 
64  public function getCheckout()
65  {
66  return $this->_multishipping;
67  }
68 
72  protected function _prepareLayout()
73  {
74  $this->pageConfig->getTitle()->set(
75  __('Shipping Methods') . ' - ' . $this->pageConfig->getTitle()->getDefault()
76  );
77  return parent::_prepareLayout();
78  }
79 
83  public function getAddresses()
84  {
85  return $this->getCheckout()->getQuote()->getAllShippingAddresses();
86  }
87 
91  public function getAddressCount()
92  {
93  $count = $this->getData('address_count');
94  if ($count === null) {
95  $count = count($this->getAddresses());
96  $this->setData('address_count', $count);
97  }
98  return $count;
99  }
100 
105  public function getAddressItems($address)
106  {
107  $items = [];
108  foreach ($address->getAllItems() as $item) {
109  if ($item->getParentItemId()) {
110  continue;
111  }
112  $item->setQuoteItem($this->getCheckout()->getQuote()->getItemById($item->getQuoteItemId()));
113  $items[] = $item;
114  }
115  $itemsFilter = $this->_filterGridFactory->create();
116  $itemsFilter->addFilter(new \Magento\Framework\Filter\Sprintf('%d'), 'qty');
117  return $itemsFilter->filter($items);
118  }
119 
125  {
126  return $address->getShippingMethod();
127  }
128 
133  public function getShippingRates($address)
134  {
135  $groups = $address->getGroupedAllShippingRates();
136  return $groups;
137  }
138 
143  public function getCarrierName($carrierCode)
144  {
145  if ($name = $this->_scopeConfig->getValue(
146  'carriers/' . $carrierCode . '/title',
148  )
149  ) {
150  return $name;
151  }
152  return $carrierCode;
153  }
154 
159  public function getAddressEditUrl($address)
160  {
161  return $this->getUrl('*/checkout_address/editShipping', ['id' => $address->getCustomerAddressId()]);
162  }
163 
167  public function getItemsEditUrl()
168  {
169  return $this->getUrl('*/*/backToAddresses');
170  }
171 
175  public function getPostActionUrl()
176  {
177  return $this->getUrl('*/*/shippingPost');
178  }
179 
183  public function getBackUrl()
184  {
185  return $this->getUrl('*/*/backtoaddresses');
186  }
187 
194  public function getShippingPrice($address, $price, $flag)
195  {
196  return $this->priceCurrency->convertAndFormat(
197  $this->_taxHelper->getShippingPrice($price, $flag, $address),
198  true,
200  $address->getQuote()->getStore()
201  );
202  }
203 
212  public function getItemsBoxTextAfter(\Magento\Framework\DataObject $addressEntity)
213  {
214  return '';
215  }
216 }
getData($key='', $index=null)
Definition: DataObject.php:119
$count
Definition: recent.phtml:13
__()
Definition: __.php:13
$price
getItemsBoxTextAfter(\Magento\Framework\DataObject $addressEntity)
Definition: Shipping.php:212
$address
Definition: customer.php:38
__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=[])
Definition: Shipping.php:43
setData($key, $value=null)
Definition: DataObject.php:72
getShippingPrice($address, $price, $flag)
Definition: Shipping.php:194
$items
if(!isset($_GET['name'])) $name
Definition: log.php:14