Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Data.php
Go to the documentation of this file.
1 <?php
7 
13 
21 {
22  const XML_PATH_GUEST_CHECKOUT = 'checkout/options/guest_checkout';
23 
24  const XML_PATH_CUSTOMER_MUST_BE_LOGGED = 'checkout/options/customer_must_be_logged';
25 
29  protected $_storeManager;
30 
34  protected $_checkoutSession;
35 
39  protected $_localeDate;
40 
44  protected $_transportBuilder;
45 
49  protected $inlineTranslation;
50 
54  protected $priceCurrency;
55 
59  private $paymentFailures;
60 
72  public function __construct(
73  \Magento\Framework\App\Helper\Context $context,
74  \Magento\Store\Model\StoreManagerInterface $storeManager,
75  \Magento\Checkout\Model\Session $checkoutSession,
76  \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
77  \Magento\Framework\Mail\Template\TransportBuilder $transportBuilder,
78  \Magento\Framework\Translate\Inline\StateInterface $inlineTranslation,
80  PaymentFailuresInterface $paymentFailures = null
81  ) {
82  $this->_storeManager = $storeManager;
83  $this->_checkoutSession = $checkoutSession;
84  $this->_localeDate = $localeDate;
85  $this->_transportBuilder = $transportBuilder;
86  $this->inlineTranslation = $inlineTranslation;
87  $this->priceCurrency = $priceCurrency;
88  $this->paymentFailures = $paymentFailures ? : \Magento\Framework\App\ObjectManager::getInstance()
89  ->get(PaymentFailuresInterface::class);
90  parent::__construct($context);
91  }
92 
99  public function getCheckout()
100  {
102  }
103 
110  public function getQuote()
111  {
112  return $this->getCheckout()->getQuote();
113  }
114 
119  public function formatPrice($price)
120  {
121  return $this->priceCurrency->format(
122  $price,
123  true,
125  $this->getQuote()->getStore()
126  );
127  }
128 
134  public function convertPrice($price, $format = true)
135  {
136  return $format
137  ? $this->priceCurrency->convertAndFormat($price)
138  : $this->priceCurrency->convert($price);
139  }
140 
146  public function canOnepageCheckout()
147  {
148  return (bool)$this->scopeConfig->getValue(
149  'checkout/options/onepage_checkout_enabled',
151  );
152  }
153 
160  public function getPriceInclTax($item)
161  {
162  if ($item->getPriceInclTax()) {
163  return $item->getPriceInclTax();
164  }
165  $qty = $item->getQty() ? $item->getQty() : ($item->getQtyOrdered() ? $item->getQtyOrdered() : 1);
166  $taxAmount = $item->getTaxAmount() + $item->getDiscountTaxCompensation();
167  $price = (float)$qty ? ($item->getRowTotal() + $taxAmount) / $qty : 0;
168  return $this->priceCurrency->round($price);
169  }
170 
177  public function getSubtotalInclTax($item)
178  {
179  if ($item->getRowTotalInclTax()) {
180  return $item->getRowTotalInclTax();
181  }
182  $tax = $item->getTaxAmount() + $item->getDiscountTaxCompensation();
183  return $item->getRowTotal() + $tax;
184  }
185 
190  public function getBasePriceInclTax($item)
191  {
192  $qty = $item->getQty() ? $item->getQty() : ($item->getQtyOrdered() ? $item->getQtyOrdered() : 1);
193  $taxAmount = $item->getBaseTaxAmount() + $item->getBaseDiscountTaxCompensation();
194  $price = (float)$qty ? ($item->getBaseRowTotal() + $taxAmount) / $qty : 0;
195  return $this->priceCurrency->round($price);
196  }
197 
202  public function getBaseSubtotalInclTax($item)
203  {
204  $tax = $item->getBaseTaxAmount() + $item->getBaseDiscountTaxCompensation();
205  return $item->getBaseRowTotal() + $tax;
206  }
207 
216  public function sendPaymentFailedEmail(
217  \Magento\Quote\Model\Quote $checkout,
218  string $message,
219  string $checkoutType = 'onepage'
220  ): \Magento\Checkout\Helper\Data {
221  $this->paymentFailures->handle((int)$checkout->getId(), $message, $checkoutType);
222 
223  return $this;
224  }
225 
231  protected function _getEmails($configPath, $storeId)
232  {
233  $data = $this->scopeConfig->getValue(
234  $configPath,
236  $storeId
237  );
238  if (!empty($data)) {
239  return explode(',', $data);
240  }
241  return false;
242  }
243 
252  public function isAllowedGuestCheckout(\Magento\Quote\Model\Quote $quote, $store = null)
253  {
254  if ($store === null) {
255  $store = $quote->getStoreId();
256  }
257  $guestCheckout = $this->scopeConfig->isSetFlag(
258  self::XML_PATH_GUEST_CHECKOUT,
260  $store
261  );
262 
263  if ($guestCheckout == true) {
264  $result = new \Magento\Framework\DataObject();
265  $result->setIsAllowed($guestCheckout);
266  $this->_eventManager->dispatch(
267  'checkout_allow_guest',
268  ['quote' => $quote, 'store' => $store, 'result' => $result]
269  );
270 
271  $guestCheckout = $result->getIsAllowed();
272  }
273 
274  return $guestCheckout;
275  }
276 
283  public function isContextCheckout()
284  {
285  return $this->_request->getParam('context') == 'checkout';
286  }
287 
294  public function isCustomerMustBeLogged()
295  {
296  return $this->scopeConfig->isSetFlag(
297  self::XML_PATH_CUSTOMER_MUST_BE_LOGGED,
299  );
300  }
301 
308  {
309  return (bool) !$this->scopeConfig->getValue(
310  'checkout/options/display_billing_address_on',
312  );
313  }
314 }
const XML_PATH_CUSTOMER_MUST_BE_LOGGED
Definition: Data.php:24
$quote
$storeManager
sendPaymentFailedEmail(\Magento\Quote\Model\Quote $checkout, string $message, string $checkoutType='onepage')
Definition: Data.php:216
$price
$message
_getEmails($configPath, $storeId)
Definition: Data.php:231
$format
Definition: list.phtml:12
isDisplayBillingOnPaymentMethodAvailable()
Definition: Data.php:307
convertPrice($price, $format=true)
Definition: Data.php:134
__construct(\Magento\Framework\App\Helper\Context $context, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Checkout\Model\Session $checkoutSession, \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate, \Magento\Framework\Mail\Template\TransportBuilder $transportBuilder, \Magento\Framework\Translate\Inline\StateInterface $inlineTranslation, PriceCurrencyInterface $priceCurrency, PaymentFailuresInterface $paymentFailures=null)
Definition: Data.php:72
isAllowedGuestCheckout(\Magento\Quote\Model\Quote $quote, $store=null)
Definition: Data.php:252