0

Actually i am trying like this

mage\app\code\Inkind\Navdata\Block\Index\Current.php

<?php
namespace Inkind\Navdata\Block\Index;
class Current extends \Magento\Framework\View\Element\Template
{ 
    private $_objectManager; 
    protected $_customerSession; 
    protected $_customer; 
    public function __construct(
        \Magento\Framework\View\Element\Template\Context $context,
        \Magento\Framework\ObjectManagerInterface $objectmanager, 
        \Magento\Customer\Model\Session $customerSession, 
        \Magento\Customer\Model\Customer $customer
    ){
        $this->_objectManager = $objectmanager; 
        $this->_customerSession = $customerSession; 
        $this->_customer = $customer; 
        parent::__construct($context);
    }

   public function getCurrentCustomer() 
    { 
    echo "Test";die;
        $context = $this->_objectManager->get('Magento\Framework\App\Http\Context'); 
        $isLoggedIn = $context->getValue(\Magento\Customer\Model\Context::CONTEXT_AUTH); 
        $customerSession = $this->_objectManager->create('Magento\Customer\Model\SessionFactory')->create(); 
        echo "1";
        if ($isLoggedIn == 1) { 
        echo "2";
            $customer_id = $customerSession->getCustomer()->getId(); 
            $customerData = $this->_customer->load($customer_id); 
            $data['name'] = $customerData->getName();
            $data['email'] = $customerData->getEmail();
            //return $data; 
        } 
    } 

        /* public function getCustomerName(){
        return $this->_customerSession->getCustomer()->getName();
    } */



}

mage\app\code\Inkind\Navdata\view\frontend\templates\content.phtml

<?php
    $block->getCurrentCustomer();

    //echo $block->getCustomerName();
    //var_dump($customerData);
    //echo $customerData->getName(); 
    //echo $customerData->getEmail(); 
    /* if($isLoggedIn) {
       $customerSession = $objectManager->get('Magento\Customer\Model\Session');
        $customerSession->getCustomer()->getId();  
        $name =   $customerSession->getCustomer()->getName(); 
        $email=  $customerSession->getCustomer()->getEmail(); 
        $customerSession->getCustomer()->getGroupId();  
        $customer_logged_in = $customerSession->isLoggedIn();


    } */

?>

Now i am calling this block with phtml file like below shown

{{block class="Inkind\Navdata\Block\Index" template="Inkind_Navdata::content.phtml"}}
1
  • Any error do you face? Or what you are looking? Sep 26, 2018 at 14:03

1 Answer 1

2

You need to change your line of code in CMS block like this.

{{block class="Inkind\Navdata\Block\Index\Current" template="Inkind_Navdata::content.phtml"}}
1
  • If answer help you, please mark as solution and upvote. So it help other in community. Sep 27, 2018 at 4:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.