Skip to content

Developer notes

The add-on adds a promotion condition kv_ccp_batch in schemas/promotions/schema.post.php. All batches of a promotion sit in one nested group set to any, so a code from any batch satisfies the promotion. Its value is the batch ID, and its field_function is fn_kv_coupon_codes_pro_condition, which returns the batch ID when the cart holds a valid code of that batch. The promotion stores one short condition however many codes there are. Core’s coupon_code condition would keep all codes in conditions and search conditions_hash with LIKE.

Core expects a coupon to be found in conditions_hash (fn_promotion_check_coupon). get_promotions_pre narrows that lookup to the promotion of the batch when the code is ours.

Core hides the coupon field when no promotion has a coupon condition, so promotion_apply_pre sets has_coupons while batches exist.

Table Contents
?:kv_ccp_batches Name, promotion, pattern, limits
?:kv_ccp_codes Code (unique), status, max_uses, used, expires_at
?:kv_ccp_usage One row per code and order: total, discount, released
Hook Purpose
get_promotions_pre Coupon lookup for own codes
promotion_apply_pre Coupon field; code from a link
pre_place_order Atomic used + 1, refuses a code that ran out
place_order Usage row, parent orders only
change_order_status_post Gives a use back, or takes it again
delete_order, delete_promotions_post Clean up

All exist with the same arguments in 4.17.2 and 4.21.2. Generation uses random_int().

kv_coupon_codes_pro.apply is a GET dispatch outside the cacheable list. It stores the code in the session and redirects. to must be a path on the store.

No storefront output. The link writes the session on its own address, so the page behind it can stay cached.

Codes::isOn() is checked in the condition, when applying a link and when generating.