Docs
STEP 3-2

getCart: Get the cart (CartConnector)

getCart(): Promise<CheckoutPlusCart | null>

A CartConnector function that the SDK user implements. The SDK uses this function to get the latest cart. An implementation example is in Step 2: Implement CartConnector.

  • Return value: Promise<CheckoutPlusCart | null>. The SDK treats null as no cart and offers no price. Nothing is reported to onError either. It decides again on the refresh() after a cart is created.

What to follow

ItemRule
Return the latest stateDon't use a cache (in the browser, or on the server if you go through one); return the cart fetched from the Storefront API every time. When the cart is fetched right after an update, the change is reflected. Don't return the cart state held by your UI
Return all linesReturn all lines, including Checkout+ product lines. For carts with more than 250 lines, fetch the remaining lines too
Values for each lineReturn the product handle, tags, and line attributes (including the Checkout+ marker _rcmr_checkout_plus). Return tags (tags) on every line, whether or not the store has exclusion tags. For a product without tags, return an empty array []
When to return nullOnly when the cart doesn't exist. If fetching fails, throw an exception. If the Storefront API response has errors, treat it as a failed fetch even when data is returned
  • If you return from a cache, two Checkout+ product lines may end up in the cart after an update whose result was unknown.
  • If you return null or partial values when the response has errors, the SDK treats the cart or the benefit set as missing. Failures such as missing permissions never reach onError.
  • If a line has no tags field, invalid-cart is delivered to onError and the banner is not shown, even in stores without exclusion tags. Exclusion tags can be set later.

When it throws

  • How the SDK handles it: It treats the fetch as failed, does not show the banner, and delivers unavailable to onError. On that page, later calls to refresh() complete without doing anything, and the banner isn't shown again. What happens after a failed fetch is in the "The cart cannot be fetched" row of the table in What the SDK does for each trigger. Inside prepareCheckout(), it completes without adding Checkout+.
  • When the returned value has the wrong shape: invalid-cart is delivered to onError, and the banner is not shown. This includes when the metafield field is missing or doesn't match the type in the table below.

Return value (CheckoutPlusCart)

FieldTypeValueWhat the SDK uses it for
currencystringThe cart currency (ISO 4217, e.g. JPY)Checks whether it matches the currency of the benefit set (the commitment charge and benefits for each range). The banner is not shown for carts in a different currency (benefit sets are currently in Japanese yen only)
metafield{ value: string } | nullThe Checkout+ metafield, as fetched from the Storefront API. null if there is no metafieldReads the benefit set to determine the range and the price
linesCheckoutPlusCartLine[]Every line of the cartSee the table below
  • When metafield is null: not-published is delivered to onError. When metafield.value can't be read as a benefit set, invalid-benefit-set is delivered. In both cases, the banner is not shown.

Fields of each line in lines (CheckoutPlusCartLine).

FieldTypeValueWhat the SDK uses it for
idstringThe line ID (Storefront API CartLine.id)Specifies which lines to remove (change.remove)
variantIdstringThe variant ID (merchandise.id)Determines the range of the Checkout+ product
productHandlestringThe product handle (merchandise.product.handle)Identifies Checkout+ product lines (handles that start with rcmr-checkout-plus-)
titlestringThe product nameShown in the excluded-item notice
quantitynumberThe quantityCalculation for benefit sets that set the range by quantity
lineTotalstringThe line total after quantity and line-level discounts (Storefront API cost.totalAmount.amount as is). A decimal string in the standard unit of the cart currency (e.g. '8000', '49.99'). Don't convert it to Japanese yen, round it to an integer, or add currency symbols or thousands separatorsThe total that determines the range
tagsstring[]The product tags (merchandise.product.tags). An empty array for products without tagsIdentifies excluded products
attributes{ key, value }[]The line attributes (including _rcmr_checkout_plus). An empty array for lines without attributes. Leave out attributes whose value is nullIdentifies Checkout+ products added on a previous screen. Checks that the attributes of regular lines have not been changed
© Recustomer, Inc.