Developer notes
Technical reference for developers who customize Quantity Break Offer Cards.
Add-on identity
Section titled “Add-on identity”| Item | Value |
|---|---|
| Add-on id | kv_quantity_break_offer_cards |
| Function prefix | fn_kv_quantity_break_offer_cards_ |
| Language variables | kv_quantity_break_offer_cards.* |
| CSS scope | .kv-qbo (BEM: .kv-qbo__card, .kv-qbo__badge, …) |
| PHP namespace | Tygh\Addons\KvQuantityBreakOfferCards |
How a discount is applied
Section titled “How a discount is applied”- The add-on keeps ONE core cart promotion whose bonus is
kv_qbo_offers(schemas/promotions/schema.post.php;Promotion::ensure()creates it on install). - The core promotion engine runs the bonus function
fn_kv_quantity_break_offer_cards_apply_bonus()->Engine::apply()for every cart calculation. - For every cart line
Offers::forProduct()finds the offer (the same function the product page uses),Pricing::tierFor()the card the total quantity of the product reaches,Pricing::unitDiscount()the per-unit discount in minor units of the primary currency. - The line gets a core product discount (
price,discount,promotions[<id>]['bonuses'][]with akv_qbonote holding offer id, card quantity and amount). No hook rewrites catalog prices.
Hooks used
Section titled “Hooks used”PHP: place_order (stores the lines that got an offer for the analytics), delete_order, delete_company, init_templater_post (upgrade synchronizer). Promotion schema: bonus kv_qbo_offers. Block manager schema: our tables are added to the cache update_handlers of the product blocks and of the main block (products.view, categories.view, …).
Template hooks: products:qty (pre: the cards, only on the product page and quick view), products:product_labels (post: list label), index:scripts, index:styles.
Hooks provided
Section titled “Hooks provided”None.
Database tables
Section titled “Database tables”| Table | Content |
|---|---|
?:kv_qbo_offers |
One row per offer: company, status, name, scope (all, products, categories), product / category / vendor / customer group ids, priority, stack flag |
?:kv_qbo_tiers |
The cards of an offer: quantity, mode (P percent, A amount off each unit, F fixed unit price), value, badge, title, hint, preselected |
?:kv_qbo_stats |
Daily counters per offer and card: views, picks |
?:kv_qbo_lines |
One row per order line that got an offer: order, offer, product, company, card quantity, quantity, discount, total |
Uninstall keeps the four tables unless “Delete all data on uninstall” is ticked.
Template overrides
Section titled “Template overrides”Storefront templates live in design/themes/<theme>/templates/addons/kv_quantity_break_offer_cards/. To change the card markup copy hooks/products/qty.pre.tpl to your own theme; do not edit the add-on’s files, they are replaced on update. Colours and radius are CSS variables on .kv-qbo (--kv-qbo-accent, --kv-qbo-accent-ink, --kv-qbo-ink, --kv-qbo-muted, --kv-qbo-line, --kv-qbo-surface, --kv-qbo-save, --kv-qbo-radius).
The script js/addons/kv_quantity_break_offer_cards/func.js reads the data attributes of the block (data-ca-kv-qbo, -input, -button, -click, -default, -track, -hide-qty, -url) and of each card (data-ca-kv-qbo-qty).
Storefront beacon
Section titled “Storefront beacon”POST index.php?dispatch=kv_qbo.track with events=[{"o":<offer id>,"t":<card quantity>,"a":"v"|"p"}] counts a view or a pick (at most 12 events per request and 40 per visitor address per minute, unknown offers and cards are ignored). It sets no cookie and stores no IP; the minute limit keeps only a short hash of the address in a cache file that is replaced every minute. The address comes from the “Client IP” settings tab (the connecting address unless you name a trusted proxy).
REST API
Section titled “REST API”Entity kv_qbo_offers (/api/kv_qbo_offers, or api.php?_d=kv_qbo_offers without URL rewriting). Authentication as for every CS-Cart API entity (administrator e-mail and API key). Vendor administrators work with their own offers when vendor offers are on.
| Method | Path | Purpose |
|---|---|---|
| GET | /api/kv_qbo_offers |
List (filters: status A or D; company_id for marketplace administrators) |
| GET | /api/kv_qbo_offers/<id> |
One offer with its cards |
| POST | /api/kv_qbo_offers |
Create. 201 with offer_id; 400 with message on invalid data |
| PUT | /api/kv_qbo_offers/<id> |
Update; fields not sent keep their value; tiers replaces all cards |
| DELETE | /api/kv_qbo_offers/<id> |
Delete (204) |
Body fields: name, status (A, D), scope (all, products, categories), product_ids, category_ids, include_subcats (Y, N), vendor_ids, usergroup_ids, priority, stack (Y, N) and tiers: a list of {qty, mode, value, badge, badge_text, title, hint, is_default}.
Send Content-Type: application/json; give DELETE an empty JSON body ({}) as CS-Cart rejects an empty body with that header.
curl -u admin@example.com:API_KEY -H "Content-Type: application/json" \ -d '{"name":"Sneakers","scope":"products","product_ids":[12],"tiers":[{"qty":2,"mode":"P","value":10},{"qty":3,"mode":"P","value":20,"badge":"popular","is_default":"Y"}]}' \ "https://shop.example.com/api/kv_qbo_offers"Upgrades
Section titled “Upgrades”The add-on ships the Upgrade Synchronizer: files replaced in place (Upgrade Center or manual upload) are followed by an idempotent step that re-creates the core promotion if it is missing, rewrites the core-named label and copies the storefront templates into themes that do not inherit from Responsive.