Function useShopperBasketsMutationHelper

  • This is a helper function for Basket Mutations. useShopperBasketsMutationHelper.addItemToNewOrExistingBasket: is responsible for managing the process of adding an item to a basket.

    • If a basket already exists, add the item to the basket immediately.
    • If a basket does not exist, create a new basket using the createBasket mutation and then add the item to the newly created basket using the addItemToBasket mutation.

    Returns {
        addItemToNewOrExistingBasket: ((productItem) => Promise<Basket>);
    }

    Example

    import useShopperBasketsMutationHelper from '@salesforce/commerce-sdk-react'

    const Page = () => {
    const helpers = useShopperBasketsMutationHelper()

    const addToCart = async () => {
    const productItems = [{id: 123, quantity: 2}]
    await basketMutationHelpers.addItemToNewOrExistingBasket(productItems)
    }

    }