Commit e309e7c4 authored by Afid's avatar Afid

coba yu

parent ce1583f3
...@@ -210,32 +210,39 @@ const rootReducer = (state = globalState, action) => { ...@@ -210,32 +210,39 @@ const rootReducer = (state = globalState, action) => {
let addedItem = action.data.item let addedItem = action.data.item
let is_exist = state.order_item.find(item => addedItem.id == item.id) let is_exist = state.order_item.find(item => addedItem.id == item.id)
let order_item = state.order_item; let order_item = []
if (is_exist) { if (is_exist) {
// update // update
addedItem.quantity += 1 addedItem.quantity += 1
console.log('Update : ' + JSON.stringify(addedItem)) console.log('Update : ' + JSON.stringify(addedItem))
let quantity = state.order_quantity + 1
let total = parseInt(state.order_total) + parseInt(addedItem.price) updated_data = []
for (let i = 0; i < state.order_item.length; i++) {
return{ const old_data = state.order_item[i];
...state, const data = old_data;
order_quantity: quantity, if (old_data.id == addedItem.id) {
order_total: total data = {...old_data, ...addedItem}
}
updated_data.push(data)
} }
order_item = updated_data
} else { } else {
// add // add
addedItem.quantity = 1 addedItem.quantity = 1
console.log('Baru : ' + JSON.stringify(addedItem)) console.log('Baru : ' + JSON.stringify(addedItem))
let quantity = state.order_quantity + 1 order_item = [...state.order_item, addedItem]
let total = parseInt(state.order_total) + parseInt(addedItem.price) }
return{ let quantity = state.order_quantity + 1
...state, let total = parseInt(state.order_total) + parseInt(addedItem.price)
order_item: [...state.order_item, addedItem],
order_quantity: quantity, return{
order_total: total ...state,
} order_item: order_item,
order_quantity: quantity,
order_total: total
} }
} }
......
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