Cache breaks my check for detecting if a customer is logged inMagento 2: check customer logged in by javascript use modelCheck whether customer is loggedin in Magento 2 model classMagento2: How to update the product price programaticallycustomer session does not work except customer page - Magento 2Magento 2: get customer id of logged in user with cache enabledMagentoCustomerModelCustomer::__construct() must be an instance of MagentoFrameworkModelContextCustomer session for logged in customer by token based authenticationMagento get Customer Data from session idMagento 2.2.4 unable to get customer session dataMagento2 REST API get all customers detailsMagento 2.3 error after cache flush or clean
How do you say “buy” in the sense of “believe”?
Tic-tac-toe for the terminal, written in C
How strong are Wi-Fi signals?
Placing bypass capacitors after VCC reaches the IC
Full backup on database creation
How to capture more stars?
I unknowingly submitted plagiarised work
Is there a public standard for 8 and 10 character grid locators?
What is the most important source of natural gas? coal, oil or other?
Were pens caps holes designed to prevent death by suffocation if swallowed?
Is there a general effective method to solve Smullyan style Knights and Knaves problems? Is the truth table method the most appropriate one?
How does an ARM MCU run faster than the external crystal?
Integrating an absolute function using Mathematica
Can you heal a summoned creature?
Full horizontal justification in table
How did early x86 BIOS programmers manage to program full blown TUIs given very few bytes of ROM/EPROM?
Why does the 'metric Lagrangian' approach appear to fail in Newtonian mechanics?
Would jet fuel for an F-16 or F-35 be producible during WW2?
In general, would I need to season a meat when making a sauce?
When and what was the first 3D acceleration device ever released?
Employer asking for online access to bank account - Is this a scam?
Different circular sectors as new logo of the International System
Infinite Sequence based on Simple Rule
Crossing US border with music files I'm legally allowed to possess
Cache breaks my check for detecting if a customer is logged in
Magento 2: check customer logged in by javascript use modelCheck whether customer is loggedin in Magento 2 model classMagento2: How to update the product price programaticallycustomer session does not work except customer page - Magento 2Magento 2: get customer id of logged in user with cache enabledMagentoCustomerModelCustomer::__construct() must be an instance of MagentoFrameworkModelContextCustomer session for logged in customer by token based authenticationMagento get Customer Data from session idMagento 2.2.4 unable to get customer session dataMagento2 REST API get all customers detailsMagento 2.3 error after cache flush or clean
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
When I turned off cache (bin/magento cache:disable) the below code works otherwise it's not working.
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$customerSession = $objectManager->get('MagentoCustomerModelSession');
if($customerSession->isLoggedIn())
echo "logged in";
else
echo "no logged";
magento2 customer cache
add a comment |
When I turned off cache (bin/magento cache:disable) the below code works otherwise it's not working.
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$customerSession = $objectManager->get('MagentoCustomerModelSession');
if($customerSession->isLoggedIn())
echo "logged in";
else
echo "no logged";
magento2 customer cache
bin/magento cache:disable if i go guest i got no logged if i go customer i got loged. bin/magento cache:enable if i go guest i got no loged if go customer ig ot no loged
– Ibrahim Aldar
May 21 at 13:23
1
The response is just getting cached. Itt will work on first load however remain the same for each request thereafter if that is what you are experiencing. There are Javascript alternatives for this that will work magento.stackexchange.com/questions/263905/…
– harri
May 21 at 13:33
You can NOT use the code like this. where you want to use check customer session?
– Amit Bera♦
May 21 at 13:39
add a comment |
When I turned off cache (bin/magento cache:disable) the below code works otherwise it's not working.
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$customerSession = $objectManager->get('MagentoCustomerModelSession');
if($customerSession->isLoggedIn())
echo "logged in";
else
echo "no logged";
magento2 customer cache
When I turned off cache (bin/magento cache:disable) the below code works otherwise it's not working.
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$customerSession = $objectManager->get('MagentoCustomerModelSession');
if($customerSession->isLoggedIn())
echo "logged in";
else
echo "no logged";
magento2 customer cache
magento2 customer cache
edited May 21 at 13:31
harri
3,13611661
3,13611661
asked May 21 at 13:22
Ibrahim AldarIbrahim Aldar
283
283
bin/magento cache:disable if i go guest i got no logged if i go customer i got loged. bin/magento cache:enable if i go guest i got no loged if go customer ig ot no loged
– Ibrahim Aldar
May 21 at 13:23
1
The response is just getting cached. Itt will work on first load however remain the same for each request thereafter if that is what you are experiencing. There are Javascript alternatives for this that will work magento.stackexchange.com/questions/263905/…
– harri
May 21 at 13:33
You can NOT use the code like this. where you want to use check customer session?
– Amit Bera♦
May 21 at 13:39
add a comment |
bin/magento cache:disable if i go guest i got no logged if i go customer i got loged. bin/magento cache:enable if i go guest i got no loged if go customer ig ot no loged
– Ibrahim Aldar
May 21 at 13:23
1
The response is just getting cached. Itt will work on first load however remain the same for each request thereafter if that is what you are experiencing. There are Javascript alternatives for this that will work magento.stackexchange.com/questions/263905/…
– harri
May 21 at 13:33
You can NOT use the code like this. where you want to use check customer session?
– Amit Bera♦
May 21 at 13:39
bin/magento cache:disable if i go guest i got no logged if i go customer i got loged. bin/magento cache:enable if i go guest i got no loged if go customer ig ot no loged
– Ibrahim Aldar
May 21 at 13:23
bin/magento cache:disable if i go guest i got no logged if i go customer i got loged. bin/magento cache:enable if i go guest i got no loged if go customer ig ot no loged
– Ibrahim Aldar
May 21 at 13:23
1
1
The response is just getting cached. Itt will work on first load however remain the same for each request thereafter if that is what you are experiencing. There are Javascript alternatives for this that will work magento.stackexchange.com/questions/263905/…
– harri
May 21 at 13:33
The response is just getting cached. Itt will work on first load however remain the same for each request thereafter if that is what you are experiencing. There are Javascript alternatives for this that will work magento.stackexchange.com/questions/263905/…
– harri
May 21 at 13:33
You can NOT use the code like this. where you want to use check customer session?
– Amit Bera♦
May 21 at 13:39
You can NOT use the code like this. where you want to use check customer session?
– Amit Bera♦
May 21 at 13:39
add a comment |
1 Answer
1
active
oldest
votes
The block responsible for rendering the template which contains the logic above is cached.
Couple of options
To disable caching of custom block on a Magento 2 product view page, you can implement a couple of different approaches:
In a layout, set cacheable=”false”. Note that this attribute will make the whole page non-cacheable.
Alternatively, you can set _isScopePrivate property to true in a block class. By implementing this approach, you instruct a page cache module to replace your block content with placeholder before caching. When the page is loaded from cache, your block can be rendered via Ajax request. Check MagentoCaptchaBlockCaptcha::__construct and related layouts/templates as an example.
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f275487%2fcache-breaks-my-check-for-detecting-if-a-customer-is-logged-in%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The block responsible for rendering the template which contains the logic above is cached.
Couple of options
To disable caching of custom block on a Magento 2 product view page, you can implement a couple of different approaches:
In a layout, set cacheable=”false”. Note that this attribute will make the whole page non-cacheable.
Alternatively, you can set _isScopePrivate property to true in a block class. By implementing this approach, you instruct a page cache module to replace your block content with placeholder before caching. When the page is loaded from cache, your block can be rendered via Ajax request. Check MagentoCaptchaBlockCaptcha::__construct and related layouts/templates as an example.
add a comment |
The block responsible for rendering the template which contains the logic above is cached.
Couple of options
To disable caching of custom block on a Magento 2 product view page, you can implement a couple of different approaches:
In a layout, set cacheable=”false”. Note that this attribute will make the whole page non-cacheable.
Alternatively, you can set _isScopePrivate property to true in a block class. By implementing this approach, you instruct a page cache module to replace your block content with placeholder before caching. When the page is loaded from cache, your block can be rendered via Ajax request. Check MagentoCaptchaBlockCaptcha::__construct and related layouts/templates as an example.
add a comment |
The block responsible for rendering the template which contains the logic above is cached.
Couple of options
To disable caching of custom block on a Magento 2 product view page, you can implement a couple of different approaches:
In a layout, set cacheable=”false”. Note that this attribute will make the whole page non-cacheable.
Alternatively, you can set _isScopePrivate property to true in a block class. By implementing this approach, you instruct a page cache module to replace your block content with placeholder before caching. When the page is loaded from cache, your block can be rendered via Ajax request. Check MagentoCaptchaBlockCaptcha::__construct and related layouts/templates as an example.
The block responsible for rendering the template which contains the logic above is cached.
Couple of options
To disable caching of custom block on a Magento 2 product view page, you can implement a couple of different approaches:
In a layout, set cacheable=”false”. Note that this attribute will make the whole page non-cacheable.
Alternatively, you can set _isScopePrivate property to true in a block class. By implementing this approach, you instruct a page cache module to replace your block content with placeholder before caching. When the page is loaded from cache, your block can be rendered via Ajax request. Check MagentoCaptchaBlockCaptcha::__construct and related layouts/templates as an example.
answered May 21 at 21:41
Dominic XigenDominic Xigen
61511
61511
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f275487%2fcache-breaks-my-check-for-detecting-if-a-customer-is-logged-in%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
bin/magento cache:disable if i go guest i got no logged if i go customer i got loged. bin/magento cache:enable if i go guest i got no loged if go customer ig ot no loged
– Ibrahim Aldar
May 21 at 13:23
1
The response is just getting cached. Itt will work on first load however remain the same for each request thereafter if that is what you are experiencing. There are Javascript alternatives for this that will work magento.stackexchange.com/questions/263905/…
– harri
May 21 at 13:33
You can NOT use the code like this. where you want to use check customer session?
– Amit Bera♦
May 21 at 13:39