From e4f80f7660191f1727789d089b791c1f48588cee Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Wed, 5 Dec 2018 16:45:05 +0100 Subject: [PATCH] Widget: Allow to pre-fill fields in the invoice address --- doc/user/events/widget.rst | 7 +++++++ src/pretix/presale/checkoutflow.py | 15 +++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/doc/user/events/widget.rst b/doc/user/events/widget.rst index e3e415f969..fcbdd77702 100644 --- a/doc/user/events/widget.rst +++ b/doc/user/events/widget.rst @@ -183,6 +183,8 @@ with that information:: @@ -200,6 +202,11 @@ This works for the pretix Button as well. Currently, the following attributes ar ``data-attendee-name-latin-transcription``. If you don't know or don't care, you can also just pass a string as ``data-attendee-name``, which will pre-fill the last part of the name, whatever that is. +* ``data-invoice-address-FIELD`` will pre-fill the corresponding field of the invoice address. Possible values for + ``FIELD`` are ``company``, ``street``, ``zipcode``, ``city`` and ``country``, as well as fields specified by the + naming scheme such as ``name-title`` or ``name-given-name`` (see above). ``country`` expects a two-character + country code. + Any configured pretix plugins might understand more data fields. For example, if the appropriate plugins on pretix Hosted or pretix Enterprise are active, you can pass the following fields: diff --git a/src/pretix/presale/checkoutflow.py b/src/pretix/presale/checkoutflow.py index 967a5aa779..0b3954a9eb 100644 --- a/src/pretix/presale/checkoutflow.py +++ b/src/pretix/presale/checkoutflow.py @@ -329,15 +329,30 @@ class QuestionsStep(QuestionsViewMixin, CartMixin, TemplateFlowStep): @cached_property def invoice_form(self): + initial = { + 'name_parts': { + k[21:].replace('-', '_'): v + for k, v in self.cart_session.get('widget_data', {}).items() + if k.startswith('invoice-address-name-') + }, + 'company': self.cart_session.get('widget_data', {}).get('invoice-address-company', ''), + 'is_business': bool(self.cart_session.get('widget_data', {}).get('invoice-address-company', '')), + 'street': self.cart_session.get('widget_data', {}).get('invoice-address-street', ''), + 'zipcode': self.cart_session.get('widget_data', {}).get('invoice-address-zipcode', ''), + 'city': self.cart_session.get('widget_data', {}).get('invoice-address-city', ''), + 'country': self.cart_session.get('widget_data', {}).get('invoice-address-country', ''), + } if not self.request.event.settings.invoice_address_asked and self.request.event.settings.invoice_name_required: return InvoiceNameForm(data=self.request.POST if self.request.method == "POST" else None, event=self.request.event, request=self.request, instance=self.invoice_address, + initial=initial, validate_vat_id=False) return InvoiceAddressForm(data=self.request.POST if self.request.method == "POST" else None, event=self.request.event, request=self.request, + initial=initial, instance=self.invoice_address, validate_vat_id=self.eu_reverse_charge_relevant)