Developer notes
Overview · Installation · Configuration · Usage · Developer notes · FAQ
How it plugs into CS-Cart
Section titled “How it plugs into CS-Cart”- Tender, not a discount.
calculate_cart(priority 220: after core gift certificates at 200, before store credit at 250) lowers$cart['total']by the card amounts, after taxes, shipping and promotions, like core gift certificates.allow_place_orderadds the card part back for the minimum order amount. - Locks.
allow_place_order_post(top-level order) takesGET_LOCKfor every card in the cart and keeps it until the request ends, then re-reads the balances; a parallel checkout with the same card waits and is refused. Every balance change (Cards::post) takes the card lock, opens a transaction, re-reads the balance withSELECT ... FOR UPDATE, writes one ledger row and updates the card. A booking with a reference key is written once (uniqueref_key): repeated hooks never book twice. - Orders.
place_orderbooks per leaf order and card (?:kv_gcp_usage, state A = taken, R = given back, P = Multi-Vendor parent plan). The parent stores the plan; each sub-order getsMoney::childShare()of it (proportional, last one takes the rest, never above its own total), filled from the cards in order;place_suborderslowers the remaining plan.change_order_status_postgives the money back on a restore status and takes it again on reopen (idempotent by the state);delete_ordergives it back. - Buying cards.
pre_add_to_cartvalidates the product form and buildsextra.kv_gcp(a browser-sentextra.kv_gcpis always dropped);get_cart_product_datasets the line price from it after checking it against the product again;get_cart_product_data_post_optionsmakes the line need no shipping;get_cart_product_data_postremoves catalog discounts. Cards are issued inchange_order_status_postwith the unique issue keyo:<order>:<item>:<unit>. - Codes. 80 random bits from
random_int()(32-symbol alphabet without look-alikes), stored as a tagged SHA-256 (lookup, unique), an encrypted copy (corefn_encrypt_text, checked against the hash on decrypt) and a mask. - Guessing lock.
Limiter: buckets per visitor (ClientIp::rateKey(), IPv4 /32, IPv6 /64; forwarded headers only from trusted proxies), stored as a keyed hash, one atomic upsert per wrong code. - Full page cache (4.21). The product page form is product data only (cacheable). Codes and balances appear only on the cart, checkout, balance and account pages (not cacheable); the account menu link sits in the session-dependent my-account block. Storefront GETs write nothing.
- PDF. Own small PDF writer (
Pdf): standard fonts (WinAnsi), shapes, JPEG artwork (PNG/WebP converted with GD), QR code (QrCode, ISO 18004 byte mode, level M), several pages.
| Table | Content |
|---|---|
kv_gcp_cards |
card: code hash / encrypted code / mask, issue key (unique), source, value, balance, status (A, B blocked, V void, E expired), order / item / unit, batch, design, recipient, sender, message, delivery state and date, expiry |
kv_gcp_ledger |
append-only bookings: type (issue, redeem, refund, void, adjust, expire), signed amount, balance after, order, staff member, note, unique reference key |
kv_gcp_usage |
order + card: amount, state, parent order, sequence |
kv_gcp_designs |
designs (colours; image = core image pair kv_gcp_design) |
kv_gcp_products |
gift card settings per product |
kv_gcp_batches |
generated batches and imports |
kv_gcp_attempts |
guessing lock buckets (dropped on uninstall) |
Invariant: balance = sum of the card’s ledger amounts >= 0 (Cards::verify()).
Order data for templates and documents
Section titled “Order data for templates and documents”fn_get_order_info() adds $order['kv_gcp']: paid (amount paid with cards), used (card mask, amount, state) and cards (cards bought with the order). Vendor payout details carry kv_gift_cards.
Template kv_gift_cards_pro_card (Design → E-mail templates; Twig, valid in 2.14 and 3.x). Variables: title, greeting, intro, message, store, amount, code, expires, how, shop_url, balance_url, colours bg, fg, accent. Development hosts (localhost, *.local, *.test) and $config['kv_gift_cards_pro_mail_off'] = true; write the message and the PDF to var/kv_gift_cards_pro/mail/ instead of sending.
php admin.php --dispatch=kv_gift_cards_pro.cron or index.php?dispatch=kv_gift_cards_pro.cron&key=<cron key>: due deliveries (claimed per card, retried up to 5 times), expiry, unpaid orders, lock cleanup. One run at a time (named lock).
Captcha Pro
Section titled “Captcha Pro”The hook kv_captcha_pro_get_forms registers the form kv_gcp_balance (dispatch kv_gift_cards_pro.balance).
Uninstall
Section titled “Uninstall”Retention (kv retention): cards, ledger, usage, designs, product settings and batches are kept unless Delete all gift card data on uninstall is on; the add-on settings are saved in ?:kv_keep and restored on install.
Not in 1.0.0
Section titled “Not in 1.0.0”Apple / Google Wallet passes, cards issued by vendors, balances in several currencies (balances are in the primary currency and shown converted), REST endpoints for a POS, a printed-card service.
File map
Section titled “File map”| Path | Purpose |
|---|---|
app/addons/kv_gift_cards_pro/Tygh/Addons/KvGiftCardsPro/ |
Cards, Locks, CartCards, Orders, Issuer, Products, Designs, Delivery, CardPdf, Pdf, QrCode, Limiter, ClientIp, Scheduler, Batches, Admin, Config, Money, Code, Retention, License, Upgrade |
controllers/backend/kv_gift_cards_pro.php, products.post.php |
Admin pages, product tab |
controllers/frontend/kv_gift_cards_pro.php, checkout.pre.php, checkout.post.php, products.post.php |
Apply / remove, promo field, balance, account page, cron URL, product form data |
design/backend/templates/addons/kv_gift_cards_pro/ |
Admin views, product tab, order panel |
var/themes_repository/responsive/templates/addons/kv_gift_cards_pro/ |
Product form, cart box, totals lines, balance page, account page |