-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cant't get cart items in block - quote object empty #6392
Comments
I think problem may lay in cache, especially |
@bartek9007 there is a problem in your code
$cartItems never will be an array. This code causes an exception for me. Could you specify the code version which works from controller? |
@SerhiyShkolyarenko you are right. I updated my question, I posted chunk of code I have been testing later. Of course, it will cause exception. Now there is a code in question which actually works only when |
@bartek9007 please also provide DownloadableSampleUrlProviderInterface code for clean experiment. |
@SerhiyShkolyarenko I will update it to the code I have now - and it is whole class and also doesn't work. |
@bartek9007 I made some minor changes to have your code compiled and injected to controller. Patch with all my changes is attached. Also I disabled page cache to check how it works in debugger. |
@SerhiyShkolyarenko Controller was just another place to test code. |
@bartek9007 that check 5 days ago was performed on latest develop branch. Does the same code in standard Magento themes(Blank or Luma) works properly? |
I have checked it on 2.1.1. and with FPC disabled and enabled - checking if product is in cart (using checkout session works) |
But with full page cache doesn't work block checking if product is in currently logged in customer wishlist. Should I reopen this one or open new issue? |
Let's continue here. Please attach all required changes as a patch and describe all steps to reproduce from clean magento installation to avoid different reproducing flows for you and me. |
Hm, I am not sure how to make a patch, so for now I will post a code of block:
and it is added inside
Works for me only with
|
tested on clean Magento instance - 2.1.2 and doesn't work if it's not marked as |
Your $data parameter is required. What is |
Which way |
I haven't added any configuration for this class in |
@bartek9007 could you please create a separate module with that block and corresponding layout update to activate it on category page? Attaching that module as archive would be handy here. I need it to be sure we have the same code changes. |
Test.zip Here with FPC enabled, both blocks cachebale: And here after disabling FPC or setting any of block as not cacheable in xml, as they make all page not cacheable: |
@bartek9007
and stack trace.
'template' attributes are not allowed for 'referenceBlock' elements in layouts. How do you make that code run? Am I doing anything wrong? |
Test.zip |
@bartek9007 I added
Generally, it is a common rule: blocks with personal data have to be not cacheable. |
Yes, that is true - they work if I match them as not 'cacheable'. So I understand it's like this by design. The problem in such a situation is that the whole page is not cacheable. Is there any way to omit that? Shouldn't be this designed other way - to allow not cache part of page? Or is it hard/impossible to achieve? |
@bartek9007 the general rule is to move private content in browser. When Magento renders public content (should not contain any personal data), it removes everything from session in order to prevent information leaks. Take a look on this - http://devdocs.magento.com/guides/v2.1/config-guide/cache/cache-priv-priv.html. "Customer data sections" is preferable way to achieve your goal. If you don't want to rewrite your code to JS, you can try deprecated approach - mark your block as private using _isScopePrivate property. This will tell Magento to load content using separate AJAX call. In this case cache will be invalidated on any POST request. |
you need to add cacheable="false" in layout xml to access cart quote in custom module |
I am using magento 2.1.8. I my custom theme app\design\frontend\Sample\theme-frontend-shop\Magento_Catalog\templates\product\view\form.phtml I have done `$quoteId = $objectManager->get('Magento\Checkout\Model\Session')->getQuoteId();
} echo $currentItemCount;` and in my app\design\frontend\Sample\theme-frontend-shop\Magento_Catalog\layout\catalog_product_view.xml I have added But this is not working properly when full page cache is enabled. Need help to fix this issue. |
Preconditions
Steps to reproduce
namespace [vendor]\SkinHelper\Block\Catalog\Product;
`isInCart($_product); ?>
helper([vendor]\SkinHelper\Helper\Test')->isInCart($_product) ?>`As you can see I was trying the same thing with helper (called from helper), but it failed.
\Magento\Checkout\Model\Cart
and it also didn't worked.Expected result
Actual result
$itemsIds
it is empty, so no elements can be retrieved. Products are present in minicart, as well as inquote
table as well.The text was updated successfully, but these errors were encountered: