Skip to content

fix: Cart not refreshed after re-order#21202

Open
rmch91 wants to merge 1 commit intodevelopfrom
fix/CXSPA-11929
Open

fix: Cart not refreshed after re-order#21202
rmch91 wants to merge 1 commit intodevelopfrom
fix/CXSPA-11929

Conversation

@rmch91
Copy link
Contributor

@rmch91 rmch91 commented Feb 27, 2026

Closes: https://jira.tools.sap/browse/CXSPA-11929

QA steps:

Can be reproduced locally with SPA from develop-next-major and backend 22.11jdk21. ("CX_BASE_URL": "https://spartacus-devci7677.eastus.cloudapp.azure.com:8443/")

Submit an order in B2B site. View order history and navigate to order details. Re-order

Message 'Products have been sucessfully added to the cart' appears.

Navigate to cart -> no cart entries visible. 

Only when you hit F5 or add another product to the cart, cart becomes updated with the entry from re-order.

@rmch91 rmch91 requested a review from a team as a code owner February 27, 2026 20:45
@github-actions github-actions bot marked this pull request as draft February 27, 2026 20:45
@rmch91 rmch91 marked this pull request as ready for review February 27, 2026 20:48
@cypress
Copy link

cypress bot commented Feb 27, 2026

spartacus    Run #52041

Run Properties:  status check passed Passed #52041  •  git commit 8c421e6eee ℹ️: Merge 999b8563b4aead141f3f8641d278086f97c4dd44 into 3e71f7a9219000437defd3f7382a...
Project spartacus
Branch Review fix/CXSPA-11929
Run status status check passed Passed #52041
Run duration 11m 59s
Commit git commit 8c421e6eee ℹ️: Merge 999b8563b4aead141f3f8641d278086f97c4dd44 into 3e71f7a9219000437defd3f7382a...
Committer Roman
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 3
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 101
⚠️ You've recorded test results over your free plan limit.
Upgrade your plan to view test results.
View all changes introduced in this branch ↗︎

Copy link
Contributor

@uroslates uroslates left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! 👍 Great job!

Added a comment with some neat-peek suggestions but not required, leave it to you to decide if they make sense in this case.

Would suggest we assign it to @KateChuen for QA!

Comment on lines 63 to +78
if (!userId) {
throw new Error('Must be logged in to reorder');
}

if (cartId) {
this.multiCartFacade.deleteCart(cartId, userId);
// Wait for the cart entity to be fully removed from the store
// before proceeding with the reorder.
return this.multiCartFacade.getCartEntity(cartId).pipe(
filter((state) => !state.value && !state.loading),
take(1),
map(() => userId)
);
}

return userId;
return of(userId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// ...
    switchMap(([userId, cartId]) => {
      if (!userId) {
        return throwError(() => new Error('Must be logged in to reorder'));
      }

      if (cartId) {
        return this.deleteCartAndWait(cartId, userId);
      }

      return of(userId);
    })
  );
// ...

protected deleteCartAndWait(cartId: string, userId: string): Observable<string> {
 this.multiCartFacade.deleteCart(cartId, userId);
  
  return this.multiCartFacade.getCartEntity(cartId).pipe(
    filter((state) => !state.value && !state.loading || !!state.error),
    take(1),
    switchMap((state) => {
      if (state.error) {
        // Log W/O blocking reorder
        console.warn('Cart deletion may have failed:', state.error);
      }
      return of(userId);
    })
}
  1. [neat pick] Would add proper RxJs error propagation (throwError instead of throw for consistency with reactive nature & better integration with catchError and retry/... RxJs primitives)
  2. [neat pick] For the sake of better readability and testability I would suggest extracting deleteCartAndWait into separate protected method.
  3. [neat pick] handle failed cases (!state.value && !state.loading || !!state.error) - deletion failed but we continue
  4. [neat pick] this.multiCartFacade.getCartEntity -> switchMap block - we log error as warning and continue (not sure if necessary - leave it to you to decide)

I am not sure if in addition to above - in the context of returned deleteCartAndWait method observable - we should also handle adding rxjs timeout (for preventing indefinite hanging) and catchError (just logging and proceeding event if it times out). I guess it would be too much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants