@avvyr/storefront-sdk - v0.19.0
    Preparing search index...

    Class CartResource

    Index
    • ADD goods to an existing option group: each quantity is added, a new sku (another size or model of the same product) joins with the group's choices and is priced on its class key.

      Parameters

      • cartId: string
      • optionGroupId: string
      • items: { quantity: number; sku: string }[]

      Returns Promise<StorefrontCart>

    • Add a product configured with its option profile as one group: goods lines (one per size) and the charge lines its choices add, in one request. Tiers are judged on the group's total. Every line of the group carries the same optionGroupId.

      With setId the group joins an existing set and inherits its choices ("Komplettera i samma tyg"); with set it starts one. Then the answer also has setId and optionGroupId.

      Parameters

      Returns Promise<ConfiguredItemsResult>

    • Add a set (serie-grupp) in one request, everything or nothing: plain lines and option groups, every line stamped with the same set. An error from one part has details.setItem ({ list: "items" | "configured", index, sku }).

      Parameters

      Returns Promise<AddSetResult>

    • Apply a unified code (discount code, gift card, or store credit)

      Parameters

      • cartId: string
      • code: string

      Returns Promise<StorefrontCart>

    • Apply a discount code / coupon (legacy, use applyCode instead)

      Parameters

      • cartId: string
      • code: string

      Returns Promise<StorefrontCart>

    • Apply a gift card

      Parameters

      • cartId: string
      • code: string

      Returns Promise<StorefrontCart>

    • Apply a store credit

      Parameters

      • cartId: string
      • code: string

      Returns Promise<StorefrontCart>

    • Claim an anonymous cart for the signed-in customer.

      Call this right after sign-in. The cart is normally created before anyone logs in — items added, then sign in at checkout — so without claiming it stays anonymous and the shopper keeps seeing B2C prices and consumer VAT even though they are signed in.

      Identity comes from the customer access token, never from the body: there is nothing to pass. A cart belonging to a different customer is rejected with 403; one already claimed is returned unchanged, so calling it on every login is safe.

      Parameters

      • cartId: string

      Returns Promise<StorefrontCart>

    • Complete cart (create order with custom/external payment).

      SERVER-SIDE ONLY. The declared payment is written onto the order as completed without any PSP being consulted, so the endpoint requires a storefront key carrying the storefront:orders:create scope — the private, server-to-server key, never the public one in your page source. Calls made from a browser are rejected with 403 SERVER_SIDE_KEY_REQUIRED even when the key is right.

      payment.amount must equal the cart's remaining amount, or the call fails with 409 CART_AMOUNT_MISMATCH. Pass 0 only for a cart already fully covered by gift cards or store credit.

      Parameters

      Returns Promise<StorefrontCart>

    • Confirm the code from the e-mail. The cart gets verifiedEmail. Throws EMAIL_VERIFICATION_INVALID_CODE (details.attemptsLeft) or EMAIL_VERIFICATION_EXPIRED.

      Parameters

      • cartId: string
      • code: string

      Returns Promise<{ email: string; verified: true }>

    • Create a new empty cart. Stores the cartAccessToken internally. visitorId/sessionId are optional tracking attribution (pseudonymous ids, see the tracking resource) — they follow the cart onto the order so behaviour can be joined to purchases, including guest checkout. consent stores the visitor's cookie choices on the cart (see setConsent).

      Parameters

      • Optionalparams: {
            businessUnitId?: string;
            consent?: CartConsentInput;
            sessionId?: string;
            visitorId?: string;
        }

      Returns Promise<StorefrontCart>

    • Get an existing cart by ID

      Parameters

      • cartId: string

      Returns Promise<StorefrontCart>

    • Get abandoned cart for recovery

      Parameters

      • cartId: string

      Returns Promise<StorefrontCart>

    • Whether the customer can split the order when something is out of stock, and what each choice looks like: which items ship now, which later, and roughly when. Returns enabled: false when the store does not offer the choice.

      Parameters

      • cartId: string

      Returns Promise<ShipmentOptions>

    • Shipping options for one shipment of a split cart, priced on that shipment's items.

      Parameters

      • cartId: string
      • shipmentOrderId: string
      • postalCode: string

      Returns Promise<ShipmentShippingOptions>

    • The signed-in customer's own open carts, newest first.

      Device continuity: a cart filled on a phone is here after signing in on a laptop. Requires a customer access token — there is no anonymous meaning to "my carts".

      Summaries only, and no access tokens: resume a cart with claim(id), which proves identity.

      Parameters

      • Optionallimit: number

      Returns Promise<{ carts: CustomerCartSummary[] }>

    • Remove a unified code

      Parameters

      • cartId: string
      • code: string

      Returns Promise<StorefrontCart>

    • Remove a whole option group, goods and charges.

      Parameters

      • cartId: string
      • optionGroupId: string

      Returns Promise<StorefrontCart>

    • Remove a discount code (legacy)

      Parameters

      • cartId: string
      • code: string

      Returns Promise<StorefrontCart>

    • Remove a gift card

      Parameters

      • cartId: string
      • code: string

      Returns Promise<StorefrontCart>

    • Remove a line item from the cart. A charge line answers 400 OPTION_CHARGE_LINE_LOCKED.

      Parameters

      • cartId: string
      • lineItemId: string

      Returns Promise<StorefrontCart>

    • Remove a whole set: its plain lines and option groups, goods and charges.

      Parameters

      • cartId: string
      • setId: string

      Returns Promise<StorefrontCart>

    • Remove a store credit

      Parameters

      • cartId: string
      • code: string

      Returns Promise<StorefrontCart>

    • Send a one-time code to the e-mail address, to confirm it belongs to the shopper (no account needed). Payment methods with requireVerifiedEmail (e.g. free samples) need it before checkout. Throws 429 EMAIL_VERIFICATION_TOO_MANY when asked too often.

      Parameters

      • cartId: string
      • email: string

      Returns Promise<
          {
              alreadyVerified?: boolean;
              email: string;
              expiresAt?: string;
              sent?: boolean;
          },
      >

    • Choose which company this cart is bought for.

      Only needed by a customer who belongs to SEVERAL companies — a single membership is bound automatically when the cart is claimed. Pass null to buy as a private individual instead.

      The choice decides B2B prices, payment terms, invoicing address and the VAT registration the sale is reported under, so the API verifies membership: a company you do not belong to is refused with 403, not ignored.

      Parameters

      • cartId: string
      • companyId: string | null

      Returns Promise<StorefrontCart>

    • Manually set the cart access token. Useful when restoring from a cookie or persisted state.

      Parameters

      • token: string | null

      Returns void

    • Store the visitor's cookie consent on the cart. Call it whenever the visitor saves a choice, from Avvyr's banner or your own CMP. The snapshot follows the cart to the order and decides whether the purchase may be sent server-side to marketing channels. Rejects with 409 CART_CLOSED once the cart has become an order.

      Parameters

      Returns Promise<{ consent: CartConsent }>

    • Set customer type (private or business)

      Parameters

      • cartId: string
      • type: "private" | "business"

      Returns Promise<StorefrontCart>

    • Who the gift cards on a line go to, one per card (the line's product must be marked as a gift card). Replaces the line's list; fewer recipients than the quantity sends the rest to the buyer. The cards are issued when the order is paid and emailed on each sendOn day.

      Parameters

      Returns Promise<StorefrontCart>

    • Record the customer's choice. "split" splits the cart into shipments; set shipping on each with setShipmentShipping. "complete" or null goes back to one shipment. Changing the cart's contents afterwards resets the choice, so ask getShipmentOptions again. Throws 409 SPLIT_NOT_AVAILABLE when everything ships together.

      Parameters

      Returns Promise<StorefrontCart>

    • Set shipping on one shipment of a split cart. Pickup is only accepted where that shipment ships from (pickupWarehouse in getShipmentShippingOptions), never on a backorder.

      Parameters

      Returns Promise<StorefrontCart>

    • Set the goods quantities of a group. 0 removes a size, a new sku adds one with the group's choices. Charge lines follow on the server; to change a choice, remove the group and add again.

      Parameters

      • cartId: string
      • optionGroupId: string
      • items: { quantity: number; sku: string }[]

      Returns Promise<StorefrontCart>

    • New quantities on a set's lines: the total per line (0 removes it), by sku or lineItemId. A sku not in the set joins it. Use this, not remove + add, for a line in a set: an ordinary add never lands in a set.

      Parameters

      • cartId: string
      • setId: string
      • items: UpdateSetItem[] | null
      • __namedParameters: { layout?: SetLayout | null } = {}

      Returns Promise<StorefrontCart>

    • Check the cart's VAT registration number and store the result on the cart.

      For guest B2B, which has no account to hold the evidence. Set the number with setCustomer first.

      Whether it comes back verified decides whether the sale can be zero-rated, so treat valid: false and status: "unavailable" differently in the UI: the first means the number is not registered, the second means the EU service could not answer and VAT will be charged for now.

      Parameters

      • cartId: string

      Returns Promise<CartVatValidation>