Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Billing.php
Go to the documentation of this file.
1 <?php
11 
14 
19 {
25  protected $address;
26 
32  protected $taxvat;
33 
37  protected $addressFactory;
38 
42  protected $customer;
43 
47  protected $quote;
48 
52  protected $checkoutSession;
53 
57  protected $customerSession;
58 
63 
67  protected $httpContext;
68 
73 
84  public function __construct(
85  \Magento\Framework\View\Element\Template\Context $context,
86  \Magento\Customer\Model\Session $customerSession,
87  \Magento\Checkout\Model\Session $resourceSession,
88  \Magento\Directory\Model\ResourceModel\Country\CollectionFactory $countryCollectionFactory,
90  \Magento\Framework\App\Http\Context $httpContext,
91  \Magento\Quote\Model\Quote\AddressFactory $addressFactory,
92  array $data = []
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  }
103 
109  protected function _construct()
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  }
121 
126  {
127  if ($this->getQuote()->getIsVirtual() || !$this->getQuote()->getShippingAddress()->getSameAsBilling()) {
128  return false;
129  }
130  return true;
131  }
132 
138  public function getCountries()
139  {
140  return $this->countryCollectionFactory->create()->loadByStore();
141  }
142 
148  public function getMethod()
149  {
150  return $this->getQuote()->getCheckoutMethod();
151  }
152 
159  public function getFirstname()
160  {
161  return $this->getAddress()->getFirstname();
162  }
163 
170  public function getLastname()
171  {
172  return $this->getAddress()->getLastname();
173  }
174 
180  public function canShip()
181  {
182  return !$this->getQuote()->isVirtual();
183  }
184 
188  public function getSaveUrl()
189  {
190  }
191 
197  protected function _getTaxvat()
198  {
199  if (!$this->taxvat) {
200  $this->taxvat = $this->getLayout()->createBlock(\Magento\Customer\Block\Widget\Taxvat::class);
201  }
202 
203  return $this->taxvat;
204  }
205 
211  public function isTaxvatEnabled()
212  {
213  return $this->_getTaxvat()->isEnabled();
214  }
215 
219  public function getTaxvatHtml()
220  {
221  return $this->_getTaxvat()
222  ->setTaxvat($this->getQuote()->getCustomerTaxvat())
223  ->setFieldIdFormat('billing:%s')
224  ->setFieldNameFormat('billing[%s]')
225  ->toHtml();
226  }
227 
233  public function getAddress()
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  }
251 
258  public function getConfig($path)
259  {
260  return $this->_scopeConfig->getValue($path, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
261  }
262 
268  protected function _getCustomer()
269  {
270  if (empty($this->customer)) {
271  $this->customer = $this->customerRepository->getById($this->customerSession->getCustomerId());
272  }
273  return $this->customer;
274  }
275 
281  public function getCheckout()
282  {
283  return $this->checkoutSession;
284  }
285 
291  public function getQuote()
292  {
293  if (empty($this->quote)) {
294  $this->quote = $this->getCheckout()->getQuote();
295  }
296  return $this->quote;
297  }
298 
302  public function isCustomerLoggedIn()
303  {
304  return $this->httpContext->getValue(\Magento\Customer\Model\Context::CONTEXT_AUTH);
305  }
306 }
__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=[])
Definition: Billing.php:84
__()
Definition: __.php:13