Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Billing Class Reference
Inheritance diagram for Billing:
Template AbstractBlock DataObject BlockInterface

Public Member Functions

 __construct (\Magento\Framework\View\Element\Template\Context $context, \Magento\Customer\Model\Session $customerSession, \Magento\Checkout\Model\Session $resourceSession, \Magento\Directory\Model\ResourceModel\Country\CollectionFactory $countryCollectionFactory, CustomerRepositoryInterface $customerRepository, \Magento\Framework\App\Http\Context $httpContext, \Magento\Quote\Model\Quote\AddressFactory $addressFactory, array $data=[])
 
 isUseBillingAddressForShipping ()
 
 getCountries ()
 
 getMethod ()
 
 getFirstname ()
 
 getLastname ()
 
 canShip ()
 
 getSaveUrl ()
 
 isTaxvatEnabled ()
 
 getTaxvatHtml ()
 
 getAddress ()
 
 getConfig ($path)
 
 getCheckout ()
 
 getQuote ()
 
 isCustomerLoggedIn ()
 
- Public Member Functions inherited from Template
 __construct (Template\Context $context, array $data=[])
 
 setTemplateContext ($templateContext)
 
 getTemplate ()
 
 setTemplate ($template)
 
 getTemplateFile ($template=null)
 
 getArea ()
 
 assign ($key, $value=null)
 
 fetchView ($fileName)
 
 getBaseUrl ()
 
 getObjectData (\Magento\Framework\DataObject $object, $key)
 
 getCacheKeyInfo ()
 
- Public Member Functions inherited from AbstractBlock
 __construct (\Magento\Framework\View\Element\Context $context, array $data=[])
 
 getJsLayout ()
 
 getRequest ()
 
 getParentBlock ()
 
 setLayout (\Magento\Framework\View\LayoutInterface $layout)
 
 getLayout ()
 
 setNameInLayout ($name)
 
 getChildNames ()
 
 setAttribute ($name, $value=null)
 
 setChild ($alias, $block)
 
 addChild ($alias, $block, $data=[])
 
 unsetChild ($alias)
 
 unsetCallChild ($alias, $callback, $result, $params)
 
 unsetChildren ()
 
 getChildBlock ($alias)
 
 getChildHtml ($alias='', $useCache=true)
 
 getChildChildHtml ($alias, $childChildAlias='', $useCache=true)
 
 getBlockHtml ($name)
 
 insert ($element, $siblingName=0, $after=true, $alias='')
 
 append ($element, $alias='')
 
 getGroupChildNames ($groupName)
 
 getChildData ($alias, $key='')
 
 getUiId ($arg1=null, $arg2=null, $arg3=null, $arg4=null, $arg5=null)
 
 getJsId ($arg1=null, $arg2=null, $arg3=null, $arg4=null, $arg5=null)
 
 getUrl ($route='', $params=[])
 
 getViewFileUrl ($fileId, array $params=[])
 
 formatDate ( $date=null, $format=\IntlDateFormatter::SHORT, $showTime=false, $timezone=null)
 
 formatTime ( $time=null, $format=\IntlDateFormatter::SHORT, $showDate=false)
 
 getModuleName ()
 
 escapeHtml ($data, $allowedTags=null)
 
 escapeJs ($string)
 
 escapeHtmlAttr ($string, $escapeSingleQuote=true)
 
 escapeCss ($string)
 
 stripTags ($data, $allowableTags=null, $allowHtmlEntities=false)
 
 escapeUrl ($string)
 
 escapeXssInUrl ($data)
 
 escapeQuote ($data, $addSlashes=false)
 
 escapeJsQuote ($data, $quote='\'')
 
 getNameInLayout ()
 
 getCacheKeyInfo ()
 
 getCacheKey ()
 
 getVar ($name, $module=null)
 
 isScopePrivate ()
 
