SAP / spartacus

Spartacus is a lean, Angular-based JavaScript storefront for SAP Commerce Cloud that communicates exclusively through the Commerce REST API.
Apache License 2.0
735 stars 380 forks source link

b2b: Saving a cart with a recently placed replenishment order loads the latter #14315

Open KateChuen opened 2 years ago

KateChuen commented 2 years ago

Environment Details Browser: Chrome Device: mac Frontend: 4.2 RC0 Backend: release/2105/next branch on devci4 Happens on: https://spartacus-devci7674.eastus.cloudapp.azure.com:5201/powertools-spa/en/USD

Steps to Reproduce Go to powertools storefront Login as a b2b customer, for eg, marie.dubois@rustic-hw.com/pw4all Add any product to cart and place order as a replenishment order (for eg, every 1 day, starting today), for eg: 3879437 Now your cart is empty. Add another product or a few products to cart. Save the cart.

Actual Result You'll see the item from the replenishment order we placed previously in the cart now.

Screen Shot 2021-11-10 at 3 21 40 PM

Expected Result I was expecting an empty cart

BenjaminEmiliani commented 2 years ago

Here are some finding (with help from @bgambocjaviniar):

It seems to be a backend issue when a replenishment order is placed. It seems that the endpoint is duplicating a cart containing the item(s) purchased in the replenishment order. This cart is added to the list of carts the user has and becomes active after saving the current cart because by saving the current cart, that duplicate cart falls next in place and is loaded as active.

Here are some images that help illustrate what's happening under the hood:

  1. State of the carts list of user at the beginning

    Start
  2. Adding an item to cart and place order as replenishment. Here is the product:

    product
  3. After placing order as replenishment we can observe a list of actions done to the local Store (Ngrx). In this list there is no action that creates a new cart with the same item:

    Store actions after repl order
  4. After adding another product to the shopping cart we can observe the state of the carts in the backend. In this image we can see how there is two carts, indexed 0 and 1. The cart: 0 is the current empty shopping cart (as usual). Cart: 1 contains the same product from earlier placed as a replenishment order. Note the code of this cart is 00002294

    Network after starting new cart
  5. Here is the shopping cart after saving the current cart. Note here that the cart code matches that of cart: 1 from (4) and contains the product.

    Screen Shot 2021-12-09 at 2 56 41 PM