Why is Magento 2 not getting customer data from block?

Why is Magento 2 not getting customer data from block?

While we are injecting customer session in block to retrive logged in customer data and we are not getting customer data from block because Magento 2 reset all the customer sessions when FPC is enabled. In this case, Magento 2 ignore this page from caching.

How to display customer name when logged in Magento 2?

Then call your block function from your phtml file. Some case: Bug of Magento 2 when you turn on caches. You must reload customer sections when customer logged in. Check etc/sections.xml and customer-data.js you will know how to reload customer sections.

How to get customer ID from block class?

If you need only the customer_id then without loading whole object (see method getCustomer method) you can get it by simply using getCustomerId method. As getId method also calls getCustomerId method.

How to get customer ID from session in Magento?

When You define block which use session You have to disable cache for it. You need to inject \\Magento\\Customer\\Model\\Session $customerSession, class to get customer ID from customer session. protected $_customerSession; public function __construct (

How to get block data from phtml template?

Suppose if your route is xxxx and controller file name is Index.php and method name is Index then you need to create xxxx_index_index.xml file under this path xxxx\\Trails\\view\\frontend\\layout. You did the mistake. You can’t render a block using below code from controller

How to get customer info from Magento table structure?

Any straight query is not guaranteed to be compatible with different Magento versions and even installations of same version. 2) Magento EAV structure does not allow you to fetch all customer data in a nice form within one query, because table names are matched to attributes dynamically.

Can you get customer data from MySQL in Magento?

1) Magento is built to be configurable, so that you must not fetch data from MySQL, but you must use Magento Customer module (models, resource models) and Magento configuration data to retrieve customer data. Any straight query is not guaranteed to be compatible with different Magento versions and even installations of same version.

How to check if customer is logged in or not?

It is possible via Magento\\Framework\\App\\Http\\Context or via Magento\\Customer\\Model\\Session. However, the result may be different:

How to use auto generated object factories in Magento 2.0?

This is the WRONG methodology to use in Magento2.0. In 2.0, the auto generated object factories are the way to go. You can inject them into your constructor in almost any class and use them. Example: