From 38300bcabe15878c6531d5aa8f21bba3373a56cb Mon Sep 17 00:00:00 2001 From: YulikK Date: Mon, 3 Jun 2024 22:37:53 +0200 Subject: [PATCH] fix: cart request --- src/shared/API/cart/model/CartModel.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/shared/API/cart/model/CartModel.ts b/src/shared/API/cart/model/CartModel.ts index 064f58b0..4d619b46 100644 --- a/src/shared/API/cart/model/CartModel.ts +++ b/src/shared/API/cart/model/CartModel.ts @@ -33,10 +33,13 @@ export class CartModel { private cart: Cart | null = null; + private isSetAnonymousId = false; + private root: CartApi; constructor() { this.root = getCartApi(); + this.getCart().catch(showErrorMessage); } private adaptCart(data: CartResponse): Cart { @@ -98,13 +101,15 @@ export class CartModel { const data = await this.root.getAnonymCart(anonymousCartId); if (!data.body.customerId) { this.cart = this.getCartFromData(data); - if (data.body.anonymousId !== anonymousId) { + const cartAnonymId = data.body.anonymousId; + if (cartAnonymId !== anonymousId && !this.isSetAnonymousId) { + this.isSetAnonymousId = true; const actions: CartSetAnonymousIdAction = { action: ACTIONS.setAnonymousId, anonymousId, }; - const data = await this.root.setAnonymousId(this.cart, actions); - this.cart = this.getCartFromData(data); + const dataSetId = await this.root.setAnonymousId(this.cart, actions); + this.cart = this.getCartFromData(dataSetId); } } @@ -256,6 +261,9 @@ export class CartModel { if (!this.cart) { const { anonymousCartId, anonymousId } = getStore().getState(); if (anonymousCartId && anonymousId) { + // const data = await this.root.getAnonymCart(anonymousCartId); + // this.cart = this.getCartFromData(data); + this.cart = await this.getAnonymousCart(anonymousCartId, anonymousId); } if (!this.cart) {