feat: update cart service and components to handle productVariantId, improve item removal and addition feedback

This commit is contained in:
2026-07-02 11:00:40 -03:00
parent c9d8265790
commit d31cb65d65
6 changed files with 43 additions and 14 deletions

View File

@@ -54,6 +54,7 @@ export class StoreLayoutComponent implements OnInit {
}
return {
productVariantId: item.product_variant_id,
imageUrl: item.product?.imagen ?? null,
product,
originalPrice: null,

View File

@@ -75,8 +75,8 @@ describe('CartService', () => {
});
it('should add item and update signal', () => {
service.addItem(10, 2).subscribe((cart) => {
expect(cart).toEqual(mockCart);
service.addItem(10, 2).subscribe((res) => {
expect(res.data).toEqual(mockCart);
expect(service.cart()).toEqual(mockCart);
});

View File

@@ -31,7 +31,7 @@ export class CartService {
);
}
addItem(productVariantId: number, cantidad: number): Observable<Cart> {
addItem(productVariantId: number, cantidad: number): Observable<ApiResponse<Cart>> {
return this.http
.post<ApiResponse<Cart>>(
`${this.tenantApiUrl}/cart/items`,
@@ -39,8 +39,7 @@ export class CartService {
{ withCredentials: true }
)
.pipe(
map((response) => response.data),
tap((cart) => this.cartState.set(cart))
tap((response) => this.cartState.set(response.data))
);
}