Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Save billing address in Cart during checkout

Anna Siwikf65bd0aab83c
diff --git a/saleor/cart/checkout/forms.py b/saleor/cart/checkout/forms.py
index 930c0378f8..eabc12494b 100644
--- a/saleor/cart/checkout/forms.py
+++ b/saleor/cart/checkout/forms.py
@@ -38,6 +38,22 @@ class AddressChoiceForm(forms.Form):
self.fields['address'].choices = self.CHOICES + address_choices
+class BillingAddressChoiceForm(AddressChoiceForm):
+ """Choose one of user's addresses, a shipping one or to create new."""
+
+ NEW_ADDRESS = 'new_address'
+ SHIPPING_ADDRESS = 'shipping_address'
+ CHOICES = [
+ (NEW_ADDRESS, pgettext_lazy(
+ 'Billing addresses form choice', 'Enter a new address')),
+ (SHIPPING_ADDRESS, pgettext_lazy(
+ 'Billing addresses form choice', 'Same as shipping'))]
+
+ address = CheckoutAddressField(
+ label=pgettext_lazy('Billing addresses form field label', 'Address'),
+ choices=CHOICES, initial=SHIPPING_ADDRESS)
+
+
# FIXME: why is this called a country choice field?
class ShippingCountryChoiceField(forms.ModelChoiceField):
"""Shipping method country choice field.
@@ -45,6 +61,7 @@ class ShippingCountryChoiceField(forms.ModelChoiceField):
Uses a radio group instead of a dropdown and includes estimated shipping
prices.
"""
+
taxes = None
widget = forms.RadioSelect()
@@ -90,3 +107,27 @@ class CartShippingMethodForm(forms.ModelForm):
self.initial['shipping_method'] = method_field.queryset.first()
method_field.empty_label = None
+
+
+class AnonymousUserBillingForm(forms.Form):
+ """Additional billing information form for users who are not logged in."""
+
+ email = forms.EmailField(
+ required=True, widget=forms.EmailInput(
+ attrs={'autocomplete': 'billing email'}),
+ label=pgettext_lazy('Billing form field label', 'Email'))
+
+
+class NoteForm(forms.Form):
+ """Form to add a note to an order."""
+
+ note = forms.CharField(
+ max_length=250, required=False, strip=True, label=False)
+ note.widget = forms.Textarea({'rows': 3})
+
+ def __init__(self, *args, **kwargs):
+ self.checkout = kwargs.pop('checkout', None)
+ super().__init__(*args, **kwargs)
+
+ def set_checkout_note(self):
+ self.checkout.note = self.cleaned_data.get('note', '')
diff --git a/saleor/cart/checkout/utils.py b/saleor/cart/checkout/utils.py
index 09051095da..1c120e0e97 100644
--- a/saleor/cart/checkout/utils.py
+++ b/saleor/cart/checkout/utils.py
@@ -1,3 +1,23 @@
+def save_billing_address_in_cart(cart, address):
+ """Save billing address in cart if changed.
+
+ Remove previously saved address if not connected to any user.
+ """
+ has_address_changed = (
+ not address and cart.billing_address or
+ address and not cart.billing_address or
+ address and cart.billing_address and address != cart.billing_address)
+ if has_address_changed:
+ remove_old_address = (
+ cart.billing_address and (not cart.user or (
+ cart.user and
+ cart.billing_address not in cart.user.addresses.all())))
+ if remove_old_address:
+ cart.billing_address.delete()
+ cart.billing_address = address
+ cart.save()
+
+
def save_shipping_address_in_cart(cart, address):
"""Save shipping address in cart if changed.
@@ -9,8 +29,9 @@ def save_shipping_address_in_cart(cart, address):
address and cart.shipping_address and address != cart.shipping_address)
if has_address_changed:
remove_old_address = (
- cart.user and cart.shipping_address and
- cart.shipping_address not in cart.user.addresses.all())
+ cart.shipping_address and (not cart.user or (
+ cart.user and
+ cart.shipping_address not in cart.user.addresses.all())))
if remove_old_address:
cart.shipping_address.delete()
cart.shipping_address = address
diff --git a/saleor/cart/checkout/views/__init__.py b/saleor/cart/checkout/views/__init__.py
index aa1dfeef3c..3fd497ae2e 100644
--- a/saleor/cart/checkout/views/__init__.py
+++ b/saleor/cart/checkout/views/__init__.py
@@ -4,11 +4,14 @@ from django.template.response import TemplateResponse
from ....checkout.core import load_checkout
from ....checkout.views import (
add_voucher_form, validate_cart, validate_is_shipping_required,
- validate_shipping_address, validate_voucher)
+ validate_shipping_address, validate_shipping_method, validate_voucher)
from ..forms import CartShippingMethodForm
from ..utils import get_checkout_data
from .shipping import (
anonymous_user_shipping_address_view, user_shipping_address_view)
+from .summary import (
+ anonymous_summary_without_shipping, summary_with_shipping_view,
+ summary_without_shipping)
@load_checkout
@@ -45,3 +48,18 @@ def shipping_method_view(request, cart, checkout):
'checkout': checkout,
'shipping_method_form': form})
return TemplateResponse(request, 'checkout/shipping_method.html', ctx)
+
+
+@load_checkout
+@validate_voucher
+@validate_cart
+@add_voucher_form
+def summary_view(request, cart, checkout):
+ """Display the correct order summary."""
+ if cart.is_shipping_required():
+ view = validate_shipping_address(summary_with_shipping_view)
+ view = validate_shipping_method(view)
+ return view(request, cart, checkout)
+ if request.user.is_authenticated:
+ return summary_without_shipping(request, cart, checkout)
+ return anonymous_summary_without_shipping(request, cart, checkout)
diff --git a/saleor/cart/checkout/views/shipping.py b/saleor/cart/checkout/views/shipping.py
index 515fd61b75..9d24c1733d 100644
--- a/saleor/cart/checkout/views/shipping.py
+++ b/saleor/cart/checkout/views/shipping.py
@@ -39,7 +39,7 @@ def user_shipping_address_view(request, cart, checkout):
one of the existing entries from their address book.
"""
data = request.POST or None
- additional_addresses = request.user.addresses.all()
+ user_addresses = request.user.addresses.all()
checkout.email = request.user.email
shipping_address = cart.shipping_address
@@ -48,20 +48,20 @@ def user_shipping_address_view(request, cart, checkout):
data, country_code=request.country.code,
initial={'country': request.country})
addresses_form = AddressChoiceForm(
- data, addresses=additional_addresses,
+ data, addresses=user_addresses,
initial={'address': shipping_address.id})
elif shipping_address:
address_form, preview = get_address_form(
data, country_code=shipping_address.country.code,
instance=shipping_address)
addresses_form = AddressChoiceForm(
- data, addresses=additional_addresses)
+ data, addresses=user_addresses)
else:
address_form, preview = get_address_form(
- data, initial={'country': request.country},
- country_code=request.country.code)
+ data, country_code=request.country.code,
+ initial={'country': request.country})
addresses_form = AddressChoiceForm(
- data, addresses=additional_addresses)
+ data, addresses=user_addresses)
if addresses_form.is_valid() and not preview:
use_existing_address = (
@@ -81,7 +81,7 @@ def user_shipping_address_view(request, cart, checkout):
ctx = get_checkout_data(cart, request.discounts, checkout.get_taxes())
ctx.update({
- 'additional_addresses': additional_addresses,
+ 'additional_addresses': user_addresses,
'address_form': address_form,
'checkout': checkout,
'user_form': addresses_form})
diff --git a/saleor/checkout/views/summary.py b/saleor/cart/checkout/views/summary.py
similarity index 69%
rename from saleor/checkout/views/summary.py
rename to saleor/cart/checkout/views/summary.py
index 57b648558a..17ec8a4b85 100644
--- a/saleor/checkout/views/summary.py
+++ b/saleor/cart/checkout/views/summary.py
@@ -3,14 +3,14 @@ from django.shortcuts import redirect
from django.template.response import TemplateResponse
from django.utils.translation import pgettext, pgettext_lazy
-from ...account.forms import get_address_form
-from ...account.models import Address
-from ...cart.checkout.utils import get_checkout_data
-from ...core.exceptions import InsufficientStock
-from ...order.emails import send_order_confirmation
+from ....account.forms import get_address_form
+from ....account.models import Address
+from ....core.exceptions import InsufficientStock
+from ....order.emails import send_order_confirmation
from ..forms import (
- AnonymousUserBillingForm, BillingAddressesForm,
- BillingWithoutShippingAddressForm, NoteForm)
+ AddressChoiceForm, AnonymousUserBillingForm, BillingAddressChoiceForm,
+ NoteForm)
+from ..utils import get_checkout_data, save_billing_address_in_cart
def create_order(checkout):
@@ -50,41 +50,41 @@ def handle_order_placement(request, checkout):
def get_billing_forms_with_shipping(
data, addresses, billing_address, shipping_address):
"""Get billing form based on a the current billing and shipping data."""
- if billing_address == shipping_address:
+ if not billing_address.id or billing_address == shipping_address:
address_form, preview = get_address_form(
data, country_code=shipping_address.country.code,
autocomplete_type='billing',
- initial={'country': shipping_address.country.code},
- instance=None)
- addresses_form = BillingAddressesForm(
- data, additional_addresses=addresses, initial={
- 'address': BillingAddressesForm.SHIPPING_ADDRESS})
- elif billing_address.id is None:
+ initial={'country': shipping_address.country.code})
+ addresses_form = BillingAddressChoiceForm(
+ data, addresses=addresses, initial={
+ 'address': BillingAddressChoiceForm.SHIPPING_ADDRESS})
+ elif billing_address in addresses:
address_form, preview = get_address_form(
data, country_code=billing_address.country.code,
autocomplete_type='billing',
- initial={'country': billing_address.country.code},
- instance=billing_address)
- addresses_form = BillingAddressesForm(
+ initial={'country': billing_address.country})
+ addresses_form = BillingAddressChoiceForm(
data, additional_addresses=addresses, initial={
- 'address': BillingAddressesForm.NEW_ADDRESS})
+ 'address': billing_address.id})
else:
address_form, preview = get_address_form(
data, country_code=billing_address.country.code,
autocomplete_type='billing',
- initial={'country': billing_address.country})
- addresses_form = BillingAddressesForm(
- data, additional_addresses=addresses, initial={
- 'address': billing_address.id})
+ initial={'country': billing_address.country.code},
+ instance=billing_address)
+ addresses_form = BillingAddressChoiceForm(
+ data, addresses=addresses, initial={
+ 'address': BillingAddressChoiceForm.NEW_ADDRESS})
+
if addresses_form.is_valid() and not preview:
address_id = addresses_form.cleaned_data['address']
- if address_id == BillingAddressesForm.SHIPPING_ADDRESS:
+ if address_id == BillingAddressChoiceForm.SHIPPING_ADDRESS:
return address_form, addresses_form, shipping_address
- elif address_id != BillingAddressesForm.NEW_ADDRESS:
+ elif address_id != BillingAddressChoiceForm.NEW_ADDRESS:
address = addresses.get(id=address_id)
return address_form, addresses_form, address
elif address_form.is_valid():
- return address_form, addresses_form, address_form.instance
+ return address_form, addresses_form, address_form.save()
return address_form, addresses_form, None
@@ -101,12 +101,14 @@ def summary_with_shipping_view(request, cart, checkout):
additional_addresses = request.user.addresses.all()
else:
additional_addresses = Address.objects.none()
+
address_form, addresses_form, address = get_billing_forms_with_shipping(
request.POST or None, additional_addresses,
- checkout.billing_address or Address(country=request.country),
+ cart.billing_address or Address(country=request.country),
cart.shipping_address)
+
if address is not None:
- checkout.billing_address = address
+ save_billing_address_in_cart(cart, address)
return handle_order_placement(request, checkout)
ctx = get_checkout_data(cart, request.discounts, checkout.get_taxes())
@@ -129,7 +131,7 @@ def anonymous_summary_without_shipping(request, cart, checkout):
note_form.set_checkout_note()
user_form = AnonymousUserBillingForm(
request.POST or None, initial={'email': checkout.email})
- billing_address = checkout.billing_address
+ billing_address = cart.billing_address
if billing_address:
address_form, preview = get_address_form(
request.POST or None, country_code=billing_address.country.code,
@@ -138,9 +140,11 @@ def anonymous_summary_without_shipping(request, cart, checkout):
address_form, preview = get_address_form(
request.POST or None, country_code=request.country.code,
autocomplete_type='billing', initial={'country': request.country})
+
if all([user_form.is_valid(), address_form.is_valid()]) and not preview:
checkout.email = user_form.cleaned_data['email']
- checkout.billing_address = address_form.instance
+ address = address_form.save()
+ save_billing_address_in_cart(cart, address)
return handle_order_placement(request, checkout)
ctx = get_checkout_data(cart, request.discounts, checkout.get_taxes())
@@ -162,38 +166,57 @@ def summary_without_shipping(request, cart, checkout):
if note_form.is_valid():
note_form.set_checkout_note()
- billing_address = checkout.billing_address
+ billing_address = cart.billing_address
user_addresses = request.user.addresses.all()
- if billing_address and billing_address.id:
+ if billing_address and billing_address in user_addresses:
address_form, preview = get_address_form(
request.POST or None, autocomplete_type='billing',
- initial={'country': request.country},
- country_code=billing_address.country.code)
- addresses_form = BillingWithoutShippingAddressForm(
- request.POST or None, additional_addresses=user_addresses,
+ country_code=billing_address.country.code,
+ initial={'country': billing_address.country.code})
+ addresses_form = AddressChoiceForm(
+ request.POST or None, addresses=user_addresses,
initial={'address': billing_address.id})
elif billing_address:
address_form, preview = get_address_form(
request.POST or None, autocomplete_type='billing',
+ initial={'country': billing_address.country.code},
instance=billing_address,
country_code=billing_address.country.code)
- addresses_form = BillingWithoutShippingAddressForm(
- request.POST or None, additional_addresses=user_addresses)
+ addresses_form = AddressChoiceForm(
+ request.POST or None, addresses=user_addresses,
+ initial={'address': AddressChoiceForm.NEW_ADDRESS})
else:
address_form, preview = get_address_form(
request.POST or None, autocomplete_type='billing',
initial={'country': request.country},
country_code=request.country.code)
- addresses_form = BillingWithoutShippingAddressForm(
- request.POST or None, additional_addresses=user_addresses)
+
+ if request.user.is_authenticated:
+ initial_address = (
+ request.user.default_billing_address.id
+ if request.user.default_billing_address
+ else AddressChoiceForm.NEW_ADDRESS)
+ else:
+ initial_address = AddressChoiceForm.NEW_ADDRESS
+
+ addresses_form = AddressChoiceForm(
+ request.POST or None, addresses=user_addresses,
+ initial={'address': initial_address})
if addresses_form.is_valid():
- address_id = addresses_form.cleaned_data['address']
- if address_id != BillingWithoutShippingAddressForm.NEW_ADDRESS:
- checkout.billing_address = user_addresses.get(id=address_id)
+ use_existing_address = (
+ addresses_form.cleaned_data['address'] !=
+ AddressChoiceForm.NEW_ADDRESS)
+
+ if use_existing_address:
+ address_id = addresses_form.cleaned_data['address']
+ address = Address.objects.get(id=address_id)
+ save_billing_address_in_cart(cart, address)
return handle_order_placement(request, checkout)
- elif address_form.is_valid() and not preview:
- checkout.billing_address = address_form.instance
+
+ elif address_form.is_valid():
+ address = address_form.save()
+ save_billing_address_in_cart(cart, address)
return handle_order_placement(request, checkout)
ctx = get_checkout_data(cart, request.discounts, checkout.get_taxes())
diff --git a/saleor/cart/migrations/0007_merge_checkout_into_cart.py b/saleor/cart/migrations/0007_merge_checkout_into_cart.py
index 88bb4cfa6d..c5ca5a5530 100644
--- a/saleor/cart/migrations/0007_merge_checkout_into_cart.py
+++ b/saleor/cart/migrations/0007_merge_checkout_into_cart.py
@@ -13,6 +13,11 @@ class Migration(migrations.Migration):
]
operations = [
+ migrations.AddField(
+ model_name='cart',
+ name='billing_address',
+ field=models.ForeignKey(editable=False, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='account.Address'),
+ ),
migrations.AddField(
model_name='cart',
name='shipping_address',
diff --git a/saleor/cart/models.py b/saleor/cart/models.py
index bd4c012464..e97014860e 100644
--- a/saleor/cart/models.py
+++ b/saleor/cart/models.py
@@ -80,6 +80,9 @@ class Cart(models.Model):
quantity = models.PositiveIntegerField(default=0)
# data used for handling checkout process
+ billing_address = models.ForeignKey(
+ Address, related_name='+', editable=False, null=True,
+ on_delete=models.SET_NULL)
shipping_address = models.ForeignKey(
Address, related_name='+', editable=False, null=True,
on_delete=models.SET_NULL)
diff --git a/saleor/checkout/core.py b/saleor/checkout/core.py
index e11d2a04b2..05aac026ae 100644
--- a/saleor/checkout/core.py
+++ b/saleor/checkout/core.py
@@ -3,7 +3,6 @@ from datetime import date
from functools import wraps
from django.db import transaction
-from django.forms.models import model_to_dict
from django.utils.encoding import smart_text
from django.utils.translation import get_language
from prices import Money
@@ -108,24 +107,6 @@ class Checkout:
self.storage['note'] = note
self.modified = True
- @property
- def billing_address(self):
- """Return the billing addres if any."""
- address = self._get_address_from_storage('billing_address')
- if address is not None:
- return address
- elif (self.user.is_authenticated and
- self.user.default_billing_address):
- return self.user.default_billing_address
- return self.cart.shipping_address
-
- @billing_address.setter
- def billing_address(self, address):
- address_data = model_to_dict(address)
- address_data['country'] = smart_text(address_data['country'])
- self.storage['billing_address'] = address_data
- self.modified = True
-
@property
def discount(self):
"""Return a discount if any."""
@@ -182,16 +163,6 @@ class Checkout:
del self.storage['voucher_code']
self.modified = True
- def _add_to_user_address_book(self, address, is_billing=False,
- is_shipping=False):
- if self.user.is_authenticated:
- store_user_address(
- self.user, address, shipping=is_shipping,
- billing=is_billing)
-
- def _save_order_billing_address(self):
- return self.billing_address.get_copy()
-
@transaction.atomic
def create_order(self):
"""Create an order from the checkout session.
@@ -215,26 +186,31 @@ class Checkout:
# Voucher expired in meantime, abort order placement
return None
- if self.cart.is_shipping_required():
- shipping_address = self.cart.shipping_address
- if self.cart.user:
- if shipping_address not in self.cart.user.addresses.all():
- store_user_address(
- self.user, shipping_address, shipping=True)
- shipping_address = shipping_address.get_copy()
- else:
- shipping_address = None
- billing_address = self._save_order_billing_address()
- self._add_to_user_address_book(
- self.billing_address, is_billing=True)
+ billing_address = self.cart.billing_address
if self.cart.is_shipping_required():
+ shipping_address = self.cart.shipping_address
shipping_method = self.cart.shipping_method
shipping_method_name = smart_text(shipping_method)
else:
+ shipping_address = None
shipping_method = None
shipping_method_name = None
+ if self.cart.user:
+ if (
+ shipping_address and
+ shipping_address not in self.cart.user.addresses.all()
+ ):
+ store_user_address(
+ self.user, shipping_address, shipping=True)
+ if billing_address not in self.cart.user.addresses.all():
+ store_user_address(
+ self.user, billing_address, billing=True)
+ if shipping_address:
+ shipping_address = shipping_address.get_copy()
+ billing_address = billing_address.get_copy()
+
order_data = {
'language_code': get_language(),
'billing_address': billing_address,
diff --git a/saleor/checkout/forms.py b/saleor/checkout/forms.py
index 61ad01b3e6..8b1fa72c0a 100644
--- a/saleor/checkout/forms.py
+++ b/saleor/checkout/forms.py
@@ -9,49 +9,6 @@ class CheckoutAddressField(forms.ChoiceField):
widget = forms.RadioSelect()
-class ShippingAddressesForm(forms.Form):
- """Shipping address form."""
-
- NEW_ADDRESS = 'new_address'
- CHOICES = [
- (NEW_ADDRESS, pgettext_lazy(
- 'Shipping addresses form choice', 'Enter a new address'))]
-
- address = CheckoutAddressField(
- label=pgettext_lazy('Shipping addresses form field label', 'Address'),
- choices=CHOICES, initial=NEW_ADDRESS)
-
- def __init__(self, *args, **kwargs):
- additional_addresses = kwargs.pop('additional_addresses', [])
- super().__init__(*args, **kwargs)
- address_field = self.fields['address']
- address_choices = [
- (address.id, str(address)) for address in additional_addresses]
- address_field.choices = self.CHOICES + address_choices
-
-
-class BillingAddressesForm(ShippingAddressesForm):
- """Billing address form."""
-
- NEW_ADDRESS = 'new_address'
- SHIPPING_ADDRESS = 'shipping_address'
- CHOICES = [
- (NEW_ADDRESS, pgettext_lazy(
- 'Billing addresses form choice', 'Enter a new address')),
- (SHIPPING_ADDRESS, pgettext_lazy(
- 'Billing addresses form choice', 'Same as shipping'))]
-
- address = CheckoutAddressField(choices=CHOICES, initial=SHIPPING_ADDRESS)
-
-
-class BillingWithoutShippingAddressForm(ShippingAddressesForm):
- """Billing address form when shipping is not required.
-
- Same as the default shipping address as in this came "billing same as
- shipping" option does not make sense.
- """
-
-
class AnonymousUserShippingForm(forms.Form):
"""Additional shipping information form for users who are not logged in."""
@@ -59,27 +16,3 @@ class AnonymousUserShippingForm(forms.Form):
required=True, widget=forms.EmailInput(
attrs={'autocomplete': 'shipping email'}),
label=pgettext_lazy('Shipping form field label', 'Email'))
-
-
-class AnonymousUserBillingForm(forms.Form):
- """Additional billing information form for users who are not logged in."""
-
- email = forms.EmailField(
- required=True, widget=forms.EmailInput(
- attrs={'autocomplete': 'billing email'}),
- label=pgettext_lazy('Billing form field label', 'Email'))
-
-
-class NoteForm(forms.Form):
- """Form to add a note to an order."""
-
- note = forms.CharField(
- max_length=250, required=False, strip=True, label=False)
- note.widget = forms.Textarea({'rows': 3})
-
- def __init__(self, *args, **kwargs):
- self.checkout = kwargs.pop('checkout', None)
- super().__init__(*args, **kwargs)
-
- def set_checkout_note(self):
- self.checkout.note = self.cleaned_data.get('note', '')
diff --git a/saleor/checkout/urls.py b/saleor/checkout/urls.py
index 0c41e8274c..b3480f058e 100644
--- a/saleor/checkout/urls.py
+++ b/saleor/checkout/urls.py
@@ -1,7 +1,8 @@
from django.conf.urls import url
from . import views
-from ..cart.checkout.views import shipping_address_view, shipping_method_view
+from ..cart.checkout.views import (
+ shipping_address_view, shipping_method_view, summary_view)
urlpatterns = [
url(r'^$', views.index_view, name='index'),
@@ -9,7 +10,7 @@ urlpatterns = [
name='shipping-address'),
url(r'^shipping-method/', shipping_method_view,
name='shipping-method'),
- url(r'^summary/', views.summary_view, name='summary'),
+ url(r'^summary/', summary_view, name='summary'),
url(r'^remove_voucher/', views.discount.remove_voucher_view,
name='remove-voucher'),
url(r'^login/', views.login, name='login')]
diff --git a/saleor/checkout/views/__init__.py b/saleor/checkout/views/__init__.py
index 654c50b1cd..ef7c6094b6 100644
--- a/saleor/checkout/views/__init__.py
+++ b/saleor/checkout/views/__init__.py
@@ -2,9 +2,6 @@ from django.shortcuts import redirect
from django.template.response import TemplateResponse
from .discount import add_voucher_form, validate_voucher
-from .summary import (
- summary_with_shipping_view, anonymous_summary_without_shipping,
- summary_without_shipping)
from .validators import (
validate_cart, validate_shipping_address,
validate_shipping_method, validate_is_shipping_required)
@@ -20,21 +17,6 @@ def index_view(request, cart, checkout):
return redirect('checkout:shipping-address')
-@load_checkout
-@validate_voucher
-@validate_cart
-@add_voucher_form
-def summary_view(request, cart, checkout):
- """Display the correct order summary."""
- if cart.is_shipping_required():
- view = validate_shipping_address(summary_with_shipping_view)
- view = validate_shipping_method(view)
- return view(request, cart, checkout)
- if request.user.is_authenticated:
- return summary_without_shipping(request, cart, checkout)
- return anonymous_summary_without_shipping(request, cart, checkout)
-
-
@load_checkout
@validate_cart
def login(request, cart, checkout):
diff --git a/saleor/checkout/views/validators.py b/saleor/checkout/views/validators.py
index 71c92a537b..139afc29e0 100644
--- a/saleor/checkout/views/validators.py
+++ b/saleor/checkout/views/validators.py
@@ -32,10 +32,10 @@ def validate_shipping_address(view):
"""
@wraps(view)
def func(request, cart, checkout):
- if checkout.email is None or checkout.cart.shipping_address is None:
+ if checkout.email is None or cart.shipping_address is None:
return redirect('checkout:shipping-address')
try:
- checkout.cart.shipping_address.full_clean()
+ cart.shipping_address.full_clean()
except ValidationError:
return redirect('checkout:shipping-address')
return view(request, cart, checkout)
@@ -51,7 +51,7 @@ def validate_shipping_method(view):
"""
@wraps(view)
def func(request, cart, checkout):
- if checkout.cart.shipping_method is None:
+ if cart.shipping_method is None:
return redirect('checkout:shipping-method')
return view(request, cart, checkout)
return func
diff --git a/tests/test_checkout.py b/tests/test_checkout.py
index dd4ce93142..601fe5b420 100644
--- a/tests/test_checkout.py
+++ b/tests/test_checkout.py
@@ -5,15 +5,13 @@ from django.contrib.auth.models import AnonymousUser
from django.urls import reverse
from prices import Money, TaxedMoney
-from saleor.account.models import Address
+from saleor.cart.checkout.forms import NoteForm
from saleor.checkout import views
from saleor.checkout.core import STORAGE_SESSION_KEY, Checkout
-from saleor.checkout.forms import NoteForm
from saleor.checkout.utils import get_voucher_discount_for_checkout
from saleor.core.exceptions import InsufficientStock
from saleor.discount import DiscountValueType, VoucherType
from saleor.discount.models import Voucher, NotApplicable
-from saleor.shipping.models import ShippingMethodCountry
def test_checkout_version(checkout):
@@ -43,20 +41,6 @@ def test_checkout_clear_storage(checkout):
assert checkout.modified is True
[email protected]('user, address', [
- (AnonymousUser(), None),
- (
- Mock(
- default_billing_address='billing_address',
- addresses=Mock(
- is_authenticated=Mock(return_value=True))),
- 'billing_address')])
-def test_checkout_billing_address(checkout, user, address, monkeypatch):
- monkeypatch.setattr(checkout.cart, 'shipping_address', None)
- checkout.user = user
- assert checkout.billing_address == address
-
-
@pytest.mark.parametrize('cart, status_code, url', [
(Mock(__len__=Mock(return_value=0)), 302, reverse('cart:index')),
(
diff --git a/tests/test_checkout_integration.py b/tests/test_checkout_integration.py
index 1f69e1b9dd..a55db1c67e 100644
--- a/tests/test_checkout_integration.py
+++ b/tests/test_checkout_integration.py
@@ -8,7 +8,7 @@ from saleor.account.models import User
from .utils import get_redirect_location
-@patch('saleor.checkout.views.summary.send_order_confirmation')
+@patch('saleor.cart.checkout.views.summary.send_order_confirmation')
def test_checkout_flow(
mock_send_confirmation, request_cart_with_item, client,
shipping_method):