Last active
November 19, 2019 20:04
-
-
Save veritstudio/478c738cd3053395c11d169903b04d4c to your computer and use it in GitHub Desktop.
Get customer details - Magento 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace VeritStudio\CustomModule\Block; | |
use Magento\Customer\Model\Session; | |
class CustomBlock extends \Magento\Framework\View\Element\Template { | |
public function __construct( | |
Session $customerSession, | |
\Magento\Framework\View\Element\Template\Context $context | |
) | |
{ | |
parent::__construct($context); | |
$this->_customerSession = $customerSession; | |
} | |
public function getCustomerId(){ | |
return $this->_customerSession->getCustomer()->getId(); | |
} | |
public function getCustomerName(){ | |
return $this->_customerSession->getCustomer()->getName(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<block class="VeritStudio\CustomModule\Block\CustomBlock" name="customer.details" template="VeritStudio_CustomModule::details.phtml" cacheable="false" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div> | |
<p><?= __('Hello %s', $block->getCustomerName()) ?></p> | |
<p><?= __('Your customer id is %s, block->getCustomerId()) ?></p> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment