Advertisement
Guest User

Untitled

a guest
Dec 14th, 2018
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.12 KB | None | 0 0
  1. <?php
  2. namespace Wildwoman\LoggedInChecker\Block;
  3.  
  4. use Magento\Framework\View\Element\Template as Template;
  5. use Magento\Framework\App\Http\Context as CustomerContext;
  6.  
  7. class Checker extends Template
  8. {
  9.    
  10.    
  11.     /**
  12.      * Current template name
  13.      *
  14.      * @var string
  15.      */
  16.     protected $_template = 'Wildwoman_LoggedInChecker::checker.phtml';
  17.  
  18.     /**
  19.      * @var CustomerContext
  20.      */
  21.     protected $customerContext;
  22.  
  23.     /**
  24.      *  constructor.
  25.      *
  26.      * @param Context $context
  27.      * @param CustomerContext $customerContext
  28.      * @param array $data
  29.      */
  30.     public function __construct(
  31.         Context $context,
  32.         CustomerContext $customerContext,
  33.         array $data = []
  34.     ) {
  35.         $this->customerContext = $customerContext;
  36.         parent::__construct($context, $data);
  37.     }
  38.  
  39.     /**
  40.      * Check is Customer Logged In
  41.      *
  42.      * @return int
  43.      */
  44.     public function isCustomerLoggedIn()
  45.     {
  46.         $isLoggedIn = $this->customerContext->getValue(\Magento\Customer\Model\Context::CONTEXT_AUTH);
  47.         return $isLoggedIn ? 1 : 0 ;
  48.     }
  49.    
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement