I have created the custom link in customer account left navigation. I am successfully created it.
I am trying to get current customer Data in template file. I am getting 500 server error. Below is the code i used in my block file
class Lists extends \Magento\Framework\View\Element\Template
{
protected $helperData;
public function __construct(
\[vendor]\[Module]\Helper\Data $helperData,
) {
$this->helperData = $helperData;
}
public function _prepareLayout()
{
return parent::_prepareLayout();
}
public function currentCustomer(){
return $this->helperData->getCurrentCustomer();
}
}
Used like below in template file.
$customerObj = $this->currentCustomer();
echo '<pre>';
print_r($customerObj);die;
Helper file is like below.
class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
protected $customerSession;
protected $customerRepository;
public function __construct(
\Magento\Framework\App\Helper\Context $context,
\Magento\Customer\Model\Session $customerSession,
\Magento\Customer\Api\CustomerRepositoryInterface $customerRepository
) {
$this->customerSession = $customerSession;
$this->customerRepository = $customerRepository;
parent::__construct($context);
}
public function getCurrentCustomer() {
$customer = $this->customerSession->getCustomer();
$customerId = $customer->getId();
$customer = $this->customerRepository->getById($customerId);
return $customer;
}
}
Please anyone look the code and suggest me.Thanks