cancel
Showing results for 
Search instead for 
Did you mean: 

Add to cart is not working when we manually trigger the entry call

0 Kudos

Hi @all,

I want to add one flag in the entries call so that I have manually triggered the entries call but in the back end it creates a blank cart entry. Below is my code :

spartacus version:3.0.2

Add to Component.ts

   this.activeCartService.getActiveCartId().subscribe((data) => {<br>        this.activeCartId = data;<br>      });

      this.activeCartService.getEntries()<br>      .pipe(take(1))<br>      .subscribe((entries) => {<br>        this.snactiveCartService.addEntryCode(this.mainProduct,this.product.code,quantity,this.activeCartId);<br>        this.numberOfEntriesBeforeAdd = entries.length;<br>        this.openSnModal(module);<br>      });<br>    }
active cartservice.ts
  public addEntryCode(mainProduct: any, productCode: string, quantity: number = 1, activeCartId): void {<br>    let cartId = activeCartId;<br>    this.requireLoadedCart()<br>      .pipe(withLatestFrom(this.userIdService.getUserId(), this.getEntries()))<br>      .subscribe(([cartState, userId, previousEntries]) => {<br>        const toAdd = JSON.stringify({});<br>        const headers = new HttpHeaders({<br>          'Content-Type': 'application/x-www-form-urlencoded',<br>        });<br>        const id = activeCartId<br>        const url = this.occEndpointsService.getUrl(<br>          'addEntries',<br>          {<br>            userId,<br>            cartId,<br>            quantity,<br>            mainProduct,<br>          },<br>          { code: productCode, qty: quantity, mainProduct } // The "qty" parameter is used for the base b2c add to cart endpoint.<br>        );<br>        return this.http<br>          .post<CartModification>(url, toAdd, { headers })<br>          .pipe(this.converterService.pipeable(CART_MODIFICATION_NORMALIZER))<br>          .subscribe((data) => {<br>            if(data){<br>              let cartId;<br>              this.getActiveCartId().subscribe((data) => {<br>                cartId = data;<br>              });<br>              this.store.dispatch(<br>                new CartActions.LoadCart({<br>                  userId,<br>                  cartId,<br>                })<br>              );<br>              const tempCartId = this.generateTempCartId();<br>              this.getActiveCartId().subscribe((data) => {<br>                cartId = data;<br>              });<br>              <br>              this.store.dispatch(<br>                new CartActions.MergeCart({<br>                  userId,<br>                  cartId,<br>                  extraData: {<br>                    active: true<br>                  },<br>                  tempCartId,<br>                }))<br>              }<br>            <br>      });<br>    <br>  })<br>}

Accepted Solutions (0)

Answers (0)