Retail storefront / Cart and checkout
Keeping cart rewards and checkout discounts in step
A gift qualification flow and a Shopify Function that share the same rules.
The problem
A cart reward is only useful if the visible promise and the checkout calculation agree. Gift eligibility changes as products are added or removed; customers may change their chosen gift; and the same variant may also be purchased as an ordinary paid item.
The work combined storefront gift management with a move from legacy discount logic to a Shopify Function. It needed a clear division of responsibility: the storefront manages the gift lines, while the Function determines discounts on the lines that reach checkout.
My contribution
I built and iterated the cart reward behaviour and its discount Function. I worked on tier qualification, gift-line reconciliation, shared shop-metafield configuration, gift attribution, review fixes and focused tests for additional discount-code rules.
I also scoped the Function migration and revised the estimate as the requirements became clearer. We moved from a proposed separate settings interface to editable shop metafields, giving both parts of the implementation a shared configuration.
How I approached it
I used shared configuration so that the storefront and Function could refer to the same thresholds and permitted gift variants. Promotional attribution distinguished a reward line from a customer’s ordinary paid purchase of that same variant.
On the storefront, I reconciled eligibility after cart changes, normalised eligible gift quantities, removed gifts below their threshold and queued overlapping validations. Gift-variant swaps included a specific recovery path when the replacement variant was unavailable.
The solution
The resulting implementation separated two related concerns: storefront code inserts, removes and reconciles gifts; the Function discounts qualifying attributed lines already present in the cart. This distinction matters because a discount Function is not the component adding products to the basket.
I added focused tests for zero or one entered code, additional rejectable codes, non-rejectable codes and their interaction with gift discounts.
The outcome
I built the storefront and Function changes and worked through review revisions. My focus was keeping gift eligibility and discount calculation consistent as customers changed their baskets.
I don’t have a confirmed launch date for the combined changes or post-launch sales figures. The intended benefit was a reward offer the merchant could maintain and customers could use consistently.