diff --git a/make_post_sell/models/cart.py b/make_post_sell/models/cart.py index a751036..7e9c6c7 100644 --- a/make_post_sell/models/cart.py +++ b/make_post_sell/models/cart.py @@ -156,6 +156,15 @@ class Cart(RBase, Base): tmp_cart[product_id] += count else: tmp_cart[product_id] = count + + self.handling_option = other.handling_option + self.handling_cost_in_cents = self.handling_cost_in_cents + + for coupon in other.coupons: + if coupon not in self.coupons: + self.coupons.append(coupon) + + # this busts memoization. self.cart = tmp_cart @property diff --git a/make_post_sell/routes.py b/make_post_sell/routes.py index 26488fc..af32eab 100644 --- a/make_post_sell/routes.py +++ b/make_post_sell/routes.py @@ -50,6 +50,7 @@ def includeme(config): config.add_route("user_cart_public", "/u/cart/{cart_id}/public") config.add_route("user_cart_unpublic", "/u/cart/{cart_id}/unpublic") + # cart routes. config.add_route("cart", "/cart") config.add_route("cart_checkout", "/cart/checkout") @@ -59,7 +60,7 @@ def includeme(config): config.add_route("cart_remove_product", "/cart/{cart_id}/remove") config.add_route("cart_quantity_product", "/cart/{cart_id}/quantity") - config.add_route("cart_handling_option", "/u/cart/{cart_id}/handling-option") + config.add_route("cart_handling_option", "/cart/{cart_id}/handling-option") config.add_route("view_invoice", "/invoices/{invoice_id}") diff --git a/make_post_sell/templates/cart.j2 b/make_post_sell/templates/cart.j2 index a422cd1..3227271 100644 --- a/make_post_sell/templates/cart.j2 +++ b/make_post_sell/templates/cart.j2 @@ -196,7 +196,7 @@

Total: ${{ '%0.2f' % cart.total }}

{% endif %} - {% if not cart.is_empty %} + {% if not cart.is_empty and request.user == cart.user %} Checkout @@ -216,9 +216,9 @@ Save Cart
- {% elif request.user and request.active_cart != cart %} + {% elif request.active_cart != cart %} - {% if request.user == cart.user %} + {% if request.user and request.user == cart.user %} Make Cart Active
{% else %} diff --git a/make_post_sell/templates/join-or-log-in.j2 b/make_post_sell/templates/join-or-log-in.j2 index 92aed0f..1c49749 100644 --- a/make_post_sell/templates/join-or-log-in.j2 +++ b/make_post_sell/templates/join-or-log-in.j2 @@ -27,6 +27,11 @@ required autofocus /> + +

diff --git a/make_post_sell/templates/verification-challenge.j2 b/make_post_sell/templates/verification-challenge.j2 index 39f9700..e8894a5 100644 --- a/make_post_sell/templates/verification-challenge.j2 +++ b/make_post_sell/templates/verification-challenge.j2 @@ -26,6 +26,11 @@ required autofocus /> + +

diff --git a/make_post_sell/views/__init__.py b/make_post_sell/views/__init__.py index 712e78d..94c555e 100644 --- a/make_post_sell/views/__init__.py +++ b/make_post_sell/views/__init__.py @@ -19,8 +19,11 @@ def user_required( if request.user and request.user.authenticated: return fn(request) request.session.flash((flash_msg, flash_level)) + next_url = request.url if redirect_to_route_name: - return HTTPFound(request.route_url(redirect_to_route_name)) + return HTTPFound( + request.route_url(redirect_to_route_name, _query={"next": next_url}) + ) return HTTPFound(get_referer_or_home(request)) return inner diff --git a/make_post_sell/views/authentication.py b/make_post_sell/views/authentication.py index 3a3812f..54f09d0 100644 --- a/make_post_sell/views/authentication.py +++ b/make_post_sell/views/authentication.py @@ -82,11 +82,14 @@ def join_or_log_in(request): request.session.flash(msg) - email_encoded = urlencode({"email": email}) + email_encoded = urlencode( + {"email": email, "next": request.params.get("next", "")} + ) return HTTPFound("/verification-challenge?{}".format(email_encoded)) return { "title": "join or log in", + "next": request.params.get("next", request.route_url("home")), } @@ -127,9 +130,14 @@ def verification_challenge(request): # save user and user's active cart. request.dbsession.add(user) request.dbsession.add(request.active_cart) - request.dbsession.flush() - return HTTPFound("/") + + if request.active_cart.count > 0: + next_url = "/cart" + else: + next_url = request.params.get("next", request.route_url("home")) + + return HTTPFound(next_url) else: msg = ("Invalid Verification Code", "error") @@ -139,4 +147,5 @@ def verification_challenge(request): "title": "Please Enter Verification Code", "email": email, "raw_otp": raw_otp, + "next": request.params.get("next", request.route_url("home")), } diff --git a/make_post_sell/views/cart.py b/make_post_sell/views/cart.py index 921ee38..d5d7dee 100644 --- a/make_post_sell/views/cart.py +++ b/make_post_sell/views/cart.py @@ -101,7 +101,6 @@ def cart_unpublic(request): @view_config(route_name="user_cart_activate") -@user_required() def cart_activate(request): cart = get_cart_from_matchdict(request) @@ -119,7 +118,7 @@ def cart_activate(request): msg = ("This cart is already your active cart.", "success") else: - if request.user.owns_cart(cart): + if request.user and request.user.owns_cart(cart): msg = ("You activated that cart.", "success") request.shop.make_cart_active_for_user(request.user, cart) else: @@ -128,6 +127,7 @@ def cart_activate(request): new_cart.merge_in_cart(cart) request.dbsession.add(new_cart) request.session.flash(msg) + request.session["active_cart_id"] = new_cart.uuid_str return HTTPFound("/cart/{}".format(new_cart.id)) request.session.flash(msg)