I am trying to get the custom session data of Customer in a javascript file. As I am passing 'Magento_Customer/js/customer-data' as dependency in order to retrieve the data.

function (Component,customerData) {
    'use strict';

    return Component.extend({
        defaults: {
            template: 'Mymodule_Company/myTemplate'
        initialize : function(){

I want to get a custom variable just like i set up in my php file :

$this->customerSession->setMyCustomValue("my custom variable");
  • Did you mange to get it work? – Adarsh Khatri Jul 31 '19 at 2:23

It depends on what you want, if you want like the cart section you could use it in the following way:


You could add custom data to the customer data and then retrieve it with like:


More info: http://devdocs.magento.com/guides/v2.2/extension-dev-guide/cache/page-caching/private-content.html

| improve this answer | |

Your Answer

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

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