I've been looking at an easy and fast way (not expensive) to get the current cart data on each page view.

It seems that most information about the cart is available in LocalStorage. You can see what's there by running this:


Does anyone know when this is available? And if it is safe to use and assume it will be there?

1 Answer 1


You can check this answer out:

Magento 2: Syncing Backend and Frontend State/Cache

Here's an example how to use customer-data:

], function (customerData) {
    // Get data
    var customData = customerData.get("custom-data")();

    // Change something
    customData.foo = "bar";

    // Set data
    customerData.set("custom-data", customData);

Hope this'll help you out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.