Преглед изворни кода

[FEAT] Auto select existing user when an account already exists (#4325)

* feat :star: auto select existing user when an account already exists

* lint

* Added test and simplyfied code

---------

Co-authored-by: Lars van de Kerkhof <lars@permanentmarkers.nl>
master
Samar Hassan пре 8 месеци
родитељ
комит
c6583f6079
No account linked to committer's email address
2 измењених фајлова са 30 додато и 0 уклоњено
  1. 7
    0
      src/oscar/apps/checkout/forms.py
  2. 23
    0
      tests/functional/checkout/test_guest_checkout.py

+ 7
- 0
src/oscar/apps/checkout/forms.py Прегледај датотеку

@@ -84,6 +84,13 @@ class GatewayForm(AuthenticationForm):
84 84
                 if User._default_manager.filter(email__iexact=email).exists():
85 85
                     msg = _("A user with that email address already exists")
86 86
                     self._errors["username"] = self.error_class([msg])
87
+
88
+                    # change the value of the 'options' in the submitted data,
89
+                    # which will be used to render the form
90
+                    options_field = self.add_prefix("options")
91
+                    self.data = self.data.copy()
92
+                    self.data[options_field] = self.EXISTING
93
+
87 94
             return self.cleaned_data
88 95
         return super().clean()
89 96
 

+ 23
- 0
tests/functional/checkout/test_guest_checkout.py Прегледај датотеку

@@ -107,6 +107,29 @@ class TestIndexView(
107 107
         page = self.get(reverse("checkout:index"))
108 108
         self.assertEqual(email, page.form["username"].value)
109 109
 
110
+    def test_auto_select_existing_user(self):
111
+        email = "forgetfulguest@test.com"
112
+        self.create_user(email, email, self.password)
113
+
114
+        self.add_product_to_basket()
115
+
116
+        # select guest checkout
117
+        page = self.get(reverse("checkout:index"))
118
+        form = page.form
119
+        form["options"].select(GatewayForm.GUEST)
120
+        form["username"].value = email
121
+
122
+        response = form.submit()
123
+
124
+        # since this user allready exists
125
+        self.assertEqual(email, response.form["username"].value)
126
+        self.assertEqual(
127
+            GatewayForm.EXISTING,
128
+            response.form["options"].value,
129
+            "Since this user has an account, the GatewayForm should "
130
+            "be changed to existing, so the user can enter his password",
131
+        )
132
+
110 133
 
111 134
 @override_settings(OSCAR_ALLOW_ANON_CHECKOUT=True)
112 135
 class TestShippingAddressView(

Loading…
Откажи
Сачувај