Skip to content

Commit

Permalink
Merge branch 'sdhsp-issue/166-shipping-as-billing-address'
Browse files Browse the repository at this point in the history
  • Loading branch information
witekdev committed Dec 11, 2024
2 parents ff919fd + 3607933 commit 19e193f
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 81 deletions.
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

0 comments on commit 19e193f

Please sign in to comment.