Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Dashboard.php
Go to the documentation of this file.
1 <?php
7 
10 
18 {
22  protected $subscription;
23 
27  protected $customerSession;
28 
32  protected $subscriberFactory;
33 
38 
43 
54  public function __construct(
55  \Magento\Framework\View\Element\Template\Context $context,
56  \Magento\Customer\Model\Session $customerSession,
57  \Magento\Newsletter\Model\SubscriberFactory $subscriberFactory,
60  array $data = []
61  ) {
62  $this->customerSession = $customerSession;
63  $this->subscriberFactory = $subscriberFactory;
64  $this->customerRepository = $customerRepository;
65  $this->customerAccountManagement = $customerAccountManagement;
66  parent::__construct($context, $data);
67  }
68 
74  public function getCustomer()
75  {
76  return $this->customerRepository->getById($this->customerSession->getCustomerId());
77  }
78 
84  public function getAccountUrl()
85  {
86  return $this->_urlBuilder->getUrl('customer/account/edit', ['_secure' => true]);
87  }
88 
94  public function getAddressesUrl()
95  {
96  return $this->_urlBuilder->getUrl('customer/address/index', ['_secure' => true]);
97  }
98 
105  public function getAddressEditUrl($address)
106  {
107  return $this->_urlBuilder->getUrl(
108  'customer/address/edit',
109  ['_secure' => true, 'id' => $address->getId()]
110  );
111  }
112 
118  public function getOrdersUrl()
119  {
120  return $this->_urlBuilder->getUrl('customer/order/index', ['_secure' => true]);
121  }
122 
128  public function getReviewsUrl()
129  {
130  return $this->_urlBuilder->getUrl('review/customer/index', ['_secure' => true]);
131  }
132 
138  public function getWishlistUrl()
139  {
140  return $this->_urlBuilder->getUrl('customer/wishlist/index', ['_secure' => true]);
141  }
142 
148  public function getSubscriptionObject()
149  {
150  if ($this->subscription === null) {
151  $this->subscription =
152  $this->_createSubscriber()->loadByCustomerId($this->customerSession->getCustomerId());
153  }
154 
155  return $this->subscription;
156  }
157 
163  public function getManageNewsletterUrl()
164  {
165  return $this->getUrl('newsletter/manage');
166  }
167 
173  public function getSubscriptionText()
174  {
175  if ($this->getSubscriptionObject()->isSubscribed()) {
176  return __('You are subscribed to our newsletter.');
177  }
178 
179  return __('You aren\'t subscribed to our newsletter.');
180  }
181 
187  public function getPrimaryAddresses()
188  {
189  $addresses = [];
190  $customerId = $this->getCustomer()->getId();
191 
192  if ($defaultBilling = $this->customerAccountManagement->getDefaultBillingAddress($customerId)) {
193  $addresses[] = $defaultBilling;
194  }
195 
196  if ($defaultShipping = $this->customerAccountManagement->getDefaultShippingAddress($customerId)) {
197  if ($defaultBilling) {
198  if ($defaultBilling->getId() != $defaultShipping->getId()) {
199  $addresses[] = $defaultShipping;
200  }
201  } else {
202  $addresses[] = $defaultShipping;
203  }
204  }
205 
206  return empty($addresses) ? false : $addresses;
207  }
208 
218  public function getBackUrl()
219  {
220  // the RefererUrl must be set in appropriate controller
221  if ($this->getRefererUrl()) {
222  return $this->getRefererUrl();
223  }
224  return $this->getUrl('customer/account/');
225  }
226 
232  protected function _createSubscriber()
233  {
234  return $this->subscriberFactory->create();
235  }
236 }
return false
Definition: gallery.phtml:36
$addresses
Definition: address_list.php:7
__()
Definition: __.php:13
$address
Definition: customer.php:38
__construct(\Magento\Framework\View\Element\Template\Context $context, \Magento\Customer\Model\Session $customerSession, \Magento\Newsletter\Model\SubscriberFactory $subscriberFactory, CustomerRepositoryInterface $customerRepository, AccountManagementInterface $customerAccountManagement, array $data=[])
Definition: Dashboard.php:54