How to set the newly created cart to active cart using multiCartService.createCart service?
I have this quick order scenario, when clicking the add to cart button, it will add the items in my quick order form in the current cart. However, for some reason when it's newly logged in users, The active cart is undefined during a load of the quick order page, so I have used the "createCart" method from multiCartService to create a new cart so that when I add the items from the quick order form it will add in that new cart.
example:
this.multiCartService
.createCart({ userId: this.userCurrent })
.pipe(take(1))
.subscribe(
(success) => {
},
(error) => {}
);
However, After creating a cart and add the items, It will go to the cart page to display the added items but on the OOTB ActiveCartService.getActive()
it resulted in undefined which means there's no active cart then the cart page is empty. However, if you refresh the cart page via the browser, items will be present.
I'm still using the Spartacus version 1.5
Please advise. Thanks
We are able to figure out what is missing. We just need to set the newly created cart to active to true with the use of extraData.
Add this to the createCart
extraData: {active: true}
Example:
this.multiCartService
.createCart({ userId: this.userCurrent, extraData: {
active: true,
}, })