diff --git a/make_post_sell/templates/product.j2 b/make_post_sell/templates/product.j2 index c59a9cf..4fa3d33 100644 --- a/make_post_sell/templates/product.j2 +++ b/make_post_sell/templates/product.j2 @@ -75,7 +75,11 @@ {% if inventory and inventory.quantity > 0 %} Add To Cart {% else %} - Sold Out + + {% if request.shop.shop_locations.all()|length > 1 %} +

This item is sold out at this location. +
You can switch shop locations to check availability.

+ {% endif %} {% endif %} {% else %} Add To Cart diff --git a/make_post_sell/templates/shop_locations.j2 b/make_post_sell/templates/shop_locations.j2 index 83d0d05..5028377 100644 --- a/make_post_sell/templates/shop_locations.j2 +++ b/make_post_sell/templates/shop_locations.j2 @@ -11,14 +11,14 @@ - {% if request.user.can_edit_shop(request.shop) %} + {% if request.user and request.user.can_edit_shop(request.shop) %} Add New Location {% endif %} diff --git a/make_post_sell/views/shop_location.py b/make_post_sell/views/shop_location.py index a2f3630..ba13ee5 100644 --- a/make_post_sell/views/shop_location.py +++ b/make_post_sell/views/shop_location.py @@ -171,21 +171,31 @@ def shop_locations(request): "locations": request.shop.shop_locations, } + @view_config(route_name="shop_location_switch") def shop_location_switch(request): shop_id = request.shop.id location_id = request.matchdict.get("location_id") + next_url = request.params.get("next", request.route_url("shop", shop_id=shop_id)) # Fetch the location to ensure it exists and belongs to the shop - location = request.dbsession.query(ShopLocation).filter_by(id=location_id, shop_id=shop_id).first() + location = ( + request.dbsession.query(ShopLocation) + .filter_by(id=location_id, shop_id=shop_id) + .first() + ) if not location: - request.session.flash(("Location not found or does not belong to this shop.", "error")) + request.session.flash( + ("Location not found or does not belong to this shop.", "error") + ) return HTTPFound(request.route_url("shop_locations", shop_id=shop_id)) # Update the session with the selected location request.session["shop_location_id"] = str(location.id) - request.session.flash((f"You are now viewing the {location.name} shop location", "success")) + request.session.flash( + (f"You are now viewing the {location.name} shop location", "success") + ) - # Redirect to the shop home page - return HTTPFound(request.route_url("shop", shop_id=shop_id)) + # Redirect to the next URL or the shop home page + return HTTPFound(next_url)