diff --git a/make_post_sell/views/cart.py b/make_post_sell/views/cart.py index d5d7dee..d7202f2 100644 --- a/make_post_sell/views/cart.py +++ b/make_post_sell/views/cart.py @@ -403,38 +403,42 @@ def cart_checkout(request): elif cart.is_empty: msg = ("That cart is empty, you cannot checkout.", "error") - elif cart.physical_products and not cart.handling_option: - msg = ("Please select a handling option for your physical items.", "error") - - elif cart.physical_products and not request.user.active_address: - msg = ("Please add a shipping address to proceed with checkout.", "info") - request.session.flash(msg) - return HTTPFound("/u/addresses") - - elif cart.requires_payment and stripe_user_shop is None: - msg = ("Please enter your payment information.", "info") - request.session.flash(msg) - return HTTPFound("/billing") - - elif stripe_user_shop.active_card is None: - msg = ("Please make a payment method active.", "info") - request.session.flash(msg) - return HTTPFound("/billing") - else: - # make sure all coupon terms are met before proceeding. + # Validate coupons first error_messages = cart.validate_attached_coupons() if error_messages: for error_message in error_messages: request.session.flash((error_message, "error")) return HTTPFound(get_referer_or_home(request)) - # check inventory for physical products. - inventory_errors = cart.check_inventory(request.shop_location) - if inventory_errors: - for error_message in inventory_errors: - request.session.flash((error_message, "error")) - return HTTPFound(get_referer_or_home(request)) + # Check handling options, inventory, and address for physical products + if cart.physical_products: + inventory_errors = cart.check_inventory(request.shop_location) + if inventory_errors: + for error_message in inventory_errors: + request.session.flash((error_message, "error")) + return HTTPFound(get_referer_or_home(request)) + + if not cart.handling_option: + msg = ("Please select a handling option for your physical items.", "error") + request.session.flash(msg) + return HTTPFound(get_referer_or_home(request)) + + if not request.user.active_address: + msg = ("Please add a shipping address to proceed with checkout.", "info") + request.session.flash(msg) + return HTTPFound("/u/addresses") + + # Check for payment information + if cart.requires_payment and stripe_user_shop is None: + msg = ("Please enter your payment information.", "info") + request.session.flash(msg) + return HTTPFound("/billing") + + if stripe_user_shop.active_card is None: + msg = ("Please make a payment method active.", "info") + request.session.flash(msg) + return HTTPFound("/billing") msg = ("Please confirm your order.", "info") request.session.flash(msg)