Skip to content

Missing type definitions in currentCart from @wix/ecom  #556

Open
@sanam2405

Description

@sanam2405

I was using the wix eCommerce API. In particular, I was using the currentCart API. However, I found out there are missing type definitions in currentCart.Cart .

Screenshot 2024-09-27 at 1 17 27 PM

The below is the API response upon calling currentCart.Cart.

Screenshot 2024-09-27 at 1 06 46 PM

You can see, there is a field called subtotal. However, there seems to be no type definitions for the field subtotal in the CurrentCart.Cart present inside ecom-v1-cart-current-cart.public of node modules.


As a temporary fix, I did the below

import { currentCart } from "@wix/ecom";
import { WixClient } from "@/context/wixContext";

// structure of the subtotal field
type Subtotal = {
  amount?: string;
  convertedAmount?: string;
  formattedAmount?: string;
  formattedConvertedAmount?: string;
};

// extend currentCart.Cart to include the subtotal field
type ExtendedCart = currentCart.Cart & {
  subtotal?: Subtotal;
};

type CartState = {
  cart: ExtendedCart;
  isLoading: boolean;
  counter: number;
  getCart: (wixClient: WixClient) => void;
  addItem: (
    wixClient: WixClient,
    productId: string,
    variantId: string,
    quantity: number,
  ) => void;
  removeItem: (wixClient: WixClient, itemId: string) => void;
};

Raising this issue to get the type definitions of the { currentCart } from "@wix/ecom"fixed.

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