0

I would like to get all items in the cart with Full Page Cache (FPC) turned on

Normally I would do something like:

use Magento\Checkout\Model\Session;

public function __construct(
        ...
        Session $session
        ...
    ) {
        ...
        $this->_session = $session;
        ...
    }

public function yourFunction()
{
    $items = $this->_session->getQuote()->getAllVisibleItems();
}

However when you turn on FPC, the session is lost as per this GitHub Issue. Adding cacheable="false" to the XML is not an option as it will make all of the page not cachable.

Therefore my question is how do I get a list of items in the cart with FPC turned on?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.