Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Improve cart data structure
Artur Smęt34d84c97a6b0
diff --git a/saleor/cart/views.py b/saleor/cart/views.pyindex 886ecf57e2..a72c65309b 100644--- a/saleor/cart/views.py+++ b/saleor/cart/views.py@@ -74,8 +74,10 @@ def update(request, cart, variant_id):response = {'variantId': variant_id,'subtotal': 0,'total': 0,- 'cart': cart.quantity,- 'cart_length': len(cart)}+ 'cart': {+ 'numItems': cart.quantity,+ 'numLines': len(cart)+ }}updated_line = cart.get_line(form.cart_line.variant)if updated_line:response['subtotal'] = currencyfmt(diff --git a/saleor/static/js/storefront.js b/saleor/static/js/storefront.jsindex b251bd29a7..8fffb8afbb 100644--- a/saleor/static/js/storefront.js+++ b/saleor/static/js/storefront.js@@ -180,7 +180,7 @@ $countrySelect.on('change', (e) => {})// Save tab links to URL-+$('.nav-tabs a').click((e) => {e.preventDefault()$(this).tab('show')@@ -232,7 +232,7 @@ $cartLine.each(function() {data: {quantity: newQuantity},success: (response) => {if (newQuantity == 0) {- if (response.cart_length == 0) {+ if (response.cart.numLines == 0) {$.cookie('alert', 'true', { path: '/cart' })location.reload()} else {@@ -243,7 +243,7 @@ $cartLine.each(function() {$subtotal.html(response.subtotal)}$total.html(response.total)- $cartBadge.html(response.cart)+ $cartBadge.html(response.cart.numItems)$qunatityError.html('')$cartDropdown.load(summaryLink)},@@ -258,10 +258,10 @@ $cartLine.each(function() {method: 'POST',data: {quantity: 0},success: (response) => {- if (response.cart_length >= 1) {+ if (response.cart.numLines >= 1) {$(this).fadeOut()$total.html(response.total)- $cartBadge.html(response.cart)+ $cartBadge.html(response.cart.numItems)$cartDropdown.load(summaryLink)$removeProductSucces.removeClass('hidden-xs-up')} else {