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.
define(
[
......
'Magento_Customer/js/customer-data'
.....
],
function (Component,customerData) {
'use strict';
return Component.extend({
defaults: {
template: 'Mymodule_Company/myTemplate'
},
initialize : function(){
this._super(customerData.getData());
console.log(customerData.getCustomerInfo());
}
});
}
);
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– Adarsh Khatri2019年07月31日 02:23:24 +00:00Commented Jul 31, 2019 at 2:23
1 Answer 1
It depends on what you want, if you want like the cart section you could use it in the following way:
customerData.get('cart')();
You could add custom data to the customer data and then retrieve it with like:
customerData.get('sectionData');
More info: http://devdocs.magento.com/guides/v2.2/extension-dev-guide/cache/page-caching/private-content.html