Now compatible with Magento 2.4.4 PHP 8.1 Check new release of Improved Import & Export
FireBear Blog
  • M2 Extensions
    • Improved Import
    • SAP Business One
    • ICP
  • Demo
  • Blog
    • Must have M2 Extensions
    • M2 Extensions Reviews
    • M2 Extensions Compared
    • Magento 2 B2B
    • Magento® 2 Extensions
    • Magento Performance
    • Magento SEO
    • Magento 2
      • Magento 2 Tutorial
      • Magento 2 Extensions
      • Magento 2 Cookbook
    • E-Commerce
    • Our extensions
    • Magento tips
    • Cryptocurrency
      • Ethereum
      • BitCoin
  • Contact Us
  • Services
    • ERP Integration
    • CRM Integration
    • Accounting integration
    • Migration to M2

Search on Firebear Studio blog

Firebear Studio

How to check if customer is logged into Magento 2

December 4, 2015 - Fire development, Magento 2

Magento 2 Development

In Magento 2, to check if customer is logged in, use the following code:

1
2
3
4
5
6
/** @var \Magento\Framework\App\ObjectManager $om */
$om = \Magento\Framework\App\ObjectManager::getInstance();
/** @var \Magento\Framework\App\Http\Context $context */
$context = $om->get('Magento\Framework\App\Http\Context');
/** @var bool $isLoggedIn */
$isLoggedIn = $context->getValue(\Magento\Customer\Model\Context::CONTEXT_AUTH);

Source (Stackexchange Question)(Marius♦ and Mage2.PRO)

More tips from the Cookbook

Related posts

  • How to import product images in Magento 2 when they already exist in pub/mediaHow to import product images in Magento 2 when they already exist in pub/media
  • How to fix “The source file moving process failed” error in Magento 2How to fix “The source file moving process failed” error in Magento 2
  • How to use external image URLs in Magento 2 importHow to use external image URLs in Magento 2 import
  • How To Add ‘Delete Confirmation Popup’ In Magento 2 For Default Import Functionality How To Add ‘Delete Confirmation Popup’ In Magento 2 For Default Import Functionality 
  • How to export Page Builder pages or templates in Magento 2?How to export Page Builder pages or templates in Magento 2?
  • The Ultimate Guide To Magento 2 Integration (API, IPAAS, ESB, ETL, automation, no-code, consultancy)The Ultimate Guide To Magento 2 Integration (API, IPAAS, ESB, ETL, automation, no-code, consultancy)
  • The Ultimate Guide To ERPNext Integration (API, IPAAS, ESB, ETL, automation, no-code, solution architecture, consultancy)The Ultimate Guide To ERPNext Integration (API, IPAAS, ESB, ETL, automation, no-code, solution architecture, consultancy)
  • Magento 2 Release NotesMagento 2 Release Notes
Post Tags:customerloginmagento 2Magento 2 Developer’s Cookbook
Homepage » Fire development » How to check if customer is logged into Magento 2
← Previous Post Next Post →


Index

  • Magento 2 In-Depth Review
  • Magento 2 Import & Export Guide
  • Must have Magento 2 Extensions
  • Magento 2 Extensions Reviews
  • Magento 2 Extensions Comparisons
  • Magento 2 Cookbook
  • Magento® 2 Tutorial
  • Magento 2 Templates
  • Improved Import Magento 2 Extension
  • Improved Configurable Product Magento 2 Extension

Newsletter

customer

  • Magento 2 Custom Order Number by Ulmod

    Customs numbers are useful to ecommerce businesses and look more professional to customers.  It helps you provide a positive impact… Read more…

  • How to get default billing and shipping address by customer in Magento 2

    The following article sheds light on how to get default billing and shipping address by a customer in Magento 2.… Read more…

  • Magento 2 Customer Approval by Ulmod

    Many stores owners always complain about their Magento 2 webshop getting flooded with fake customer registrations and their get tired… Read more…

  • Magento 2 Minimum Order Amount for Customer Group Extension by MageAnts

    It happens at times that customers just take a stroll on your online store and place an order of a… Read more…

  • How to get Customer in product view in Magento 2

    You can get customer_id, getName(), and getEmail() in the product view in Magento 2 directly from customer session. Utilize the… Read more…

  • How to check if customer is logged into Magento 2

    In Magento 2, to check if customer is logged in, use the following code: [crayon-63d7c9c8b1b70930753135/] Source (Stackexchange Question)(Marius♦ and Mage2.PRO)… Read more…

Top E-Commerce

Don't Miss

How to enable profiler in Magento 2

On September 7, 2015
  • Contact Us
  • Archives
  • Magento extensions
© 2018 Firebear Studio
Magento® is a registered trademark of Magento Inc.