Dynamic object syncing
Customer
In your app you can easily sync internal Buddi.customer object with a local var to be able to find out when a customer is logged in and get the customer details.
For example if you’re using VueJS you can easily do it like this:
new Vue({
el: '#app',
data: {
customer: Buddi.customer,
},
beforeUnmount() {
Buddi.$off('customer:updated', 'customerUpdatedEvent');
},
created() {
Buddi.$on('customer:updated', customer => {
this.customer = {...customer};
}, 'customerUpdatedEvent');
},
...
});
Now every time when the main Buddi module changes the customer object, the object will also be changed in your app.
Cart
In your app you can sync Buddi.cart object with a local var to be able to find out the products counts in the cart, totals, etc.
For example if you’re using VueJS you can easily do it like this:
new Vue({
el: '#app',
data: {
cart: Buddi.cart,
},
beforeUnmount() {
Buddi.$off('cart:updated', 'cartUpdatedEvent');
},
created() {
Buddi.$on('cart:updated', cart => {
this.cart = {...cart};
}, 'cartUpdatedEvent');
},
...
});
Now every time when the main Buddi module changes the cart object, the object will also be changed in your app.