Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement 'billing_address_is_shipping_address' checkbox in checkout form #91

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 34 additions & 5 deletions jazkarta/shop/browser/checkout/stripe.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,21 @@ def handle_submit(self):

userid = get_current_userid()
contact_info = PersistentMapping()
for f in ('first_name', 'last_name', 'email', 'phone', 'address',
'city', 'state', 'zip', 'country'):
if f in self.request.form: # for digital products only email address is currently required in /checkout
contact_info[f] = self.request.form[f]
for field in ('first_name', 'last_name', 'email', 'phone', 'address', 'city', 'state', 'zip', 'country'):
if field in self.request.form: # for digital products only email address is currently required in /checkout
if self.request.form.get('billing_address_is_shipping_address') == 'on' and field not in ('email', 'phone'):
# Use shipping data inplace of form data if the 'billing_address_is_shipping_address'
# checkbox is checked.
if field == 'zip':
contact_info[field] = self.cart.ship_to['postal_code']
elif field == 'address':
contact_info[field] = self.cart.ship_to['street']
else:
contact_info[field] = self.cart.ship_to[field]
else:
contact_info[field] = self.request.form[field]
else:
contact_info[f] = None
contact_info[field] = None

if not amount and 'nocharge' in self.request.form:
method = 'Free download'
Expand Down Expand Up @@ -165,3 +174,23 @@ def store_order(self, method, charge_result, userid, contact_info):
self.old_cart = self.cart.clone()

self.send_receipt_email()

def prepopulate_billing_info(self):
form = self.request.form
for form_field in (
'first_name',
'last_name',
'address',
'city',
'state',
'zip',
'country'
):
address_field = form_field
if form_field == 'address':
address_field = 'street'
elif form_field == 'zip':
address_field = 'postal_code'

if form_field not in form and address_field in self.cart.ship_to:
form[form_field] = self.cart.ship_to[address_field]
3 changes: 2 additions & 1 deletion jazkarta/shop/browser/static/shop-compiled.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion jazkarta/shop/browser/static/shop-compiled.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading