We can store new coupons and make queries to retrieve existing coupons. Now we need a way for customers to apply coupons to their purchases. The functionality to apply a coupon would be as follows:
- The user adds products to the shopping cart.
- The user can enter a coupon code in a form displayed in the shopping cart detail page.
- When a user enters a coupon code and submits the form, we look for an existing coupon with the given code that is currently valid. We have to check that the coupon code matches the one entered by the user that the active attribute is True, and that the current datetime is between the valid_from and valid_to values.
- If a coupon is found, we save it in the user's session and display ...