UNPKG

@selldone/sdk-storefront

Version:

A TypeScript SDK to connect to your shop and build a fully functional storefront and website by simply developing a frontend web application. All backend operations are seamlessly managed by the serverless Selldone solution.

59 lines (58 loc) 2.48 kB
import { Currency } from "@selldone/core-js/enums/payment/Currency"; import { BasketItem } from "@selldone/core-js/models/shop/order/basket/basket_item.model"; import { XapiBasket } from "../XapiBasket"; import { Basket } from "@selldone/core-js/models/shop/order/basket/basket.model"; /** * Adds an item to the basket. * * This function is used to add a specified product variant to the basket with the given quantity and optional parameters. * * @param {number} product_id - The ID of the product to be added. * @param {number | null} variant_id - The ID of the product variant, or null if not applicable. * @param {number} count - The quantity of the item to be added. * @param {XapiBasketAddItemTypes.IOption} [options] - Optional parameters for adding the item. * @returns {Promise<XapiBasketAddItemTypes.IResponse>} - The response from the server after attempting to add the item. * * @example * window.$storefront.basket * .addItem(product_id, variant_id, count, { * preferences: preferences, * vendor_product_id: vendor_product_id, // 🟣 Marketplace 🟣 * price_id: subscription_price_id, // 🎗️ Subscription * }) * .then(({ basket, bill, refresh, error, error_msg }) => { * if (basket) { * this.setBasket(basket); * this.setBasketBill(basket, bill); * if (callbackSuccess) callbackSuccess(basket); * } * * if (error) { * NotificationService.showErrorAlert(null, error_msg); * if (callbackError) callbackError(error_msg!); * } * * if (refresh) this.fetchBasketAndShop(); // Important! Fetch data from server. (Ex. Remove item automatically from basket) * }) * .catch((error) => { * NotificationService.showLaravelError(error); * if (callbackError) callbackError(error); * }); */ export default function XapiBasketAddItem(this: XapiBasket, product_id: number, variant_id: number | null, count: number, options?: XapiBasketAddItemTypes.IOption): Promise<XapiBasketAddItemTypes.IResponse>; export declare namespace XapiBasketAddItemTypes { interface IResponse { error: boolean; error_msg: string | null; refresh?: boolean; success: boolean; basket: Basket; bill: Basket.ICalculatedBill; } interface IOption { currency?: keyof typeof Currency; preferences?: BasketItem.IPreferences | null; vendor_product_id?: number | null; price_id?: number | null; } }