Repository: saleor/saleor

Issue:
Can't create product
The product can not be added, no errors in console.
![nagranie ekranu 2017-12-20 o 13 16 04](https://user-images.githubusercontent.com/1561204/34206895-97d3feca-e588-11e7-852a-1bf54d890228.gif)


Discussion:
Hi @maltitco,
Thanks for reporting! This one was freshly merged, must overlook something.

Resolving patch:
diff --git a/saleor/dashboard/product/urls.py b/saleor/dashboard/product/urls.py
--- a/saleor/dashboard/product/urls.py
+++ b/saleor/dashboard/product/urls.py
@@ -18,8 +18,8 @@
         views.product_create, name='product-add'),
     url(r'^bulk-update/$',
         views.product_bulk_update, name='product-bulk-update'),
-    url(r'^product-select-classes/$',
-        views.product_select_classes, name='product-select-classes'),
+    url(r'^add/select-class/$',
+        views.product_select_classes, name='product-add-select-class'),
 
     url(r'^classes/$',
         views.product_class_list, name='product-class-list'),
diff --git a/saleor/dashboard/product/views.py b/saleor/dashboard/product/views.py
--- a/saleor/dashboard/product/views.py
+++ b/saleor/dashboard/product/views.py
@@ -3,7 +3,7 @@
 from django.contrib.auth.decorators import permission_required
 from django.db.models import Q
 from django.http import JsonResponse
-from django.shortcuts import get_object_or_404, redirect
+from django.shortcuts import get_object_or_404, redirect, reverse
 from django.template.response import TemplateResponse
 from django.utils.translation import npgettext_lazy, pgettext_lazy
 from django.views.decorators.http import require_POST
@@ -126,19 +126,20 @@ def product_list(request):
 @staff_member_required
 @permission_required('product.edit_product')
 def product_select_classes(request):
-    """
-    View for add product modal embedded in the product list view.
-    """
+    """View for add product modal embedded in the product list view."""
     form = forms.ProductClassSelectorForm(request.POST or None)
     status = 200
     if form.is_valid():
-        return redirect(
+        redirect_url = reverse(
             'dashboard:product-add',
-            class_pk=form.cleaned_data.get('product_cls').pk)
+            kwargs={'class_pk': form.cleaned_data.get('product_cls').pk})
+        return (
+            JsonResponse({'redirectUrl': redirect_url}, status=302)
+            if request.is_ajax() else redirect(redirect_url))
     elif form.errors:
         status = 400
     ctx = {'form': form}
-    template = 'product/modal/add_product.html'
+    template = 'dashboard/product/modal/select_class.html'
     return TemplateResponse(request, template, ctx, status=status)
 
 


Test patch:
diff --git a/tests/dashboard/test_product.py b/tests/dashboard/test_product.py
--- a/tests/dashboard/test_product.py
+++ b/tests/dashboard/test_product.py
@@ -615,13 +615,26 @@ def test_product_list_pagination_with_filters(admin_client, product_list):
     assert list(response.context['products'])[0] == product_list[1]
 
 
-def test_product_select_classes(admin_client, product_list):
-    url = reverse('dashboard:product-select-classes')
+def test_product_select_classes(admin_client, product_class):
+    url = reverse('dashboard:product-add-select-class')
     response = admin_client.get(url)
     assert response.status_code == HTTP_STATUS_OK
 
-    data = {'product_cls': product_list[0].product_class.pk}
+    data = {'product_cls': product_class.pk}
     response = admin_client.post(url, data)
     assert response.get('location') == reverse(
-        'dashboard:product-add', args=[product_list[0].product_class.pk])
+        'dashboard:product-add', kwargs={'class_pk': product_class.pk})
     assert response.status_code == HTTP_REDIRECTION
+
+
+def test_product_select_classes_by_ajax(admin_client, product_class):
+    url = reverse('dashboard:product-add-select-class')
+    data = {'product_cls': product_class.pk}
+
+    response = admin_client.post(
+        url, data, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
+
+    resp_decoded = json.loads(response.content.decode('utf-8'))
+    assert response.status_code == 302
+    assert resp_decoded.get('redirectUrl') == reverse(
+        'dashboard:product-add', kwargs={'class_pk': product_class.pk})