Skip to main content

I have an lwc in a webstore in commerce cloud that adds products to the cart. On the backend works fine, the product is added to the cart without dificulties but it doesn't update the cart on the webstore. The only way I can refresh the cart is if I reload the page.

 

I've already tried using Lightning Message Service with:

 

publish(this.messageContext, cartChanged);

 

And using the old workaround with an event:

 

this.dispatchEvent(new CustomEvent("cartchanged", {

bubbles: true,

composed: true

}));

1 respuesta
  1. 22 abr 2023, 14:52

    One possible reason for this could be that you are not listening to the event or message correctly in the component where the cart is displayed.

    Make sure that you have subscribed to the `cartChanged` message or `cartchanged` event in the component that displays the cart. You can do this using the `lightning:messageService` component or by adding an event listener in your JavaScript code.

    Another possible solution could be to use the `refreshCart()` method provided by the `commerceCartService` to refresh the cart data in your LWC. This method can be called after adding or removing items from the cart to update the cart data without having to reload the page.

    Finally, make sure that you are using the latest version of the Commerce Cloud platform and that your code is compatible with the current API version. Sometimes, outdated code or API versions can cause issues with updating the cart in LWCs.

0/9000