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 treatsnullas no cart and offers no price. Nothing is reported toonErroreither. It decides again on therefresh()after a cart is created.
What to follow
| Item | Rule |
|---|---|
| Return the latest state | Don'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 lines | Return all lines, including Checkout+ product lines. For carts with more than 250 lines, fetch the remaining lines too |
| Values for each line | Return 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 null | Only 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
nullor partial values when the response haserrors, the SDK treats the cart or the benefit set as missing. Failures such as missing permissions never reachonError. - If a line has no
tagsfield,invalid-cartis delivered toonErrorand 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
unavailabletoonError. On that page, later calls torefresh()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. InsideprepareCheckout(), it completes without adding Checkout+. - When the returned value has the wrong shape:
invalid-cartis delivered toonError, and the banner is not shown. This includes when themetafieldfield is missing or doesn't match the type in the table below.
Return value (CheckoutPlusCart)
| Field | Type | Value | What the SDK uses it for |
|---|---|---|---|
currency | string | The 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 } | null | The Checkout+ metafield, as fetched from the Storefront API. null if there is no metafield | Reads the benefit set to determine the range and the price |
lines | CheckoutPlusCartLine[] | Every line of the cart | See the table below |
- When
metafieldisnull:not-publishedis delivered toonError. Whenmetafield.valuecan't be read as a benefit set,invalid-benefit-setis delivered. In both cases, the banner is not shown.
Fields of each line in lines (CheckoutPlusCartLine).
| Field | Type | Value | What the SDK uses it for |
|---|---|---|---|
id | string | The line ID (Storefront API CartLine.id) | Specifies which lines to remove (change.remove) |
variantId | string | The variant ID (merchandise.id) | Determines the range of the Checkout+ product |
productHandle | string | The product handle (merchandise.product.handle) | Identifies Checkout+ product lines (handles that start with rcmr-checkout-plus-) |
title | string | The product name | Shown in the excluded-item notice |
quantity | number | The quantity | Calculation for benefit sets that set the range by quantity |
lineTotal | string | The 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 separators | The total that determines the range |
tags | string[] | The product tags (merchandise.product.tags). An empty array for products without tags | Identifies 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 null | Identifies Checkout+ products added on a previous screen. Checks that the attributes of regular lines have not been changed |
© Recustomer, Inc.