- Public Member Functions inherited from DataObject
 __construct (array $data=[])
 
 addData (array $arr)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 getDataByPath ($path)
 
 getDataByKey ($key)
 
 setDataUsingMethod ($key, $args=[])
 
 getDataUsingMethod ($key, $args=null)
 
 hasData ($key='')
 
 toArray (array $keys=[])
 
 convertToArray (array $keys=[])
 
 toXml (array $keys=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 convertToXml (array $arrAttributes=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 toJson (array $keys=[])
 
 convertToJson (array $keys=[])
 
 toString ($format='')
 
 __call ($method, $args)
 
 isEmpty ()
 
 serialize ($keys=[], $valueSeparator='=', $fieldSeparator=' ', $quote='"')
 
 debug ($data=null, &$objects=[])
 
 offsetSet ($offset, $value)
 
 offsetExists ($offset)
 
 offsetUnset ($offset)
 
 offsetGet ($offset)
 
- Public Member Functions inherited from BlockInterface
 toHtml ()
 

Protected Member Functions

 _construct ()
 
 _getTaxvat ()
 
 _getCustomer ()
 
- Protected Member Functions inherited from Template
 _construct ()
 
 _toHtml ()
 
 getRootDirectory ()
 
 getMediaDirectory ()
 
- Protected Member Functions inherited from AbstractBlock
 _construct ()
 
 _prepareLayout ()
 
 _beforeToHtml ()
 
 _afterToHtml ($html)
 
 _toHtml ()
 
 _getNotFoundUrl ($route='', $params=['_direct'=> 'core/index/notFound'])
 
 getCacheTags ()
 
 getCacheLifetime ()
 
 _loadCache ()
 
 _saveCache ($data)
 
 _getSidPlaceholder ($cacheKey=null)
 
- Protected Member Functions inherited from DataObject
 _getData ($key)
 
 _underscore ($name)
 

Protected Attributes

 $address
 
 $taxvat
 
 $addressFactory
 
 $customer
 
 $quote
 
 $checkoutSession
 
 $customerSession
 
 $customerRepository
 
 $httpContext
 
 $countryCollectionFactory
 
- Protected Attributes inherited from Template
 $_viewVars = []
 
 $_baseUrl
 
 $_jsUrl
 
 $_allowSymlinks
 
 $_filesystem
 
 $_template
 
 $templateEnginePool
 
 $_storeManager
 
 $_appState
 
 $directory
 
 $templateContext
 
 $pageConfig
 
 $resolver
 
 $validator
 
- Protected Attributes inherited from AbstractBlock
 $_design
 
 $_session
 
 $_sidResolver
 
 $_nameInLayout
 
 $_layout
 
 $jsLayout = []
 
 $_request
 
 $_urlBuilder
 
 $_eventManager
 
 $_frontController
 
 $_assetRepo
 
 $_viewConfig
 
 $_cacheState
 
 $_logger
 
 $_escaper
 
 $filterManager
 
 $_localeDate
 
 $inlineTranslation
 
 $_isScopePrivate = false
 
 $_scopeConfig
 
 $_cache
 
- Protected Attributes inherited from DataObject
 $_data = []
 

Additional Inherited Members

- Static Public Member Functions inherited from AbstractBlock
static extractModuleName ($className)
 
- Data Fields inherited from Template
const XML_PATH_TEMPLATE_ALLOW_SYMLINK = 'dev/template/allow_symlink'
 
- Data Fields inherited from AbstractBlock
const CACHE_GROUP = \Magento\Framework\App\Cache\Type\Block::TYPE_IDENTIFIER
 
const CACHE_KEY_PREFIX = 'BLOCK_'
 
- Static Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Detailed Description

@SuppressWarnings(PHPMD.CouplingBetweenObjects)

Definition at line 18 of file Billing.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\View\Element\Template\Context  $context,
\Magento\Customer\Model\Session  $customerSession,
\Magento\Checkout\Model\Session  $resourceSession,
\Magento\Directory\Model\ResourceModel\Country\CollectionFactory  $countryCollectionFactory,
CustomerRepositoryInterface  $customerRepository,
\Magento\Framework\App\Http\Context  $httpContext,
\Magento\Quote\Model\Quote\AddressFactory  $addressFactory,
array  $data = [] 
)
Parameters
\Magento\Framework\View\Element\Template\Context$context
\Magento\Customer\Model\Session$customerSession
\Magento\Checkout\Model\Session$resourceSession
\Magento\Directory\Model\ResourceModel\Country\CollectionFactory$countryCollectionFactory
CustomerRepositoryInterface$customerRepository
\Magento\Framework\App\Http\Context$httpContext
Quote\AddressFactory$addressFactory
array$data

Definition at line 84 of file Billing.php.

93  {
94  $this->addressFactory = $addressFactory;
95  $this->_isScopePrivate = true;
96  $this->httpContext = $httpContext;
97  $this->customerRepository = $customerRepository;
98  $this->checkoutSession = $resourceSession;
99  $this->customerSession = $customerSession;
100  $this->countryCollectionFactory = $countryCollectionFactory;
101  parent::__construct($context, $data);
102  }

Member Function Documentation

◆ _construct()

_construct ( )
protected

Initialize billing address step

Returns
void

Definition at line 109 of file Billing.php.

110  {
111  $this->getCheckout()->setStepData(
112  'billing',
113  ['label' => __('Billing Information'), 'is_show' => true]
114  );
115 
116  if ($this->isCustomerLoggedIn()) {
117  $this->getCheckout()->setStepData('billing', 'allow', true);
118  }
119  parent::_construct();
120  }
__()
Definition: __.php:13

◆ _getCustomer()

_getCustomer ( )
protected

Get logged in customer

Returns
\Magento\Customer\Api\Data\CustomerInterface

Definition at line 268 of file Billing.php.

269  {
270  if (empty($this->customer)) {
271  $this->customer = $this->customerRepository->getById($this->customerSession->getCustomerId());
272  }
273  return $this->customer;
274  }

◆ _getTaxvat()

_getTaxvat ( )
protected

Get Customer Taxvat Widget block

Returns
\Magento\Customer\Block\Widget\Taxvat

Definition at line 197 of file Billing.php.

198  {
199  if (!$this->taxvat) {
200  $this->taxvat = $this->getLayout()->createBlock(\Magento\Customer\Block\Widget\Taxvat::class);
201  }
202 
203  return $this->taxvat;
204  }

◆ canShip()

canShip ( )

Check is Quote items can ship to

Returns
bool

Definition at line 180 of file Billing.php.

181  {
182  return !$this->getQuote()->isVirtual();
183  }

◆ getAddress()

getAddress ( )

Return Sales Quote Address model

Returns
\Magento\Quote\Model\Quote\Address

Definition at line 233 of file Billing.php.

234  {
235  if ($this->address === null) {
236  if ($this->isCustomerLoggedIn() || $this->getQuote()->getBillingAddress()) {
237  $this->address = $this->getQuote()->getBillingAddress();
238  if (!$this->address->getFirstname()) {
239  $this->address->setFirstname($this->getQuote()->getCustomer()->getFirstname());
240  }
241  if (!$this->address->getLastname()) {
242  $this->address->setLastname($this->getQuote()->getCustomer()->getLastname());
243  }
244  } else {
245  $this->address = $this->addressFactory->create();
246  }
247  }
248 
249  return $this->address;
250  }

◆ getCheckout()

getCheckout ( )

Retrieve checkout session model

Returns
\Magento\Checkout\Model\Session

Definition at line 281 of file Billing.php.

◆ getConfig()

getConfig (   $path)

Get config

Parameters
string$path
Returns
string|null

Definition at line 258 of file Billing.php.

259  {
260  return $this->_scopeConfig->getValue($path, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
261  }

◆ getCountries()

getCountries ( )

Return country collection

Returns
\Magento\Directory\Model\ResourceModel\Country\Collection

Definition at line 138 of file Billing.php.

139  {
140  return $this->countryCollectionFactory->create()->loadByStore();
141  }

◆ getFirstname()

getFirstname ( )

Return Customer Address First Name If Sales Quote Address First Name is not defined - return Customer First Name

Returns
string

Definition at line 159 of file Billing.php.

160  {
161  return $this->getAddress()->getFirstname();
162  }

◆ getLastname()

getLastname ( )

Return Customer Address Last Name If Sales Quote Address Last Name is not defined - return Customer Last Name

Returns
string

Definition at line 170 of file Billing.php.

171  {
172  return $this->getAddress()->getLastname();
173  }

◆ getMethod()

getMethod ( )

Return checkout method

Returns
string

Definition at line 148 of file Billing.php.

149  {
150  return $this->getQuote()->getCheckoutMethod();
151  }

◆ getQuote()

getQuote ( )

Retrieve sales quote model

Returns
Quote

Definition at line 291 of file Billing.php.

292  {
293  if (empty($this->quote)) {
294  $this->quote = $this->getCheckout()->getQuote();
295  }
296  return $this->quote;
297  }

◆ getSaveUrl()

getSaveUrl ( )
Returns
void

Definition at line 188 of file Billing.php.

189  {
190  }

◆ getTaxvatHtml()

getTaxvatHtml ( )
Returns
string

Definition at line 219 of file Billing.php.

220  {
221  return $this->_getTaxvat()
222  ->setTaxvat($this->getQuote()->getCustomerTaxvat())
223  ->setFieldIdFormat('billing:%s')
224  ->setFieldNameFormat('billing[%s]')
225  ->toHtml();
226  }

◆ isCustomerLoggedIn()

isCustomerLoggedIn ( )
Returns
bool

Definition at line 302 of file Billing.php.

303  {
304  return $this->httpContext->getValue(\Magento\Customer\Model\Context::CONTEXT_AUTH);
305  }

◆ isTaxvatEnabled()

isTaxvatEnabled ( )

Check whether taxvat is enabled

Returns
bool

Definition at line 211 of file Billing.php.

212  {
213  return $this->_getTaxvat()->isEnabled();
214  }

◆ isUseBillingAddressForShipping()

isUseBillingAddressForShipping ( )
Returns
bool

Definition at line 125 of file Billing.php.

126  {
127  if ($this->getQuote()->getIsVirtual() || !$this->getQuote()->getShippingAddress()->getSameAsBilling()) {
128  return false;
129  }
130  return true;
131  }

Field Documentation

◆ $address

$address
protected

Definition at line 25 of file Billing.php.

◆ $addressFactory

$addressFactory
protected

Definition at line 37 of file Billing.php.

◆ $checkoutSession

$checkoutSession
protected

Definition at line 52 of file Billing.php.

◆ $countryCollectionFactory

$countryCollectionFactory
protected

Definition at line 72 of file Billing.php.

◆ $customer

$customer
protected

Definition at line 42 of file Billing.php.

◆ $customerRepository

$customerRepository
protected

Definition at line 62 of file Billing.php.

◆ $customerSession

$customerSession
protected

Definition at line 57 of file Billing.php.

◆ $httpContext

$httpContext
protected

Definition at line 67 of file Billing.php.

◆ $quote

$quote
protected

Definition at line 47 of file Billing.php.

◆ $taxvat

$taxvat
protected

Definition at line 32 of file Billing.php.


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