Magento 2.3: Customer ID from Session Returning NULL with Cache EnabledI created a custom module ,but getting error, not able to figure out what the error is about. How to get out of this error?Magento 2: How to override newsletter Subscriber modelMagento 2 : Unable to save data in Sessions with Cache enabledMagento 2 Create dynamic array From different Model Collection to use in multi select in gridMonolog Error After 2.2 UpgradeI am trying to override multishipping.php file in vendor/magento/module-multishipping/Model/Checkout/Type/Multishipping.phpCustomer Session not working on full page cache in magento2Magento 2.3 Can't view module's front end page output?Magento2 REST API get all customers detailsI am getting this error when I installed algolia search module

Linear Combination of Atomic Orbitals

What's the best tool for cutting holes into duct work?

Are there other characters in the Star Wars universe who had damaged bodies and needed to wear an outfit like Darth Vader?

PTIJ: Aliyot for the deceased

How to write a chaotic neutral protagonist and prevent my readers from thinking they are evil?

Why is there an extra space when I type "ls" on the Desktop?

How can I be pwned if I'm not registered on the compromised site?

Is there a way to find out the age of climbing ropes?

Is "cogitate" an appropriate word for this?

Sundering Titan and basic normal lands and snow lands

Are Wave equations equivalent to Maxwell equations in free space?

What does "rhumatis" mean?

What is Tony Stark injecting into himself in Iron Man 3?

Can a Mimic (container form) actually hold loot?

Why would the IRS ask for birth certificates or even audit a small tax return?

Preparing as much as possible of a cake in advance

Short story about an infectious indestructible metal bar?

Why doesn't "adolescent" take any articles in "listen to adolescent agonising"?

The (Easy) Road to Code

Should I use HTTPS on a domain that will only be used for redirection?

Where is the fallacy here?

Is this nominative case or accusative case?

Can you run a ground wire from stove directly to ground pole in the ground

Quitting employee has privileged access to critical information



Magento 2.3: Customer ID from Session Returning NULL with Cache Enabled


I created a custom module ,but getting error, not able to figure out what the error is about. How to get out of this error?Magento 2: How to override newsletter Subscriber modelMagento 2 : Unable to save data in Sessions with Cache enabledMagento 2 Create dynamic array From different Model Collection to use in multi select in gridMonolog Error After 2.2 UpgradeI am trying to override multishipping.php file in vendor/magento/module-multishipping/Model/Checkout/Type/Multishipping.phpCustomer Session not working on full page cache in magento2Magento 2.3 Can't view module's front end page output?Magento2 REST API get all customers detailsI am getting this error when I installed algolia search module













0















I'm calling the following helper but getCustomerId is returning NULL when I have cache enabled. If I disable all cache, then I can return the customer's ID.



<?php
namespace CompanyModuleHelper;

class Data extends MagentoFrameworkAppHelperAbstractHelper

private $_customerSession;

public function __construct (
MagentoCustomerModelSession $customerSession
)
$this->_customerSession = $customerSession;


public function getCustomerId()

return $this->_customerSession->getCustomerId();




I've also tried return $this->_customerSession->getCustomer()->getId(); which also returns NULL




Now if I inject the Object Manager instead, I get my desired result and it returns the customerId even with cache enabled:



...
public function __construct(
MagentoFrameworkObjectManagerInterface $objectmanager
)
$this->_objectManager = $objectmanager;


public function isBrandingCustomer()

$customerSession = $this->_objectManager->create("MagentoCustomerModelSession");
return $customerSession->getCustomerId();

...


So my question is, How can I return the customer's ID from $customerSession with cache enabled and without using Object Manager?










