Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Review.php
Go to the documentation of this file.
1 <?php
8 
11 
20 {
24  protected $_quote;
25 
29  protected $_address;
30 
34  protected $_addressConfig;
35 
41  protected $_currentShippingRate = null;
42 
48  protected $_controllerPath = 'paypal/express';
49 
53  protected $_taxHelper;
54 
58  protected $priceCurrency;
59 
67  public function __construct(
68  \Magento\Framework\View\Element\Template\Context $context,
69  \Magento\Tax\Helper\Data $taxHelper,
70  \Magento\Customer\Model\Address\Config $addressConfig,
72  array $data = []
73  ) {
74  $this->priceCurrency = $priceCurrency;
75  $this->_taxHelper = $taxHelper;
76  $this->_addressConfig = $addressConfig;
77  parent::__construct($context, $data);
78  }
79 
86  public function setQuote(\Magento\Quote\Model\Quote $quote)
87  {
88  $this->_quote = $quote;
89  return $this;
90  }
91 
97  public function getBillingAddress()
98  {
99  return $this->_quote->getBillingAddress();
100  }
101 
107  public function getShippingAddress()
108  {
109  if ($this->_quote->getIsVirtual()) {
110  return false;
111  }
112  return $this->_quote->getShippingAddress();
113  }
114 
121  public function renderAddress($address)
122  {
124  $renderer = $this->_addressConfig->getFormatByCode('html')->getRenderer();
126  return $renderer->renderArray($addressData);
127  }
128 
135  public function getCarrierName($carrierCode)
136  {
137  if ($name = $this->_scopeConfig->getValue(
138  "carriers/{$carrierCode}/title",
139  \Magento\Store\Model\ScopeInterface::SCOPE_STORE
140  )
141  ) {
142  return $name;
143  }
144  return $carrierCode;
145  }
146 
153  public function renderShippingRateValue(\Magento\Framework\DataObject $rate)
154  {
155  if ($rate->getErrorMessage()) {
156  return '';
157  }
158  return $rate->getCode();
159  }
160 
169  public function renderShippingRateOption($rate, $format = '%s - %s%s', $inclTaxFormat = ' (%s %s)')
170  {
171  $renderedInclTax = '';
172  if ($rate->getErrorMessage()) {
173  $price = $rate->getErrorMessage();
174  } else {
175  $price = $this->_getShippingPrice(
176  $rate->getPrice(),
177  $this->_taxHelper->displayShippingPriceIncludingTax()
178  );
179 
180  $incl = $this->_getShippingPrice($rate->getPrice(), true);
181  if ($incl != $price && $this->_taxHelper->displayShippingBothPrices()) {
182  $renderedInclTax = sprintf($inclTaxFormat, $this->escapeHtml(__('Incl. Tax')), $incl);
183  }
184  }
185  return sprintf($format, $this->escapeHtml($rate->getMethodTitle()), $price, $renderedInclTax);
186  }
187 
193  public function getCurrentShippingRate()
194  {
196  }
197 
203  public function canEditShippingMethod()
204  {
205  return $this->getData('can_edit_shipping_method') || !$this->getCurrentShippingRate();
206  }
207 
213  public function getEmail()
214  {
216  return $billingAddress ? $billingAddress->getEmail() : '';
217  }
218 
225  public function setControllerPath($prefix)
226  {
227  $this->_controllerPath = $prefix;
228  }
229 
237  protected function _getShippingPrice($price, $isInclTax)
238  {
239  return $this->_formatPrice($this->_taxHelper->getShippingPrice($price, $isInclTax, $this->_address));
240  }
241 
248  protected function _formatPrice($price)
249  {
250  return $this->priceCurrency->convertAndFormat(
251  $price,
252  true,
254  $this->_quote->getStore()
255  );
256  }
257 
264  protected function _beforeToHtml()
265  {
266  $methodInstance = $this->_quote->getPayment()->getMethodInstance();
267  $this->setPaymentMethodTitle($methodInstance->getTitle());
268 
269  $this->setShippingRateRequired(true);
270  if ($this->_quote->getIsVirtual()) {
271  $this->setShippingRateRequired(false);
272  } else {
273  // prepare shipping rates
274  $this->_address = $this->_quote->getShippingAddress();
275  $groups = $this->_address->getGroupedAllShippingRates();
276  if ($groups && $this->_address) {
277  $this->setShippingRateGroups($groups);
278  // determine current selected code & name
279  foreach ($groups as $code => $rates) {
280  foreach ($rates as $rate) {
281  if ($this->_address->getShippingMethod() == $rate->getCode()) {
282  $this->_currentShippingRate = $rate;
283  break 2;
284  }
285  }
286  }
287  }
288 
289  $canEditShippingAddress = $this->_quote->getMayEditShippingAddress() && $this->_quote->getPayment()
290  ->getAdditionalInformation(\Magento\Paypal\Model\Express\Checkout::PAYMENT_INFO_BUTTON) == 1;
291  // misc shipping parameters
292  $this->setShippingMethodSubmitUrl(
293  $this->getUrl("{$this->_controllerPath}/saveShippingMethod", ['_secure' => true])
294  )->setCanEditShippingAddress(
295  $canEditShippingAddress
296  )->setCanEditShippingMethod(
297  $this->_quote->getMayEditShippingMethod()
298  );
299  }
300 
301  $this->setEditUrl(
302  $this->getUrl("{$this->_controllerPath}/edit")
303  )->setPlaceOrderUrl(
304  $this->getUrl("{$this->_controllerPath}/placeOrder", ['_secure' => true])
305  );
306 
307  return parent::_beforeToHtml();
308  }
309 }
__construct(\Magento\Framework\View\Element\Template\Context $context, \Magento\Tax\Helper\Data $taxHelper, \Magento\Customer\Model\Address\Config $addressConfig, PriceCurrencyInterface $priceCurrency, array $data=[])
Definition: Review.php:67
_getShippingPrice($price, $isInclTax)
Definition: Review.php:237
getData($key='', $index=null)
Definition: DataObject.php:119
$billingAddress
Definition: order.php:25
$quote
__()
Definition: __.php:13
$price
$rates
Definition: tax.phtml:35
$incl
Definition: form.phtml:56
$address
Definition: customer.php:38
$addressData
Definition: order.php:19
$prefix
Definition: name.phtml:25
$format
Definition: list.phtml:12
renderShippingRateValue(\Magento\Framework\DataObject $rate)
Definition: Review.php:153
setQuote(\Magento\Quote\Model\Quote $quote)
Definition: Review.php:86
renderShippingRateOption($rate, $format='%s - %s%s', $inclTaxFormat='(%s %s)')
Definition: Review.php:169
$code
Definition: info.phtml:12
if(!isset($_GET['name'])) $name
Definition: log.php:14