From fdece7a782614dddc0cf9b5aaaea4cccc9a0f3f5 Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Mon, 17 Feb 2025 23:12:55 +0100 Subject: [PATCH] Fix handling of session create --- .../storefrontapi/endpoints/checkout.py | 29 ++++++++++--------- src/pretix/storefrontapi/steps.py | 4 +-- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/pretix/storefrontapi/endpoints/checkout.py b/src/pretix/storefrontapi/endpoints/checkout.py index c9b31593fe..52e11baa40 100644 --- a/src/pretix/storefrontapi/endpoints/checkout.py +++ b/src/pretix/storefrontapi/endpoints/checkout.py @@ -216,21 +216,22 @@ class CheckoutSessionSerializer(serializers.ModelSerializer): for p in payments ] - steps = get_steps( - self.context["event"], - cartpos, - getattr(checkout, "invoice_address", None), - checkout.session_data, - total, - ) d["steps"] = {} - for step in steps: - applicable = step.is_applicable() - valid = not applicable or step.is_valid() - d["steps"][step.identifier] = { - "applicable": applicable, - "valid": valid, - } + if cartpos: + steps = get_steps( + self.context["event"], + cartpos, + getattr(checkout, "invoice_address", None), + checkout.session_data, + total, + ) + for step in steps: + applicable = step.is_applicable() + valid = not applicable or step.is_valid() + d["steps"][step.identifier] = { + "applicable": applicable, + "valid": valid, + } return d diff --git a/src/pretix/storefrontapi/steps.py b/src/pretix/storefrontapi/steps.py index 3fc62daf3a..1d6c1ae21a 100644 --- a/src/pretix/storefrontapi/steps.py +++ b/src/pretix/storefrontapi/steps.py @@ -75,12 +75,12 @@ class PaymentStep(CheckoutStep): r.event = self.event r.organizer = self.event.organizer self.cart_session.setdefault("fake_request", {}) - cart_id = self.cart_positions[0].cart_id + cart_id = self.cart_positions[0].cart_id if self.cart_positions else None r.session = UserDict( { f"current_cart_event_{self.event.pk}": cart_id, "carts": {cart_id: self.cart_session}, - } + } if cart_id else {} ) r.session.session_key = cart_id return r