share|improve this question


























    0















    I'm calling the following helper but getCustomerId is returning NULL when I have cache enabled. If I disable all cache, then I can return the customer's ID.



    <?php
    namespace CompanyModuleHelper;

    class Data extends MagentoFrameworkAppHelperAbstractHelper

    private $_customerSession;

    public function __construct (
    MagentoCustomerModelSession $customerSession
    )
    $this->_customerSession = $customerSession;


    public function getCustomerId()

    return $this->_customerSession->getCustomerId();




    I've also tried return $this->_customerSession->getCustomer()->getId(); which also returns NULL




    Now if I inject the Object Manager instead, I get my desired result and it returns the customerId even with cache enabled:



    ...
    public function __construct(
    MagentoFrameworkObjectManagerInterface $objectmanager
    )
    $this->_objectManager = $objectmanager;


    public function isBrandingCustomer()

    $customerSession = $this->_objectManager->create("MagentoCustomerModelSession");
    return $customerSession->getCustomerId();

    ...


    So my question is, How can I return the customer's ID from $customerSession with cache enabled and without using Object Manager?










    share|improve this question
























      0












      0








      0








      I'm calling the following helper but getCustomerId is returning NULL when I have cache enabled. If I disable all cache, then I can return the customer's ID.



      <?php
      namespace CompanyModuleHelper;

      class Data extends MagentoFrameworkAppHelperAbstractHelper

      private $_customerSession;

      public function __construct (
      MagentoCustomerModelSession $customerSession
      )
      $this->_customerSession = $customerSession;


      public function getCustomerId()

      return $this->_customerSession->getCustomerId();




      I've also tried return $this->_customerSession->getCustomer()->getId(); which also returns NULL




      Now if I inject the Object Manager instead, I get my desired result and it returns the customerId even with cache enabled:



      ...
      public function __construct(
      MagentoFrameworkObjectManagerInterface $objectmanager
      )
      $this->_objectManager = $objectmanager;


      public function isBrandingCustomer()

      $customerSession = $this->_objectManager->create("MagentoCustomerModelSession");
      return $customerSession->getCustomerId();

      ...


      So my question is, How can I return the customer's ID from $customerSession with cache enabled and without using Object Manager?










      share|improve this question














      I'm calling the following helper but getCustomerId is returning NULL when I have cache enabled. If I disable all cache, then I can return the customer's ID.



      <?php
      namespace CompanyModuleHelper;

      class Data extends MagentoFrameworkAppHelperAbstractHelper

      private $_customerSession;

      public function __construct (
      MagentoCustomerModelSession $customerSession
      )
      $this->_customerSession = $customerSession;


      public function getCustomerId()

      return $this->_customerSession->getCustomerId();




      I've also tried return $this->_customerSession->getCustomer()->getId(); which also returns NULL




      Now if I inject the Object Manager instead, I get my desired result and it returns the customerId even with cache enabled:



      ...
      public function __construct(
      MagentoFrameworkObjectManagerInterface $objectmanager
      )
      $this->_objectManager = $objectmanager;


      public function isBrandingCustomer()

      $customerSession = $this->_objectManager->create("MagentoCustomerModelSession");
      return $customerSession->getCustomerId();

      ...


      So my question is, How can I return the customer's ID from $customerSession with cache enabled and without using Object Manager?







      magento2 php magento2.3 customer-session






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 7 hours ago









      AJ47AJ47

      295217




      295217




















          0






          active

          oldest

          votes











          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "479"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f264922%2fmagento-2-3-customer-id-from-session-returning-null-with-cache-enabled%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Magento Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f264922%2fmagento-2-3-customer-id-from-session-returning-null-with-cache-enabled%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          六本木駅

          Integral that is continuous and looks like it converges to a geometric seriesTesting if a geometric series converges by taking limit to infinitySummation of arithmetic-geometric series of higher orderGeometric series with polynomial exponentHow to Recognize a Geometric SeriesShowing an integral equality with series over the integersDiscontinuity of a series of continuous functionsReasons why a Series ConvergesSum of infinite geometric series with two terms in summationUsing geometric series for computing IntegralsLimit of geometric series sum when $r = 1$

          Joseph Lister