From 660e6d7ed69ee0f72548328ec4b2a4d79926a902 Mon Sep 17 00:00:00 2001 From: Russell Ballestrini Date: Sun, 16 Jun 2024 15:49:45 -0400 Subject: [PATCH] save handling option in frontend and recalculate handling when shop is switched. modified: templates/cart.j2 modified: views/cart.py modified: views/shop_location.py --- make_post_sell/templates/cart.j2 | 8 ++++---- make_post_sell/views/cart.py | 7 ++++++- make_post_sell/views/shop_location.py | 15 +++++++++++++++ 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/make_post_sell/templates/cart.j2 b/make_post_sell/templates/cart.j2 index 67999db..a422cd1 100644 --- a/make_post_sell/templates/cart.j2 +++ b/make_post_sell/templates/cart.j2 @@ -135,19 +135,19 @@

Physical Handling Options

{% if request.shop_location.local_pickup %} - +
{% endif %} {% if request.shop_location.local_delivery %} - +
{% endif %} {% if request.shop_location.local_shipping %} - +
{% endif %} {% if request.shop_location.international_shipping %} - +
{% endif %} diff --git a/make_post_sell/views/cart.py b/make_post_sell/views/cart.py index 97f42c9..f384b5d 100644 --- a/make_post_sell/views/cart.py +++ b/make_post_sell/views/cart.py @@ -369,7 +369,7 @@ def cart_handling_option(request): request.dbsession.flush() request.session.flash(("Handling option set successfully.", "success")) - return HTTPFound("/u/cart/{}".format(cart.id)) + return HTTPFound(f"/cart/{cart.id}") @view_config(route_name="cart_checkout", renderer="cart_checkout.j2") @@ -407,6 +407,11 @@ def cart_checkout(request): request.session.flash(msg) return HTTPFound("/billing") + elif cart.physical_products and not cart.handling_option: + msg = ("Please select a handling option for your physical items.", "error") + request.session.flash(msg) + return HTTPFound(f"/cart/{cart.id}") + else: # make sure all coupon terms are met before proceeding. error_messages = cart.validate_attached_coupons() diff --git a/make_post_sell/views/shop_location.py b/make_post_sell/views/shop_location.py index 6c22e54..934f669 100644 --- a/make_post_sell/views/shop_location.py +++ b/make_post_sell/views/shop_location.py @@ -196,5 +196,20 @@ def shop_location_switch(request): (f"You are now viewing the {location.name} shop location", "success") ) + # Recalculate the handling cost based on the new location + cart = request.active_cart + if cart.handling_option: + if cart.handling_option == "local_pickup": + cart.handling_cost_in_cents = 0 + elif cart.handling_option == "local_delivery": + cart.handling_cost_in_cents = location.local_delivery_rate_in_cents + elif cart.handling_option == "local_shipping": + cart.handling_cost_in_cents = location.local_shipping_rate_in_cents + elif cart.handling_option == "international_shipping": + cart.handling_cost_in_cents = location.international_shipping_rate_in_cents + + request.dbsession.add(cart) + request.dbsession.flush() + # Redirect to the next URL or the shop home page return HTTPFound(next_url)