Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
Data Class Reference
Inheritance diagram for Data:
AbstractHelper

Public Member Functions

 __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)
 
 getCheckout ()
 
 getQuote ()
 
 formatPrice ($price)
 
 convertPrice ($price, $format=true)
 
 canOnepageCheckout ()
 
 getPriceInclTax ($item)
 
 getSubtotalInclTax ($item)
 
 getBasePriceInclTax ($item)
 
 getBaseSubtotalInclTax ($item)
 
 sendPaymentFailedEmail (\Magento\Quote\Model\Quote $checkout, string $message, string $checkoutType='onepage')
 
 isAllowedGuestCheckout (\Magento\Quote\Model\Quote $quote, $store=null)
 
 isContextCheckout ()
 
 isCustomerMustBeLogged ()
 
 isDisplayBillingOnPaymentMethodAvailable ()
 
- Public Member Functions inherited from AbstractHelper
 __construct (Context $context)
 
 isModuleOutputEnabled ($moduleName=null)
 

Data Fields

const XML_PATH_GUEST_CHECKOUT = 'checkout/options/guest_checkout'
 
const XML_PATH_CUSTOMER_MUST_BE_LOGGED = 'checkout/options/customer_must_be_logged'
 

Protected Member Functions

 _getEmails ($configPath, $storeId)
 
- Protected Member Functions inherited from AbstractHelper
 _getRequest ()
 
 _getModuleName ()
 
 _getUrl ($route, $params=[])
 

Protected Attributes

 $_storeManager
 
 $_checkoutSession
 
 $_localeDate
 
 $_transportBuilder
 
 $inlineTranslation
 
 $priceCurrency
 
- Protected Attributes inherited from AbstractHelper
 $_moduleName
 
 $_request
 
 $_moduleManager
 
 $_logger
 
 $_urlBuilder
 
 $_httpHeader
 
 $_eventManager
 
 $_remoteAddress
 
 $urlEncoder
 
 $urlDecoder
 
 $scopeConfig
 
 $_cacheConfig
 

Detailed Description

Checkout default helper

Author
Magento Core Team core@.nosp@m.mage.nosp@m.ntoco.nosp@m.mmer.nosp@m.ce.co.nosp@m.m @SuppressWarnings(PHPMD.CouplingBetweenObjects)

Definition at line 20 of file Data.php.

Constructor & Destructor Documentation

◆ __construct()

Parameters
\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 | null$paymentFailures@codeCoverageIgnore

Definition at line 72 of file Data.php.

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  }
$storeManager

Member Function Documentation

◆ _getEmails()

_getEmails (   $configPath,
  $storeId 
)
protected
Parameters
string$configPath
null | string | bool | int | Store$storeId
Returns
array|false

Definition at line 231 of file Data.php.

232  {
233  $data = $this->scopeConfig->getValue(
234  $configPath,
236  $storeId
237  );
238  if (!empty($data)) {
239  return explode(',', $data);
240  }
241  return false;
242  }

◆ canOnepageCheckout()

canOnepageCheckout ( )

Get onepage checkout availability

Returns
bool

Definition at line 146 of file Data.php.

147  {
148  return (bool)$this->scopeConfig->getValue(
149  'checkout/options/onepage_checkout_enabled',
151  );
152  }

◆ convertPrice()

convertPrice (   $price,
  $format = true 
)
Parameters
float$price
bool$format
Returns
float

Definition at line 134 of file Data.php.

135  {
136  return $format
137  ? $this->priceCurrency->convertAndFormat($price)
138  : $this->priceCurrency->convert($price);
139  }
$price
$format
Definition: list.phtml:12

◆ formatPrice()

formatPrice (   $price)
Parameters
float$price
Returns
string

Definition at line 119 of file Data.php.

120  {
121  return $this->priceCurrency->format(
122  $price,
123  true,
125  $this->getQuote()->getStore()
126  );
127  }
$price

◆ getBasePriceInclTax()

getBasePriceInclTax (   $item)
Parameters
AbstractItem$item
Returns
float

Definition at line 190 of file Data.php.

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  }
$price

◆ getBaseSubtotalInclTax()

getBaseSubtotalInclTax (   $item)
Parameters
AbstractItem$item
Returns
float

Definition at line 202 of file Data.php.

