Skip to content

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

User cart's email field instead of user_email

Anna Siwik952e2c4f88dc
diff --git a/saleor/checkout/forms.py b/saleor/checkout/forms.py
index e03a498953..5813d12179 100644
--- a/saleor/checkout/forms.py
+++ b/saleor/checkout/forms.py
@@ -178,25 +178,25 @@ class CountryForm(forms.Form):
class AnonymousUserShippingForm(forms.ModelForm):
"""Additional shipping information form for users who are not logged in."""
- user_email = forms.EmailField(
+ email = forms.EmailField(
widget=forms.EmailInput(attrs={'autocomplete': 'shipping email'}),
label=pgettext_lazy('Address form field label', 'Email'))
class Meta:
model = Cart
- fields = ['user_email']
+ fields = ['email']
class AnonymousUserBillingForm(forms.ModelForm):
"""Additional billing information form for users who are not logged in."""
- user_email = forms.EmailField(
+ email = forms.EmailField(
widget=forms.EmailInput(attrs={'autocomplete': 'billing email'}),
label=pgettext_lazy('Address form field label', 'Email'))
class Meta:
model = Cart
- fields = ['user_email']
+ fields = ['email']
class AddressChoiceForm(forms.Form):
diff --git a/saleor/checkout/migrations/0007_merge_cart_with_checkout.py b/saleor/checkout/migrations/0007_merge_cart_with_checkout.py
index a74c0350a0..f0a44d28f6 100644
--- a/saleor/checkout/migrations/0007_merge_cart_with_checkout.py
+++ b/saleor/checkout/migrations/0007_merge_cart_with_checkout.py
@@ -1,4 +1,4 @@
-# Generated by Django 2.0.3 on 2018-05-24 09:14
+# Generated by Django 2.0.3 on 2018-05-29 05:55
from django.db import migrations, models
import django.db.models.deletion
@@ -9,23 +9,18 @@ class Migration(migrations.Migration):
dependencies = [
('shipping', '0008_auto_20180108_0814'),
- ('product', '0063_required_attr_value_order'),
- ('account', '0018_auto_20180426_0641'),
+ ('account', '0019_auto_20180528_1205'),
('checkout', '0006_auto_20180221_0825'),
]
- replaces = [
- ('cart', '0007_merge_cart_with_checkout.'),
- ]
-
operations = [
migrations.RemoveField(
model_name='cart',
- name='status',
+ name='checkout_data',
),
migrations.RemoveField(
model_name='cart',
- name='checkout_data',
+ name='status',
),
migrations.RemoveField(
model_name='cart',
@@ -61,16 +56,16 @@ class Migration(migrations.Migration):
name='shipping_method',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='carts', to='shipping.ShippingMethodCountry'),
),
- migrations.AddField(
- model_name='cart',
- name='user_email',
- field=models.EmailField(blank=True, default='', max_length=254),
- ),
migrations.AddField(
model_name='cart',
name='voucher_code',
field=models.CharField(blank=True, max_length=12, null=True),
),
+ migrations.AlterField(
+ model_name='cart',
+ name='email',
+ field=models.EmailField(blank=True, default='', max_length=254),
+ ),
migrations.AlterModelTable(
name='cart',
table=None,
diff --git a/saleor/checkout/models.py b/saleor/checkout/models.py
index 8c0fcb1173..ba58b0a9a8 100644
--- a/saleor/checkout/models.py
+++ b/saleor/checkout/models.py
@@ -39,15 +39,12 @@ class Cart(models.Model):
user = models.ForeignKey(
settings.AUTH_USER_MODEL, blank=True, null=True, related_name='carts',
on_delete=models.CASCADE)
- email = models.EmailField(blank=True, null=True)
+ email = models.EmailField(blank=True, default='')
token = models.UUIDField(primary_key=True, default=uuid4, editable=False)
total = MoneyField(
currency=settings.DEFAULT_CURRENCY, max_digits=12,
decimal_places=settings.DEFAULT_DECIMAL_PLACES, default=0)
quantity = models.PositiveIntegerField(default=0)
-
- # data used for handling checkout process
- user_email = models.EmailField(blank=True, default='')
billing_address = models.ForeignKey(
Address, related_name='+', editable=False, null=True,
on_delete=models.SET_NULL)
diff --git a/saleor/checkout/utils.py b/saleor/checkout/utils.py
index 689d4755f4..9658b1b6f5 100644
--- a/saleor/checkout/utils.py
+++ b/saleor/checkout/utils.py
@@ -793,7 +793,7 @@ def create_order(cart, tracking_code, discounts, taxes):
order_data['user'] = cart.user
order_data['user_email'] = cart.user.email
else:
- order_data['user_email'] = cart.user_email
+ order_data['user_email'] = cart.email
if voucher:
order_data['voucher'] = voucher
diff --git a/saleor/checkout/views/shipping.py b/saleor/checkout/views/shipping.py
index eeb2c44482..989404cb31 100644
--- a/saleor/checkout/views/shipping.py
+++ b/saleor/checkout/views/shipping.py
@@ -29,8 +29,8 @@ def user_shipping_address_view(request, cart):
In addition to entering a new address the user has an option of selecting
one of the existing entries from their address book.
"""
- cart.user_email = request.user.email
- cart.save(update_fields=['user_email'])
+ cart.email = request.user.email
+ cart.save(update_fields=['email'])
user_addresses = cart.user.addresses.all()
addresses_form, address_form, updated = update_shipping_address_in_cart(
diff --git a/saleor/checkout/views/validators.py b/saleor/checkout/views/validators.py
index 40cd227624..5b134225bc 100644
--- a/saleor/checkout/views/validators.py
+++ b/saleor/checkout/views/validators.py
@@ -29,7 +29,7 @@ def validate_shipping_address(view):
"""
@wraps(view)
def func(request, cart):
- if cart.user_email is None or cart.shipping_address is None:
+ if not cart.email or not cart.shipping_address:
return redirect('checkout:shipping-address')
try:
cart.shipping_address.full_clean()
diff --git a/tests/test_checkout.py b/tests/test_checkout.py
index ce6e0be590..424141ceef 100644
--- a/tests/test_checkout.py
+++ b/tests/test_checkout.py
@@ -59,7 +59,7 @@ def test_view_checkout_index_authorized_user(
def test_view_checkout_shipping_address(client, request_cart_with_item):
url = reverse('checkout:shipping-address')
data = {
- 'user_email': '[email protected]',
+ 'email': '[email protected]',
'first_name': 'John',
'last_name': 'Doe',
'street_address_1': 'Aleje Jerozolimskie 2',
@@ -79,7 +79,7 @@ def test_view_checkout_shipping_address(client, request_cart_with_item):
redirect_url = reverse('checkout:shipping-method')
assert response.request['PATH_INFO'] == redirect_url
- assert request_cart_with_item.user_email == '[email protected]'
+ assert request_cart_with_item.email == '[email protected]'
def test_view_checkout_shipping_address_authorized_user(
@@ -93,7 +93,7 @@ def test_view_checkout_shipping_address_authorized_user(
redirect_url = reverse('checkout:shipping-method')
assert response.request['PATH_INFO'] == redirect_url
- assert request_cart_with_item.user_email == customer_user.email
+ assert request_cart_with_item.email == customer_user.email
def test_view_checkout_shipping_address_without_shipping(
@@ -106,13 +106,13 @@ def test_view_checkout_shipping_address_without_shipping(
assert response.status_code == 302
assert get_redirect_location(response) == reverse('checkout:summary')
- assert not request_cart.user_email
+ assert not request_cart.email
def test_view_checkout_shipping_method(
client, shipping_method, address, request_cart_with_item):
request_cart_with_item.shipping_address = address
- request_cart_with_item.user_email = '[email protected]'
+ request_cart_with_item.email = '[email protected]'
request_cart_with_item.save()
url = reverse('checkout:shipping-method')
data = {'shipping_method': shipping_method.price_per_country.first().pk}
@@ -131,7 +131,7 @@ def test_view_checkout_shipping_method_authorized_user(
authorized_client, customer_user, shipping_method, address,
request_cart_with_item):
request_cart_with_item.user = customer_user
- request_cart_with_item.user_email = customer_user.email
+ request_cart_with_item.email = customer_user.email
request_cart_with_item.shipping_address = address
request_cart_with_item.save()
url = reverse('checkout:shipping-method')
@@ -175,7 +175,7 @@ def test_view_checkout_summary(
mock_send_confirmation, client, shipping_method, address,
request_cart_with_item):
request_cart_with_item.shipping_address = address
- request_cart_with_item.user_email = '[email protected]'
+ request_cart_with_item.email = '[email protected]'
request_cart_with_item.shipping_method = (
shipping_method.price_per_country.first())
request_cart_with_item.save()
@@ -201,7 +201,7 @@ def test_view_checkout_summary_authorized_user(
shipping_method, address, request_cart_with_item):
request_cart_with_item.shipping_address = address
request_cart_with_item.user = customer_user
- request_cart_with_item.user_email = customer_user.email
+ request_cart_with_item.email = customer_user.email
request_cart_with_item.shipping_method = (
shipping_method.price_per_country.first())
request_cart_with_item.save()
@@ -235,7 +235,7 @@ def test_view_checkout_summary_save_language(
request_cart_with_item.shipping_address = address
request_cart_with_item.user = customer_user
- request_cart_with_item.user_email = customer_user.email
+ request_cart_with_item.email = customer_user.email
request_cart_with_item.shipping_method = (
shipping_method.price_per_country.first())
request_cart_with_item.save()
@@ -284,7 +284,7 @@ def test_view_checkout_summary_with_invalid_voucher(
voucher.save()
request_cart_with_item.shipping_address = address
- request_cart_with_item.user_email = '[email protected]'
+ request_cart_with_item.email = '[email protected]'
request_cart_with_item.shipping_method = (
shipping_method.price_per_country.first())
request_cart_with_item.save()
@@ -317,7 +317,7 @@ def test_view_checkout_summary_with_invalid_voucher(
def test_view_checkout_summary_with_invalid_voucher_code(
client, request_cart_with_item, shipping_method, address):
request_cart_with_item.shipping_address = address
- request_cart_with_item.user_email = '[email protected]'
+ request_cart_with_item.email = '[email protected]'
request_cart_with_item.shipping_method = (
shipping_method.price_per_country.first())
request_cart_with_item.save()
@@ -335,7 +335,7 @@ def test_view_checkout_summary_with_invalid_voucher_code(
def test_view_checkout_summary_remove_voucher(
client, request_cart_with_item, shipping_method, voucher, address):
request_cart_with_item.shipping_address = address
- request_cart_with_item.user_email = '[email protected]'
+ request_cart_with_item.email = '[email protected]'
request_cart_with_item.shipping_method = (
shipping_method.price_per_country.first())
request_cart_with_item.save()
diff --git a/tests/test_order.py b/tests/test_order.py
index 61c2eb7231..85b41f3ca0 100644
--- a/tests/test_order.py
+++ b/tests/test_order.py
@@ -389,7 +389,7 @@ def test_order_payment_flow(
request_cart_with_item, client, address, shipping_method):
request_cart_with_item.shipping_address = address
request_cart_with_item.billing_address = address.get_copy()
- request_cart_with_item.user_email = '[email protected]'
+ request_cart_with_item.email = '[email protected]'
request_cart_with_item.shipping_method = (
shipping_method.price_per_country.first())
request_cart_with_item.save()