Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Shipping.php
Go to the documentation of this file.
1 <?php
11 
14 
16 {
22  protected $address = null;
23 
27  protected $addressFactory;
28 
32  protected $customer;
33 
37  protected $quote;
38 
42  protected $checkoutSession;
43 
48 
52  protected $httpContext;
53 
57  protected $customerSession;
58 
68  public function __construct(
69  \Magento\Framework\View\Element\Template\Context $context,
70  \Magento\Customer\Model\Session $customerSession,
71  \Magento\Checkout\Model\Session $resourceSession,
73  \Magento\Framework\App\Http\Context $httpContext,
74  \Magento\Quote\Model\Quote\AddressFactory $addressFactory,
75  array $data = []
76  ) {
77  $this->addressFactory = $addressFactory;
78  $this->_isScopePrivate = true;
79  $this->httpContext = $httpContext;
80  $this->customerRepository = $customerRepository;
81  $this->checkoutSession = $resourceSession;
82  $this->customerSession = $customerSession;
83  parent::__construct($context, $data);
84  }
85 
91  protected function _construct()
92  {
93  $this->checkoutSession->setStepData(
94  'shipping',
95  ['label' => __('Shipping Information'), 'is_show' => $this->isShow()]
96  );
97 
98  parent::_construct();
99  }
100 
106  public function getMethod()
107  {
108  return $this->getQuote()->getCheckoutMethod();
109  }
110 
116  public function isShow()
117  {
118  return !$this->getQuote()->isVirtual();
119  }
120 
126  public function getAddress()
127  {
128  if ($this->address === null) {
129  if ($this->isCustomerLoggedIn() || $this->getQuote()->getShippingAddress()) {
130  $this->address = $this->getQuote()->getShippingAddress();
131  } else {
132  $this->address = $this->addressFactory->create();
133  }
134  }
135 
136  return $this->address;
137  }
138 
145  public function getConfig($path)
146  {
147  return $this->_scopeConfig->getValue($path, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
148  }
149 
155  protected function _getCustomer()
156  {
157  if (empty($this->customer)) {
158  $this->customer = $this->customerRepository->getById($this->customerSession->getCustomerId());
159  }
160  return $this->customer;
161  }
162 
168  public function getQuote()
169  {
170  if (empty($this->quote)) {
171  $this->quote = $this->checkoutSession->getQuote();
172  }
173  return $this->quote;
174  }
175 
179  public function isCustomerLoggedIn()
180  {
181  return $this->httpContext->getValue(\Magento\Customer\Model\Context::CONTEXT_AUTH);
182  }
183 }
__()
Definition: __.php:13
__construct(\Magento\Framework\View\Element\Template\Context $context, \Magento\Customer\Model\Session $customerSession, \Magento\Checkout\Model\Session $resourceSession, CustomerRepositoryInterface $customerRepository, \Magento\Framework\App\Http\Context $httpContext, \Magento\Quote\Model\Quote\AddressFactory $addressFactory, array $data=[])
Definition: Shipping.php:68