Skip to content

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

Change Cart view and js product variant variable naming

Krzysztof Wolskia2ade6094d0c
diff --git a/saleor/cart/urls.py b/saleor/cart/urls.py
index d05389b664..e645608d97 100644
--- a/saleor/cart/urls.py
+++ b/saleor/cart/urls.py
@@ -6,5 +6,5 @@ from . import views
urlpatterns = [
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.py
index 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.discounts
status = None
form = 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.js
index 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 } = response
this.props.dispatch({
type: 'UPDATE_SUBTOTAL',
- productId,
+ variantId,
subtotal
})
this.props.dispatch({
@@ -222,10 +222,10 @@ const selectQuantities = (state) => ({}) // FIXME: move quantities to store
export 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.js
index 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,
subtotals
diff --git a/templates/cart/index.html b/templates/cart/index.html
index 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">