Skip to content

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

Open
@relsayed8205

Description

@relsayed8205

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions