Commit c5203ecc authored by Wahyu Adjie Prasetyo's avatar Wahyu Adjie Prasetyo

shoping cart

parent e19c59a5
...@@ -103,7 +103,7 @@ class MenuConfirmation extends React.Component { ...@@ -103,7 +103,7 @@ class MenuConfirmation extends React.Component {
<Text>Total</Text> <Text>Total</Text>
</View> </View>
<View style={{ margin: 10 }}> <View style={{ margin: 10 }}>
<Text>0</Text> <Text>{this.props.order_total + this.props.grabamount + this.state.diskon }</Text>
</View> </View>
</View> </View>
<View style={{ flexDirection: 'row', margin: 10, justifyContent: 'space-between', borderTopWidth: 1 }}> <View style={{ flexDirection: 'row', margin: 10, justifyContent: 'space-between', borderTopWidth: 1 }}>
...@@ -178,7 +178,7 @@ const mapStateToProps = (state) => { ...@@ -178,7 +178,7 @@ const mapStateToProps = (state) => {
grabdropoff:state.grabdropoff, grabdropoff:state.grabdropoff,
grabdestination:state.grabdestination, grabdestination:state.grabdestination,
balanceUsed: state.balanceUsed, balanceUsed: state.balanceUsed,
pointused: state.pointsused, pointused: state.pointused,
addressId: state.addressId addressId: state.addressId
} }
} }
......
...@@ -79,20 +79,8 @@ class ShoppingCart extends React.Component { ...@@ -79,20 +79,8 @@ class ShoppingCart extends React.Component {
if (row.id == item.id) { if (row.id == item.id) {
quantity = row.quantity quantity = row.quantity
} }
const listMenu = [...this.state.listMenu]
listMenu[index].qty = quantity
this.setState({
listMenu
})
} }
} else if (is_xist.quantity == 0) {
const order_item = {
id: item.id,
name: item.name,
price: item.price,
}
this.props.removeFromChart(order_item)
} }
} }
} }
...@@ -118,11 +106,6 @@ class ShoppingCart extends React.Component { ...@@ -118,11 +106,6 @@ class ShoppingCart extends React.Component {
quantity = is_xist.quantity quantity = is_xist.quantity
} }
const listMenu = [...this.state.listMenu]
listMenu[index].qty = quantity
this.setState({
listMenu
})
} }
checkedSelection(val) { checkedSelection(val) {
...@@ -170,73 +153,114 @@ class ShoppingCart extends React.Component { ...@@ -170,73 +153,114 @@ class ShoppingCart extends React.Component {
componentDidMount() { componentDidMount() {
this.getMenuList()
this.getBalance() this.getBalance()
this.getRate() this.getRate()
} }
getMenuList() { // getMenuList() {
let params = { // let params = {
outlet_id: "dec1abbb-95d0-46ae-a6cd-2bf306590f15" // outlet_id: "dec1abbb-95d0-46ae-a6cd-2bf306590f15"
} // }
Axios.post('https://excelsocrm.ravintoladev.com/crm/v2/menu/get_list', params).then(res => { // Axios.post('https://excelsocrm.ravintoladev.com/crm/v2/menu/get_list', params).then(res => {
let data = res.data.data // let data = res.data.data
this.setState({ // this.setState({
listCategory: data.category, // listCategory: data.category,
listMenu: data.menu // listMenu: data.menu
}) // })
// let last_category = ''
// let list_menu = []
// for (let i = 0; i < data.menu.length; i++) {
// const row = data.menu[i];
// // cari sudah ada belum di redux
// let is_xist = this.props.order_item.find(item => row.id == item.id)
// if (is_xist) {
// row['qty'] = is_xist.quantity
// } else {
// row['qty'] = 0
// }
// if (last_category != row.category.name) {
// let category = {
// "id": row.category.id,
// "name": row.category.name,
// "code": "CATEGORY"
// }
// list_menu.push(category)
// list_menu.push(row)
// last_category = row.category.name
// } else {
// list_menu.push(row)
// }
// }
// this.setState({
// listMenu: list_menu
// })
// })
// }
let last_category = '' getRate() {
let list_menu = []
for (let i = 0; i < data.menu.length; i++) { if (this.props.outlet_id === '') {
let params = {
const row = data.menu[i]; session_id: this.props.session_id,
outlet_id: '0cb81ffe0c8242bea42d39c9b92ccaac',
address_id: this.props.addressId,
order_item: this.props.order_item
}
// cari sudah ada belum di redux Axios.post('https://excelsocrm.ravintoladev.com/crm/v2/delivery/rate', params).then(res => {
let is_xist = this.props.order_item.find(item => row.id == item.id) console.log("INI LHO CUY : " + JSON.stringify(res.data.data.destination.address))
if (is_xist) {
row['qty'] = is_xist.quantity
} else {
row['qty'] = 0
}
if (last_category != row.category.name) {
let category = {
"id": row.category.id,
"name": row.category.name,
"code": "CATEGORY"
}
list_menu.push(category)
list_menu.push(row)
last_category = row.category.name
} else {
list_menu.push(row)
}
}
this.setState({ this.setState({
listMenu: list_menu grabtype: res.data.data.quotes[0].service.type,
}) grabamount: res.data.data.quotes[0].amount,
grabpickup: res.data.data.quotes[0].estimatedTimeline.pickup,
}) grabdropoff: res.data.data.quotes[0].estimatedTimeline.dropoff,
grabdestination: res.data.data.destination.address,
} })
getRate() { let setGrabProps = {
grabtype: this.state.grabtype,
grabamount: this.state.grabamount,
grabpickup: this.state.grabpickup,
grabdropoff: this.state.grabdropoff,
grabdestination: this.state.grabdestination,
}
let params = { this.props.setGrab(setGrabProps);
session_id: this.props.session_id, let setOrdersProps = {
outlet_id: '0cb81ffe0c8242bea42d39c9b92ccaac', balanceUsed: this.state.balanceused,
address_id: '6263e6cb70634d5da523345a2cdbc071', pointused: this.state.pointsused,
order_item: this.props.order_item }
} this.props.setOrder(setOrdersProps);
console.log("INI PARAMETER : " + JSON.stringify(params));
Axios.post('https://excelsocrm.ravintoladev.com/crm/v2/delivery/rate', params).then(res => { }).catch(error => {
console.log('ini error ' + error)
})
}else{
let params = {
session_id: this.props.session_id,
outlet_id: this.props.outlet_id,
address_id: this.props.addressId,
order_item: this.props.order_item
}
Axios.post('https://excelsocrm.ravintoladev.com/crm/v2/delivery/rate', params).then(res => {
console.log("INI LHO CUY : " + JSON.stringify(res.data.data.destination.address)) console.log("INI LHO CUY : " + JSON.stringify(res.data.data.destination.address))
this.setState({ this.setState({
...@@ -268,6 +292,9 @@ class ShoppingCart extends React.Component { ...@@ -268,6 +292,9 @@ class ShoppingCart extends React.Component {
}).catch(error => { }).catch(error => {
console.log('ini error ' + error) console.log('ini error ' + error)
}) })
}
} }
getBalance() { getBalance() {
...@@ -519,7 +546,7 @@ class ShoppingCart extends React.Component { ...@@ -519,7 +546,7 @@ class ShoppingCart extends React.Component {
<Text style={{ fontSize: 35, color: '#ccb46c' }}>Total</Text> <Text style={{ fontSize: 35, color: '#ccb46c' }}>Total</Text>
</View> </View>
<View style={{ marginTop: 15, paddingRight: 30, paddingTop: 10, alignItems: 'flex-end' }}> <View style={{ marginTop: 15, paddingRight: 30, paddingTop: 10, alignItems: 'flex-end' }}>
<Text style={{ fontSize: 35, color: '#ccb46c' }}>{this.props.order_total}</Text> <Text style={{ fontSize: 35, color: '#ccb46c' }}>{this.props.order_total + this.props.grabamount + this.state.diskon }</Text>
</View> </View>
</View> </View>
<View style={{ flexDirection: 'row', marginTop: 10, justifyContent: 'space-between' }}> <View style={{ flexDirection: 'row', marginTop: 10, justifyContent: 'space-between' }}>
...@@ -708,7 +735,7 @@ const mapDispatchToProps = (dispacth) => { ...@@ -708,7 +735,7 @@ const mapDispatchToProps = (dispacth) => {
type: ActionType.SET_ORDERS, type: ActionType.SET_ORDERS,
data: { data: {
balanceUsed: setOrdersProps.balanceUsed, balanceUsed: setOrdersProps.balanceUsed,
pointused: setOrdersProps.pointsused, pointused: setOrdersProps.pointused,
} }
}), }),
} }
...@@ -723,7 +750,12 @@ const mapStateToProps = (state) => { ...@@ -723,7 +750,12 @@ const mapStateToProps = (state) => {
order_item: state.order_item, order_item: state.order_item,
quantity: state.quantity, quantity: state.quantity,
address: state.address, address: state.address,
addressId: state.addressId addressId: state.addressId,
grabtype: state.grabtype,
grabamount: state.grabamount,
grabpickup: state.grabpickup,
grabdropoff:state.grabdropoff,
grabdestination:state.grabdestination,
} }
} }
......
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