Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Info.php
Go to the documentation of this file.
1 <?php
7 
9 
17 {
23  protected $_subscription;
24 
29 
33  protected $_helperView;
34 
38  protected $currentCustomer;
39 
49  public function __construct(
50  \Magento\Framework\View\Element\Template\Context $context,
51  \Magento\Customer\Helper\Session\CurrentCustomer $currentCustomer,
52  \Magento\Newsletter\Model\SubscriberFactory $subscriberFactory,
53  \Magento\Customer\Helper\View $helperView,
54  array $data = []
55  ) {
56  $this->currentCustomer = $currentCustomer;
57  $this->_subscriberFactory = $subscriberFactory;
58  $this->_helperView = $helperView;
59  parent::__construct($context, $data);
60  }
61 
67  public function getCustomer()
68  {
69  try {
70  return $this->currentCustomer->getCustomer();
71  } catch (NoSuchEntityException $e) {
72  return null;
73  }
74  }
75 
81  public function getName()
82  {
83  return $this->_helperView->getCustomerName($this->getCustomer());
84  }
85 
89  public function getChangePasswordUrl()
90  {
91  return $this->_urlBuilder->getUrl('customer/account/edit/changepass/1');
92  }
93 
99  public function getSubscriptionObject()
100  {
101  if (!$this->_subscription) {
102  $this->_subscription = $this->_createSubscriber();
103  $customer = $this->getCustomer();
104  if ($customer) {
105  $this->_subscription->loadByCustomerId($customer->getId());
106  }
107  }
108  return $this->_subscription;
109  }
110 
118  public function getIsSubscribed()
119  {
120  return $this->getSubscriptionObject()->isSubscribed();
121  }
122 
128  public function isNewsletterEnabled()
129  {
130  return $this->getLayout()
131  ->getBlockSingleton(\Magento\Customer\Block\Form\Register::class)
132  ->isNewsletterEnabled();
133  }
134 
138  protected function _createSubscriber()
139  {
140  return $this->_subscriberFactory->create();
141  }
142 
146  protected function _toHtml()
147  {
148  return $this->currentCustomer->getCustomerId() ? parent::_toHtml() : '';
149  }
150 }
__construct(\Magento\Framework\View\Element\Template\Context $context, \Magento\Customer\Helper\Session\CurrentCustomer $currentCustomer, \Magento\Newsletter\Model\SubscriberFactory $subscriberFactory, \Magento\Customer\Helper\View $helperView, array $data=[])
Definition: Info.php:49
$customer
Definition: customers.php:11