Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Change Cart view and js product variant variable naming
Krzysztof Wolskia2ade6094d0c
diff --git a/saleor/cart/urls.py b/saleor/cart/urls.pyindex d05389b664..e645608d97 100644--- a/saleor/cart/urls.py+++ b/saleor/cart/urls.py@@ -6,5 +6,5 @@ from . import viewsurlpatterns = [url(r'^$', views.index, name='index'),url(r'^add/(?P<product_id>\d+)/$', views.add_to_cart, name='add-to-cart'),- url(r'^update/(?P<product_id>\d+)/$', views.update, name='update-line')+ url(r'^update/(?P<variant_id>\d+)/$', views.update, name='update-line')]diff --git a/saleor/cart/views.py b/saleor/cart/views.pyindex 7854dbd4a6..7adff8a2d9 100644--- a/saleor/cart/views.py+++ b/saleor/cart/views.py@@ -60,17 +60,17 @@ def add_to_cart(request, cart, product_id):@get_or_empty_db_cart-def update(request, cart, product_id):+def update(request, cart, variant_id):if not request.is_ajax():return redirect('cart:index')- variant = get_object_or_404(ProductVariant, pk=product_id)+ variant = get_object_or_404(ProductVariant, pk=variant_id)discounts = request.discountsstatus = Noneform = ReplaceCartLineForm(request.POST, cart=cart, variant=variant,discounts=discounts)if form.is_valid():form.save()- response = {'productId': product_id,+ response = {'productId': variant_id,'subtotal': 0,'total': 0}updated_line = cart.get_line(form.cart_line.variant)diff --git a/saleor/static/js/components/cart.js b/saleor/static/js/components/cart.jsindex 082f4f859a..78075156b6 100644--- a/saleor/static/js/components/cart.js+++ b/saleor/static/js/components/cart.js@@ -101,11 +101,11 @@ class CartItemAmountSelect extends Component {$(this).remove()})}- if (response.hasOwnProperty('productId')) {- const { productId, subtotal, total } = response+ if (response.hasOwnProperty('variantId')) {+ const { variantId, subtotal, total } = responsethis.props.dispatch({type: 'UPDATE_SUBTOTAL',- productId,+ variantId,subtotal})this.props.dispatch({@@ -222,10 +222,10 @@ const selectQuantities = (state) => ({}) // FIXME: move quantities to storeexport const CartItemAmount = connect(selectQuantities)(CartItemAmountSelect);-const renderSubtotal = ({productId, subtotals}) => {+const renderSubtotal = ({variantId, subtotals}) => {let value;- if (subtotals.hasOwnProperty(productId)) {- value = subtotals[productId]+ if (subtotals.hasOwnProperty(variantId)) {+ value = subtotals[variantId]}return <span>{value}</span>}diff --git a/saleor/static/js/stores/cart-store.js b/saleor/static/js/stores/cart-store.jsindex 7017ec5e05..0083563434 100644--- a/saleor/static/js/stores/cart-store.js+++ b/saleor/static/js/stores/cart-store.js@@ -14,7 +14,7 @@ type CartUpdateTotal = {type CartUpdateSubtotal = {type: 'UPDATE_SUBTOTAL';- productId: number;+ variantId: number;subtotal: string};@@ -33,8 +33,8 @@ const cart = (state: CartState = defaultState, action: CartAction) => {total: action.total}case ('UPDATE_SUBTOTAL'):- const { productId, subtotal } = action;- const subtotals = { ...state.subtotals, [productId]: subtotal }+ const { variantId, subtotal } = action;+ const subtotals = { ...state.subtotals, [variantId]: subtotal }return {...state,subtotalsdiff --git a/templates/cart/index.html b/templates/cart/index.htmlindex 39d954f791..3fb96ec04c 100644--- a/templates/cart/index.html+++ b/templates/cart/index.html@@ -59,7 +59,7 @@</td><td><div class="cart-item-amount">- <form role="form" action="{% url "cart:update-line" product_id=line.variant.pk %}" method="post" class="form-cart">+ <form role="form" action="{% url "cart:update-line" variant_id=line.variant.pk %}" method="post" class="form-cart"><div class="input-group cart-item-quantity js-hidden{% if form.quantity.errors %} has-error{% endif %}">{{ line.form.quantity }}<span class="input-group-btn">