203  {
204  $tax = $item->getBaseTaxAmount() + $item->getBaseDiscountTaxCompensation();
205  return $item->getBaseRowTotal() + $tax;
206  }

◆ getCheckout()

getCheckout ( )

Retrieve checkout session model

Returns
\Magento\Checkout\Model\Session @codeCoverageIgnore

Definition at line 99 of file Data.php.

100  {
102  }

◆ getPriceInclTax()

getPriceInclTax (   $item)

Get sales item (quote item, order item etc) price including tax based on row total and tax amount

Parameters
\Magento\Framework\DataObject$item
Returns
float

Definition at line 160 of file Data.php.

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  }
$price

◆ getQuote()

getQuote ( )

Retrieve checkout quote model object

Returns
\Magento\Quote\Model\Quote @codeCoverageIgnore

Definition at line 110 of file Data.php.

111  {
112  return $this->getCheckout()->getQuote();
113  }

◆ getSubtotalInclTax()

getSubtotalInclTax (   $item)

Get sales item (quote item, order item etc) row total price including tax

Parameters
\Magento\Framework\DataObject$item
Returns
float

Definition at line 177 of file Data.php.

178  {
179  if ($item->getRowTotalInclTax()) {
180  return $item->getRowTotalInclTax();
181  }
182  $tax = $item->getTaxAmount() + $item->getDiscountTaxCompensation();
183  return $item->getRowTotal() + $tax;
184  }

◆ isAllowedGuestCheckout()

isAllowedGuestCheckout ( \Magento\Quote\Model\Quote  $quote,
  $store = null 
)

Check is allowed Guest Checkout Use config settings and observer

Parameters
\Magento\Quote\Model\Quote$quote
int | Store$store
Returns
bool

Definition at line 252 of file Data.php.

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  }
$quote

◆ isContextCheckout()

isContextCheckout ( )

Check if context is checkout

Returns
bool @codeCoverageIgnore

Definition at line 283 of file Data.php.

284  {
285  return $this->_request->getParam('context') == 'checkout';
286  }

◆ isCustomerMustBeLogged()

isCustomerMustBeLogged ( )

Check if user must be logged during checkout process

Returns
boolean @codeCoverageIgnore

Definition at line 294 of file Data.php.

295  {
296  return $this->scopeConfig->isSetFlag(
297  self::XML_PATH_CUSTOMER_MUST_BE_LOGGED,
299  );
300  }

◆ isDisplayBillingOnPaymentMethodAvailable()

isDisplayBillingOnPaymentMethodAvailable ( )

Checks if display billing address on payment method is available, otherwise billing address should be display on payment page

Returns
bool

Definition at line 307 of file Data.php.

308  {
309  return (bool) !$this->scopeConfig->getValue(
310  'checkout/options/display_billing_address_on',
312  );
313  }

◆ sendPaymentFailedEmail()

sendPaymentFailedEmail ( \Magento\Quote\Model\Quote  $checkout,
string  $message,
string  $checkoutType = 'onepage' 
)

Send email id payment was failed

Parameters
\Magento\Quote\Model\Quote$checkout
string$message
string$checkoutType
Returns
$this

Definition at line 216 of file Data.php.

221  $this->paymentFailures->handle((int)$checkout->getId(), $message, $checkoutType);
222 
223  return $this;
224  }
$message

Field Documentation

◆ $_checkoutSession

$_checkoutSession
protected

Definition at line 34 of file Data.php.

◆ $_localeDate

$_localeDate
protected

Definition at line 39 of file Data.php.

◆ $_storeManager

$_storeManager
protected

Definition at line 29 of file Data.php.

◆ $_transportBuilder

$_transportBuilder
protected

Definition at line 44 of file Data.php.

◆ $inlineTranslation

$inlineTranslation
protected

Definition at line 49 of file Data.php.

◆ $priceCurrency

$priceCurrency
protected

Definition at line 54 of file Data.php.

◆ XML_PATH_CUSTOMER_MUST_BE_LOGGED

const XML_PATH_CUSTOMER_MUST_BE_LOGGED = 'checkout/options/customer_must_be_logged'

Definition at line 24 of file Data.php.

◆ XML_PATH_GUEST_CHECKOUT

const XML_PATH_GUEST_CHECKOUT = 'checkout/options/guest_checkout'

Definition at line 22 of file Data.php.


The documentation for this class was generated from the following file: