We have a product site that has two possible states:
Logged In:
The product price is shown.
Not Logged In:
The price is not shown and you get a text saying that you need to login to see the price.
Problem:
Currently the "Not Logged In" state of the site is being cached and if the customer logs in, then the site gets served from the cache, and incorrectly showing the not logged in state instead of showing the "Logged In" state.
Only if the customer reloads the site again, then it shows the "Logged In" state.
So I added ttl="-1" to the block in the catalog_product_view.xml layout file, to make it private.
But then if the site loads it outputs this error:
This is the code:
app/code/Vendor/Module/view/frontend/templates/product/view/addtocart.phtml
I noticed even more problems, e.g. you can't check if a customer is logged in with \Magento\Customer\Model\Session if you are using a negative ttl.
Am I doing something wrong, or is it a bug in the litemage extension?
Logged In:
The product price is shown.
Not Logged In:
The price is not shown and you get a text saying that you need to login to see the price.
Problem:
Currently the "Not Logged In" state of the site is being cached and if the customer logs in, then the site gets served from the cache, and incorrectly showing the not logged in state instead of showing the "Logged In" state.
Only if the customer reloads the site again, then it shows the "Logged In" state.
So I added ttl="-1" to the block in the catalog_product_view.xml layout file, to make it private.
XML:
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="product.info.form.content">
<block class="Magento\Catalog\Block\Product\View"
name="product.info.addtocart"
as="addtocart"
template="Vendor_Module::product/view/addtocart.phtml"
ttl="-1"
/>
</referenceContainer>
</body>
</page>
Error: Call to a member function isSaleable() on null in app/code/Vendor/Module/view/frontend/templates/product/view/addtocart.phtml:4
app/code/Vendor/Module/view/frontend/templates/product/view/addtocart.phtml
PHP:
<?php
$_product = $block->getProduct();
if ($_product->isSaleable()):
echo "Some logic...";
endif;
I noticed even more problems, e.g. you can't check if a customer is logged in with \Magento\Customer\Model\Session if you are using a negative ttl.
Am I doing something wrong, or is it a bug in the litemage extension?
Last edited: