> ## Documentation Index
> Fetch the complete documentation index at: https://docs.aftersell.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Configure

> Every Aftersell Cart SDK configure option: drawer opening, add-to-cart interception, form validation, and money formatting.

`configure(config)` sets how the cart behaves. It's a **set-up call**, so it's safe at the very top of your script, before the cart has loaded.

```js theme={"theme":{"light":"snazzy-light","dark":"github-dark"}}
window.aftersell.cart.configure({
  open_on_add_to_cart: 'always',
  money_format: '${{amount}} USD',
});
```

You can call it more than once and values merge. A later call overrides only the keys it names, leaving the rest alone.

<Warning>
  **Passing `undefined` clears a key rather than skipping it.** `configure({ open_on_add_to_cart: undefined })` resets that option to its default, discarding whatever an earlier call set. To leave an option alone, omit the key entirely.
</Warning>

## Options

| Option                                                          | Values                             | Default        | Purpose                                                 |
| --------------------------------------------------------------- | ---------------------------------- | -------------- | ------------------------------------------------------- |
| [`open_on_add_to_cart`](#open_on_add_to_cart)                   | `'always'`, `'never'`, `'default'` | `'default'`    | Whether the drawer opens when an item is added.         |
| [`open_on_background_add`](#open_on_background_add)             | `boolean`                          | `false`        | Also open when something *else* adds to the cart.       |
| [`validate_form_on_add_to_cart`](#validate_form_on_add_to_cart) | `boolean`                          | `false`        | Block the add if the product form is invalid.           |
| [`skip_add_to_cart_interceptor`](#skip_add_to_cart_interceptor) | `boolean`                          | `false`        | Turn off Aftersell's add-to-cart interception entirely. |
| [`skip_open_cart_interceptor`](#skip_open_cart_interceptor)     | `boolean`                          | `false`        | Let a cart-icon click reach your other scripts.         |
| [`money_format`](#money_format)                                 | string                             | store's format | Override the format used by `formatMoney`.              |

***

## open\_on\_add\_to\_cart

Controls whether the drawer opens when a shopper adds a product.

| Value       | Behavior                                                                   |
| ----------- | -------------------------------------------------------------------------- |
| `'always'`  | Always open the drawer on add.                                             |
| `'never'`   | Never open it; the item is added silently.                                 |
| `'default'` | Follow the **Open cart when an item is added** setting in the cart editor. |

```js theme={"theme":{"light":"snazzy-light","dark":"github-dark"}}
// Always open, regardless of the merchant's cart setting.
window.aftersell.cart.configure({ open_on_add_to_cart: 'always' });
```

A common use is to keep the drawer shut on one specific page while leaving the merchant setting alone everywhere else:

```js theme={"theme":{"light":"snazzy-light","dark":"github-dark"}}
if (window.location.pathname.startsWith('/collections/')) {
  window.aftersell.cart.configure({ open_on_add_to_cart: 'never' });
}
```

<Note>
  If you just want this on for the whole store, it's already a setting: **Cart settings → Content → Behavior → Open cart when an item is added**. Use `configure` when the answer depends on the page, the shopper, or something only your code knows.
</Note>

## open\_on\_background\_add

Set this to `true` to also open the drawer for **background** adds — ones Aftersell detected but did not handle itself.

An add counts as background when either:

* it arrived through [Shopify's standard cart events](https://shopify.dev/docs/storefronts/themes/best-practices/standard-events) (always treated as background, whatever triggered it), or
* Aftersell saw the cart request on the wire with **no** trusted click or keypress in the preceding \~3 seconds — another app or script writing to the cart, for instance.

An add Aftersell saw on the wire that *did* follow a shopper's click is not a background add: it already opens the drawer per `open_on_add_to_cart`, with no need for this option.

```js theme={"theme":{"light":"snazzy-light","dark":"github-dark"}}
window.aftersell.cart.configure({ open_on_background_add: true });
```

This is an **additional gate, not an override**: a background add opens the drawer only if `open_on_add_to_cart` would have allowed it too. With `open_on_add_to_cart: 'never'`, this option does nothing.

<Tip>
  Reach for this when a third-party add button adds the item correctly but leaves the drawer closed. If the item never reaches the cart at all, that's an interception problem. See [`skip_add_to_cart_interceptor`](#skip_add_to_cart_interceptor) and the [page builder use case](/aftersell/cart/sdk-use-case-page-builder).
</Tip>

## validate\_form\_on\_add\_to\_cart

Runs the browser's native form validation (`reportValidity()`) before adding, and cancels the add if the form is invalid. Use it when your product form has required fields (an engraving message, a gift note, a required checkbox) that shoppers can currently skip.

```js theme={"theme":{"light":"snazzy-light","dark":"github-dark"}}
window.aftersell.cart.configure({ validate_form_on_add_to_cart: true });
```

The browser shows its own validation message on the offending field. Off by default, because a theme with a stray `required` attribute somewhere in the product form would otherwise start silently blocking add-to-cart.

## skip\_add\_to\_cart\_interceptor

Turns off Aftersell's add-to-cart interception completely. For what interception does and every way to opt out of it, see [Add-to-cart interception](/aftersell/cart/add-to-cart-interception).

The theme then performs the add itself, and every script listening on that submit runs again. Aftersell still watches for the cart request on the wire, so the drawer opens as usual. You don't lose it by opting out. On themes Aftersell recognizes, the theme's own cart stays inert, so you won't get two carts. On a theme it doesn't recognize, the theme may open its own cart alongside yours; see [Will the theme's cart open too?](/aftersell/cart/add-to-cart-interception#will-the-themes-cart-open-too).

```js theme={"theme":{"light":"snazzy-light","dark":"github-dark"}}
window.aftersell.cart.configure({ skip_add_to_cart_interceptor: true });
```

<Warning>
  This one is read **once, at boot**. It only works from a set-up call that runs before the cart loads: your cart's **Initialization** script. Setting it later (inside `ready()`, or from an event handler) has no effect, and fails silently.
</Warning>

This is a blunt instrument that disables interception for every form on the page. To exempt just one form, use the [`registerSkipAddToCartRule`](/aftersell/cart/sdk-hooks#registerskipaddtocartrule) hook instead:

```js theme={"theme":{"light":"snazzy-light","dark":"github-dark"}}
// Preferred: exempt only the forms you own.
window.aftersell.cart.hooks.registerSkipAddToCartRule((form) =>
  form.hasAttribute('data-skip-aftersell')
);
```

## skip\_open\_cart\_interceptor

Clicking the cart icon opens the Aftersell drawer. To do that reliably, Aftersell stops the click so nothing else on the page handles it, which also stops **your** scripts from seeing it. If an analytics or pixel event fires everywhere except the cart icon, this is why.

Set this to `true` to stop silencing the click:

```js theme={"theme":{"light":"snazzy-light","dark":"github-dark"}}
window.aftersell.cart.configure({ skip_open_cart_interceptor: true });
```

Your listeners then run, and the drawer still opens exactly as before. The click also still doesn't navigate to `/cart`.

<Warning>
  **This does less than the name suggests.** It doesn't skip the cart-icon interceptor. It only stops it silencing other listeners. Aftersell still handles the click and still opens your cart. For a control that Aftersell should ignore completely, use the `aftersell-cart-wont-open-cart` class instead; see [Add-to-cart interception](/aftersell/cart/add-to-cart-interception#the-cart-icon-is-separate).
</Warning>

Unlike [`skip_add_to_cart_interceptor`](#skip_add_to_cart_interceptor), this one is read **on every click**, so you can set it at any point and it takes effect immediately: from `ready()`, an event handler, or conditionally per page.

<Note>
  Some themes also respond to the cart-icon click themselves. Once Aftersell stops silencing it, a theme that opens its own drawer will do so alongside yours. If you see two carts after turning this on, add the `aftersell-cart-wont-open-cart` class to the theme's icon and open the cart from your own handler with [`actions.open()`](/aftersell/cart/sdk-actions#open-and-close).
</Note>

## money\_format

Overrides the [Shopify money format](https://shopify.dev/docs/api/liquid/filters/money) that [`formatMoney`](/aftersell/cart/sdk-actions#formatmoneycents) uses. Defaults to your store's own format; if that's unavailable, prices fall back to `$X.XX`.

```js theme={"theme":{"light":"snazzy-light","dark":"github-dark"}}
window.aftersell.cart.configure({ money_format: '${{amount}} USD' });

// Later:
window.aftersell.cart.actions.formatMoney(5779); // "$57.79 USD"
```

Because `configure` merges and `formatMoney` reads the live value, you can change the format at runtime, for example when a currency switcher fires:

```js theme={"theme":{"light":"snazzy-light","dark":"github-dark"}}
window.myTheme.onCurrencyChange((currency) => {
  window.aftersell.cart.configure({ money_format: FORMATS[currency] });
  window.aftersell.cart.actions.visualRefresh(); // repaint prices already on screen
});
```

<Note>
  This changes how the SDK and the cart *display* prices. It doesn't change the currency the shopper is charged; that's Shopify Markets.
</Note>

## Where to go next

* **[Actions](/aftersell/cart/sdk-actions)**: read and change the cart.
* **[Hooks](/aftersell/cart/sdk-hooks)**: per-form and per-line control, where `configure` is too broad.
* **[Use cases](/aftersell/cart/sdk-use-cases)**: complete solutions to common requests.
