on 2022 Nov 03 11:59 AM
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>}
Request clarification before answering.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.