Developer reference
Breakly storefront events and their event.detail fields, theme hooks, CSS classes, --bk custom properties, and how the Shopify Functions discount applies.
This page is for developers who connect Breakly's widget to a theme, a tracking script or another app.
Storefront events#
The widget dispatches two DOM events. Both are CustomEvents that bubble from the widget's root element (.breakly), so you can listen on document.
| Event | When it fires |
|---|---|
breakly:tier-change |
The shopper picks another tier, changes the variant in your theme's picker, or changes an item's variant in the per-item pickers. It can also fire once during page load, when the widget finishes loading its item pickers or theme price feature. |
breakly:add |
The shopper presses your theme's add to cart button, or Buy it now or another button in Shopify's payment button container. It fires before the add request. |
A click on add to cart and the form submit it causes fire breakly:add once.
event.detail#
Both events carry the same detail object:
| Field | Type | Content |
|---|---|---|
productId |
number | The product's numeric ID. |
quantity |
number | The chosen tier's quantity. |
units |
number[] | One variant ID per item, quantity entries long. Without per-item picks, every entry is the selected variant. |
total |
number | The chosen tier's price for these items, in cents of the cart currency. |
regular |
number | The same items at their regular price, in cents of the cart currency. |
currency |
string | The cart's ISO 4217 currency code, such as "USD". |
Amounts are integer cents: total / 100 is the amount in the currency's main unit. The saving is regular - total.
document.addEventListener("breakly:tier-change", (event) => {
const { quantity, total, regular, currency } = event.detail;
console.log(quantity, (regular - total) / 100, currency);
});
document.addEventListener("breakly:add", (event) => {
const { quantity, total, currency } = event.detail;
// Send an add-to-cart event to your analytics tool.
});
The events are informational. Calling preventDefault() doesn't stop the add.
Theme hooks#
Two data attributes let you point Breakly at your theme's own elements. Put them inside the product's section, the element with the shopify-section class.
| Attribute | Put it on | Used by |
|---|---|---|
data-breakly-price |
The element that shows the product price | Update the theme's price in Design |
data-breakly-variants |
Your theme's variant picker | Hide the theme's variant picker when shoppers pick per item in Design |
<div class="product__price" data-breakly-price>
{{ product.selected_or_first_available_variant.price | money }}
</div>
<div class="custom-variant-picker" data-breakly-variants>
…
</div>
For the price:
- Breakly writes the tier price into the first visible element that matches. Put the attribute on the element that holds the price text, or on a wrapper with a single child.
- An element with other child elements is skipped.
- Elements inside
sordel, such as compare-at prices, are skipped. - Breakly also recognizes common markup, including Dawn's and Horizon's price elements, so you need the attribute only when your theme isn't recognized.
CSS classes and custom properties#
You can style the widget with Custom CSS in Design. Breakly scopes every selector to .breakly. See Custom CSS for what it removes.
Root element#
The root element is div.breakly. It carries these attributes and modifier classes:
| Class or attribute | Meaning |
|---|---|
data-breakly |
Marks a widget. |
data-placement |
"block" for the Quantity breaks block, "embed" for auto placement. |
data-product-id |
The product's numeric ID. |
.breakly--stack, .breakly--columns, .breakly--compact, .breakly--list, .breakly--table, .breakly--grid |
The layout: Cards, Columns, Compact, List, Table, Grid. |
.breakly--p-theme, .breakly--p-outline, .breakly--p-soft, .breakly--p-solid, .breakly--p-ticket, .breakly--p-mono |
The template. |
.breakly--sp-tight, .breakly--sp-roomy |
Spacing. Normal has no class. |
.breakly--b-sticker, .breakly--b-tag |
Badge style. Pill has no class. |
.breakly--h-plain, .breakly--h-hidden |
Heading style. Centered between lines has no class. |
.breakly--caps |
Capital letters in tier titles. |
.breakly--sw-small, .breakly--sw-large, .breakly--sw-square |
Swatch size and shape. Medium circles have no class. |
To target a modifier, write it on the root: .breakly.breakly--p-soft .breakly__tier. Custom CSS keeps selectors that start with .breakly as written.
Elements#
| Class | Element |
|---|---|
.breakly__group |
The fieldset around the widget. |
.breakly__heading |
The heading (a legend; its text is in a span). |
.breakly__hint |
The mix and match or per variant hint. |
.breakly__thead |
The column headings of the Table layout. |
.breakly__tiers |
The list of tiers (role="radiogroup"). |
.breakly__tier |
One tier, a label with data-tier set to its quantity. Has .is-selected when chosen, .has-badge with a badge and .has-pickers when the item pickers follow it. |
.breakly__radio |
The tier's hidden radio input. |
.breakly__dot |
The radio dot. |
.breakly__text |
Wraps title, saving and subtitle. |
.breakly__title |
The tier title. |
.breakly__save |
The savings chip. |
.breakly__sub |
The subtitle. |
.breakly__price |
Wraps the prices. |
.breakly__total |
The tier total. |
.breakly__compare |
The struck-through compare-at total (an s element). |
.breakly__unit |
The price per item. |
.breakly__badge |
The badge. |
.breakly__pickers |
The per-item picker box. |
.breakly__unitrow |
One item row. |
.breakly__thumb |
The variant image of an item. |
.breakly__selects |
The pickers of one item. |
.breakly__select |
An option dropdown. |
.breakly__swatches |
A group of swatches. |
.breakly__swatch |
A swatch button, with aria-pressed="true" when chosen. .breakly__swatch--text is a swatch that shows the value as text. |
A tier waiting for a currency conversion has the data-pending attribute.
Custom properties#
| Property | Controls |
|---|---|
--bk-accent |
Accent color: chosen tier ring, dot, badge and savings. |
--bk-on-accent |
Text on the accent. |
--bk-radius |
Corner radius. |
--bk-text, --bk-text-sel |
Text color, and text color of the chosen tier. |
--bk-price |
Tier total color. |
--bk-card, --bk-card-sel |
Card background, and background of the chosen tier. |
--bk-border, --bk-border-w |
Card border color and width. |
--bk-ring |
Outline color of the chosen tier. |
--bk-badge, --bk-badge-text |
Badge background and text. |
--bk-save |
Savings chip color. |
--bk-line |
Divider and outline lines. |
--bk-muted |
Secondary text, such as subtitles and prices per item. |
--bk-tint |
Light accent tint. |
--bk-pad-y, --bk-pad-x, --bk-gap |
Card padding and the gap between tiers. |
--bk-title-size, --bk-title-weight, --bk-price-size |
Tier title size and weight, and total size. |
--bk-swatch, --bk-swatch-radius |
Swatch size and corner radius. |
--bk-notch |
Size of the side notches of the Ticket template. |
.breakly { --bk-gap: .5em; --bk-border-w: 2px; }
.breakly__tier.is-selected .breakly__title {
text-decoration: underline;
}
Design settings write some of these properties on the widget's style attribute: the accent, the corner radius, the title weight, any size other than Default and every element color you set. With automatic accent and corners, the widget's script also sets --bk-accent, --bk-on-accent and --bk-radius there. A custom CSS value only wins over those with !important. Prefer the Design settings for them.
Classes outside the widget#
Breakly adds these classes to your theme's elements. Custom CSS can't reach them, because it is scoped to the widget, but your theme's CSS can.
| Class | Added to |
|---|---|
.breakly-hidden-qty |
Your theme's quantity selector, when Hide the theme's quantity selector is on. |
.breakly-hidden-variants |
Your theme's variant picker, while the item pickers replace it. |
.breakly-qty-row, .breakly-grow |
The row and button around a hidden quantity, so the button keeps the full width. |
.breakly-buy-now |
The product form, when Highlight Buy it now is on. It sets --bk-buy and --bk-on-buy on the form. |
How the discount is applied at checkout#
Breakly applies its tiers with a Shopify Function, a product discount that runs in Shopify's cart and checkout.
- The store has one automatic app discount, titled Breakly quantity breaks. It covers every offer.
- The function reads each product's offer and counts the cart's items by product, by variant, or across the offer for mix and match.
- The discount on each cart line shows the tier's checkout message as its title.
- The widget and the function use the same integer-cent formula. Breakly tests both against the same price vectors, so the price on the product page is the price at checkout.
- Gift cards are never discounted. Subscription lines and B2B buyers are left out when the offer excludes them.
- For schedules, the function uses your store's local date and Breakly's list of offers running now, which Breakly refreshes every minute. For countries, it uses the buyer's country at checkout.
- In other currencies, it converts amounts set in your store currency with Shopify's presentment currency rate.
How each discount type reaches the cart:
| Discount | Discount on the cart line |
|---|---|
| % off each, Amount off each, Fixed price each | A fixed amount off each item. |
| Buy X, get Y free | 100% off the free items of the cheapest lines. |
| Fixed total for the tier | One fixed amount off across the counted lines. |
Combinations#
The Breakly discount is created to combine with product discounts and shipping discounts, and with order discounts when Shopify allows it. If Shopify refuses the order combination, Breakly creates the discount without it.
On each item, Shopify applies only the better product discount for the customer. A product discount code or another app's product discount on the same item doesn't add up with a Breakly tier.
Discounts page#
In your Shopify admin, Create discount with Breakly opens a new offer in Breakly. Opening the Breakly discount from Discounts opens Breakly's Offers page.