Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saved cart list disappears when the language is changed from the language context selector #19294

Open
relsayed8205 opened this issue Sep 26, 2024 · 0 comments

Comments

@relsayed8205
Copy link

relsayed8205 commented Sep 26, 2024

Describe
Saved cart list disappears when the language is changed from the language context selector.

Version

  • Library version: [22.11.19.0]

To Reproduce
Steps to reproduce the behavior:

  1. Login by any user
  2. Add some products to the cart
  3. Save the cart e.g. cart1
  4. Create another cart and save it cart2
  5. Open the saved carts page
  6. Change the language using the standard language context selector

Expected behavior
The list still shows 2 carts

What happens is
The list disappears.

Explanation
The list gets loaded by calling the SavedCartService.getList(). This checks the following state in the store

process: {
    entities: {
      'saved-cart-list': {
        loading: false,
        error: false,
        success: false
      },
  }
}

The 3 flags must be false to trigger the load. After the initial page load the success is turned to true and remains true after you change the language. However, changing the language resets the carts content in the store. See cart-effect.ts
resetCartDetailsOnSiteContextChange$: Observable<CartActions.ResetCartDetails> = createEffect(() => this.actions$.pipe( ofType( SiteContextActions.LANGUAGE_CHANGE, SiteContextActions.CURRENCY_CHANGE ), mergeMap(() => { return [new CartActions.ResetCartDetails()]; }) ) );

So, carts are cleared and no reload is triggered.

The solution is to trigger ClearSavedCarts action upon context change, e.g.
resetCartDetailsOnSiteContextChange$: Observable<CartActions.ResetCartDetails | SavedCartActions.ClearSavedCarts> = createEffect(() => this.actions$.pipe( ofType( SiteContextActions.LANGUAGE_CHANGE, SiteContextActions.CURRENCY_CHANGE ), mergeMap(() => { return [new CartActions.ResetCartDetails(), new SavedCartActions.ClearSavedCarts()]; }) ) );

The ClearSavedCarts causes the flags succes, loading and error to be false

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

No branches or pull requests

1 participant