Commit 37c93296 authored by Shaphen Pangburn's avatar Shaphen Pangburn

[AFP-48 Shaphen Pangburn]: CSuccesfully add update cart with new item that is...

[AFP-48 Shaphen Pangburn]: CSuccesfully add update cart with new item that is associated with a particular user
parent f4b9173d
...@@ -31,7 +31,10 @@ export default class ProductItem extends Component { ...@@ -31,7 +31,10 @@ export default class ProductItem extends Component {
handleSubmit(e, product) { handleSubmit(e, product) {
e.preventDefault(); e.preventDefault();
const newCart = Object.assign([], this.props.cart); const newCart = Object.assign({}, {
userId: this.props.user.currentUser.email,
cartItems: JSON.parse(JSON.stringify(this.props.cart)) // JSON.parse/stringify will deep-dup the object
})
const newCartItem = { const newCartItem = {
productRef: { productRef: {
id: product.sku, id: product.sku,
...@@ -40,7 +43,7 @@ export default class ProductItem extends Component { ...@@ -40,7 +43,7 @@ export default class ProductItem extends Component {
}, },
quantity: parseInt(this.state.orderItemQuantity) quantity: parseInt(this.state.orderItemQuantity)
} }
newCart.push(newCartItem); newCart.cartItems.push(newCartItem);
this.props.addToCart(newCart, this.props.user.currentUser.email); this.props.addToCart(newCart, this.props.user.currentUser.email);
} }
......
...@@ -9,5 +9,6 @@ export const createCart = newCart => { ...@@ -9,5 +9,6 @@ export const createCart = newCart => {
} }
export const updateCart = (updatedCart, userEmail) => { export const updateCart = (updatedCart, userEmail) => {
// debugger
return axios.put(`http://localhost:8080/api/carts/${userEmail}`, updatedCart) return axios.put(`http://localhost:8080/api/carts/${userEmail}`, updatedCart)
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment