π§© Current Code Situation
The coupon system (CARA20: 20% off, WELCOME10: 10% off) is implemented twice, independently, in two separate files:
app.js β used on cart.html, bound to #apply-coupon-btn / #coupon-code
js/coupon-validator.js β used on checkout.html, bound to #applyCouponBtn / #couponCodeInput
Both hardcode the same coupon codes and discount percentages separately. There is no shared source of truth. If a coupon is added, removed, or its discount percentage changes, both files must be updated in sync manually β miss one and cart.html/checkout.html will silently disagree on what a coupon is worth.
π§ Reason for Refactor
Extract the coupon codes/percentages into a single shared file, js/coupon-config.js, exposing window.CARA_COUPONS. Update both app.js and js/coupon-validator.js to read from this shared object instead of maintaining their own hardcoded copies. Load the new config script before both consumers on cart.html and checkout.html.
π§ Proposed Refactor Plan
Not a live user-facing bug β both implementations currently work correctly on their respective pages. This is a maintainability/consistency risk: future coupon changes require remembering to update two unrelated files.
β
Checklist
π§© Current Code Situation
The coupon system (CARA20: 20% off, WELCOME10: 10% off) is implemented twice, independently, in two separate files:
app.jsβ used oncart.html, bound to#apply-coupon-btn/#coupon-codejs/coupon-validator.jsβ used oncheckout.html, bound to#applyCouponBtn/#couponCodeInputBoth hardcode the same coupon codes and discount percentages separately. There is no shared source of truth. If a coupon is added, removed, or its discount percentage changes, both files must be updated in sync manually β miss one and
cart.html/checkout.htmlwill silently disagree on what a coupon is worth.π§ Reason for Refactor
Extract the coupon codes/percentages into a single shared file,
js/coupon-config.js, exposingwindow.CARA_COUPONS. Update bothapp.jsandjs/coupon-validator.jsto read from this shared object instead of maintaining their own hardcoded copies. Load the new config script before both consumers oncart.htmlandcheckout.html.π§ Proposed Refactor Plan
Not a live user-facing bug β both implementations currently work correctly on their respective pages. This is a maintainability/consistency risk: future coupon changes require remembering to update two unrelated files.
β Checklist