BuyBox
Product buy box control with variants, quantity, pricing, and add-to-cart.
import { BuyBox } from "@schukai/monster/source/components/form/buy-box.mjs";Introduction
The monster-buy-box control combines product configuration, variant selection, quantity, pricing, and add-to-cart into a single, cohesive UI. It supports static configuration as well as data sourced from REST endpoints through a datasource and mapping options.
Key Features
- Variant selection: Uses
monster-variant-selectinternally, including row selects and combined select layouts. - Pricing logic: Handles price, list price, base price, currency, tax rate, and quantity-based tiers.
- Quantity rules: Supports min/max, step, and allowed ranges (including open ranges).
- Cart integration: Posts payloads directly or forwards them to a shared
monster-cart-control. - Remote mapping: Maps product, variant, and pricing fields from API responses with path templates.
Variants
Variants are configured through the variants option. Define dimensions (such as size and color) and provide data rows that represent each SKU.
Pricing
Pricing can be defined globally or per-variant. When per-variant pricing is present, the buy box switches pricing fields based on the selected SKU. Tier pricing can be used to apply volume discounts by quantity.
Data Sources
The buy box can fetch product, stock, or pricing data from endpoints via a datasource. Mapping options allow adapting different API shapes without changing the UI logic.
Cart Flow
When the user submits the buy box, a payload is created from the current selection. The payload can be sent directly to the configured cart URL or routed through a cart control for shared cart state and optimistic UI feedback.
Basic Buy Box
A basic buy box with static product data, variants, and tier pricing. It uses slots for title and info and configures the control entirely through options.
Soft cotton, regular fit.
Ships in 2-3 days.
Javascript
import '@schukai/monster/source/components/form/buy-box.mjs';
const box = document.getElementById('buy-box-basic');
box.setOption('product', {
sku: 'TSHIRT-001',
name: 'Classic Tee',
currency: 'EUR',
taxIncluded: true,
taxRate: 19,
delivery: '2-3 days',
stock: 12,
unitLabel: 'pcs'
});
box.setOption('pricing', {
price: 29.9,
listPrice: 39.9,
basePrice: 29.9,
basePriceUnit: '1 pcs',
tiers: [
{ min: 1, price: 29.9 },
{ min: 5, price: 27.9 },
{ min: 10, price: 24.9 }
]
});
box.setOption('variants', {
dimensions: [
{ key: 'color', label: 'Color' },
{ key: 'size', label: 'Size' }
],
data: [
{ id: 'TS-RED-S', color: 'Red', size: 'S' },
{ id: 'TS-RED-M', color: 'Red', size: 'M' },
{ id: 'TS-BLU-M', color: 'Blue', size: 'M' }
]
});
box.setOption('quantity', {
min: 1,
max: 20,
step: 1
});HTML
<monster-buy-box id="buy-box-basic">
<span slot="title">Classic Tee</span>
<p slot="info">Soft cotton, regular fit.</p>
<p slot="shipping">Ships in 2-3 days.</p>
</monster-buy-box>Stylesheet
/** no additional stylesheet is defined **/Component Design
The monster-buy-box control uses Shadow DOM to keep its internal structure and styles isolated. Styling hooks are exposed via exported parts and slots.
Slots
title: Header area above the product configuration.info: Optional description or marketing text.shipping: Shipping or delivery notes.footer: Additional content below the actions.
Exported Parts
Use ::part() to style key regions such as pricing, quantity, and actions:
header,body,slotsvariants,variants-controlquantity,quantity-label,quantity-control,quantity-inputprices,price,list-price,sum,base-price,tax,totalactions,submit,submit-label
monster-buy-box::part(price) {
font-size: 1.4rem;
font-weight: 700;
}
monster-buy-box::part(submit) {
min-width: 10rem;
}
HTML Structure
<monster-buy-box></monster-buy-box>JavaScript Initialization
const element = document.createElement('monster-buy-box');
document.body.appendChild(element);Exported
BuyBoxDerived from
CustomControlOptions
The Options listed in this section are defined directly within the class. This class is derived from several parent classes, including the CustomElement class. Therefore, it inherits Options from these parent classes. If you cannot find a specific Options in this list, we recommend consulting the documentation of the CustomControl.
- since
- deprecated
Properties and Attributes
The Properties and Attributes listed in this section are defined directly within the class. This class is derived from several parent classes, including the CustomElement class and ultimately from HTMLElement. Therefore, it inherits Properties and Attributes from these parent classes. If you cannot find a specific Properties and Attributes in this list, we recommend consulting the documentation of the CustomControl.
data-monster-options: Sets the configuration options for the collapse component when used as an HTML attribute.data-monster-option-[name]: Sets the value of the configuration option[name]for the collapse component when used as an HTML attribute.
Methods
The methods listed in this section are defined directly within the class. This class is derived from several parent classes, including the CustomElement class and ultimately from HTMLElement. Therefore, it inherits methods from these parent classes. If you cannot find a specific method in this list, we recommend consulting the documentation of the CustomControl.
Behavioral methods
refresh()- {BuyBox}
Static methods
[instanceSymbol]()- {symbol}
instanceof operator.getCSSStyleSheet()- {CSSStyleSheet[]}
getTag()- {string}
Lifecycle methods
Lifecycle methods are called by the environment and are usually not intended to be called directly.
[assembleMethodSymbol]()- {BuyBox}
Events
The component emits the following events:
monster-buy-box-changemonster-buy-box-validmonster-buy-box-invalidmonster-buy-box-submitmonster-buy-box-successmonster-buy-box-errormonster-buy-box-loaded
For more information on how to handle events, see the mdn documentation.