Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix cart not updating its UI
Patryk Zawadzki8363254c9448
diff --git a/package.json b/package.jsonindex 60c4673708..90b2843bc5 100644--- a/package.json+++ b/package.json@@ -65,7 +65,7 @@"webpack": "^1.12.2"},"scripts": {- "build": "UV_THREADPOOL_SIZE=100 ./node_modules/.bin/webpack --progress",- "watch": "UV_THREADPOOL_SIZE=100 ./node_modules/.bin/webpack --progress --debug --devtool source-map --watch"+ "build": "UV_THREADPOOL_SIZE=32 ./node_modules/.bin/webpack --progress",+ "watch": "UV_THREADPOOL_SIZE=32 ./node_modules/.bin/webpack --progress --debug --devtool source-map --watch"}}diff --git a/saleor/cart/views.py b/saleor/cart/views.pyindex 3c7edbc002..32dee02937 100755--- a/saleor/cart/views.py+++ b/saleor/cart/views.py@@ -34,7 +34,7 @@ def index(request, product_id=None):form.save()if request.is_ajax():response = {- 'product_id': line.product.pk,+ 'productId': line.product.pk,'subtotal': currencyfmt(line.get_total().gross,line.get_total().currency),diff --git a/saleor/static/js_src/components/cart.jsx b/saleor/static/js_src/components/cart.jsxindex f780d3d925..d51b0aa0e9 100644--- a/saleor/static/js_src/components/cart.jsx+++ b/saleor/static/js_src/components/cart.jsx@@ -1,8 +1,11 @@+/* @flow */+import React, {Component, findDOMNode} from 'react';import {connect} from 'react-redux';+import $ from 'jquery';export class CartItemAmountOption extends Component {- render() {+ render(): Component {var value = this.props.value;var label = this.props.label ? this.props.label : value;return <option value={value}>{label}</option>;@@ -52,7 +55,7 @@ class CartItemAmountSelect extends Component {}checkKey(event) {- if (event.key == "Enter" && this.valueChanged()) {+ if (event.key === 'Enter' && this.valueChanged()) {this.sendQuantityWrapper();}}@@ -67,8 +70,8 @@ class CartItemAmountSelect extends Component {$.ajax({url: this.props.url,- method: "post",- data: {quantity: quantity},+ method: 'post',+ data: {[this.props.fieldName]: quantity},complete: () => {this.setState({sending: false});if (quantity < this.props.thresholdValue) {@@ -80,7 +83,7 @@ class CartItemAmountSelect extends Component {if (!response.total) {location.reload();}- $(findDOMNode(this)).parents("tr").fadeOut(function() {+ $(findDOMNode(this)).parents('tr').fadeOut(function() {$(this).remove();});}@@ -90,13 +93,13 @@ class CartItemAmountSelect extends Component {this.props.dispatch({type: 'UPDATE_SUBTOTAL', ...props});this.props.dispatch({type: 'UPDATE_TOTAL', total});}- this.setState({result: "success", lastSavedValue: quantity});+ this.setState({result: 'success', lastSavedValue: quantity});setTimeout(() => {this.setState({result: null});}, 1000);},error: (response) => {- this.setState({error: response.error.quantity, result: "error"});+ this.setState({error: response.error.quantity, result: 'error'});}});}@@ -116,7 +119,7 @@ class CartItemAmountSelect extends Component {break;}let classNamesInput = ['input-group', 'cart-item-quantity'];- if ((!this.state.renderSubmit || !this.valueChanged()) && !(this.state.result == "error")) {+ if ((!this.state.renderSubmit || !this.valueChanged()) && !(this.state.result === 'error')) {classNamesInput.push('no-submit');}@@ -169,30 +172,3 @@ function selectTotal(state) {}export var CartTotal = connect(selectTotal)(renderTotal);--export class FormShippingToggler extends Component {- constructor() {- super(...arguments);- this.state = {- value: true- };- }-- componentDidMount() {- $(".form-full").hide();- }-- formFullToggle(event) {- this.setState({value: event.target.checked});- $(".form-full").toggle();- }-- render() {- return <div className="checkbox">- <label>- <input checked={this.state.value} type="checkbox" onChange={this.formFullToggle.bind(this)} name="shipping_same_as_billing" />- {this.props.label}- </label>- </div>;- }-}diff --git a/saleor/static/js_src/storefront.jsx b/saleor/static/js_src/storefront.jsxindex 15bed40814..fb30d28565 100644--- a/saleor/static/js_src/storefront.jsx+++ b/saleor/static/js_src/storefront.jsx@@ -4,7 +4,7 @@ import React from 'react';import {render} from 'react-dom';import {Provider} from 'react-redux';import $ from 'jquery';-import {CartItemAmount, CartItemSubtotal, CartTotal, FormShippingToggler} from './components/cart';+import {CartItemAmount, CartItemSubtotal, CartTotal} from './components/cart';import CartStore from './stores/cart-store';require('jquery.cookie');require('bootstrap-sass');@@ -20,7 +20,7 @@ function csrfSafeMethod(method) {$.ajaxSetup({beforeSend: function(xhr, settings) {if (!csrfSafeMethod(settings.type) && !this.crossDomain) {- xhr.setRequestHeader("X-CSRFToken", csrftoken);+ xhr.setRequestHeader('X-CSRFToken', csrftoken);}}});@@ -38,13 +38,12 @@ $('.cart-item-amount').each(function(index) {options: options.slice(0, max),thresholdValue: options[options.length - 1],url: $(this).find('form').attr('action'),+ fieldName: name,value: value};-$(this).find('.cart-item-quantity').removeClass('js-hidden');$button.addClass('invisible');textInput.push(this.firstElementChild);-render(<Provider store={CartStore}><CartItemAmount {...props} /></Provider>, this);@@ -54,16 +53,16 @@ let $cartTotal = $('.cart-total');let cartTotalValue = $cartTotal.text();if ($cartTotal.length) {CartStore.dispatch({type: 'UPDATE_TOTAL', total: cartTotalValue});- let cartTotal = render(<Provider store={CartStore}>+ render(<Provider store={CartStore}><CartTotal /></Provider>, $cartTotal[0]);}-$(".cart-item-subtotal").each(function() {+$('.cart-item-subtotal').each(function() {let productId = $(this).data('product-id');let props = {productId,- subTotal: $(this).text()+ subtotal: $(this).text()};CartStore.dispatch({type: 'UPDATE_SUBTOTAL', ...props});render(<Provider store={CartStore}>