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 {
<Text>Total</Text>
</View>
<View style={{ margin: 10 }}>
<Text>0</Text>
<Text>{this.props.order_total + this.props.grabamount + this.state.diskon }</Text>
</View>
</View>
<View style={{ flexDirection: 'row', margin: 10, justifyContent: 'space-between', borderTopWidth: 1 }}>
......@@ -178,7 +178,7 @@ const mapStateToProps = (state) => {
grabdropoff:state.grabdropoff,
grabdestination:state.grabdestination,
balanceUsed: state.balanceUsed,
pointused: state.pointsused,
pointused: state.pointused,
addressId: state.addressId
}
}
......
......@@ -79,20 +79,8 @@ class ShoppingCart extends React.Component {
if (row.id == item.id) {
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 {
quantity = is_xist.quantity
}
const listMenu = [...this.state.listMenu]
listMenu[index].qty = quantity
this.setState({
listMenu
})
}
checkedSelection(val) {
......@@ -170,72 +153,113 @@ class ShoppingCart extends React.Component {
componentDidMount() {
this.getMenuList()
this.getBalance()
this.getRate()
}
getMenuList() {
let params = {
// getMenuList() {
// let params = {
outlet_id: "dec1abbb-95d0-46ae-a6cd-2bf306590f15"
}
Axios.post('https://excelsocrm.ravintoladev.com/crm/v2/menu/get_list', params).then(res => {
// outlet_id: "dec1abbb-95d0-46ae-a6cd-2bf306590f15"
// }
// Axios.post('https://excelsocrm.ravintoladev.com/crm/v2/menu/get_list', params).then(res => {
let data = res.data.data
this.setState({
listCategory: data.category,
listMenu: data.menu
})
// let data = res.data.data
// this.setState({
// listCategory: data.category,
// listMenu: data.menu
// })
let last_category = ''
let list_menu = []
// let last_category = ''
// let list_menu = []
for (let i = 0; i < data.menu.length; i++) {
// for (let i = 0; i < data.menu.length; i++) {
const row = data.menu[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
}
// // 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
})
// 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
// })
})
// })
}
// }
getRate() {
if (this.props.outlet_id === '') {
let params = {
session_id: this.props.session_id,
outlet_id: '0cb81ffe0c8242bea42d39c9b92ccaac',
address_id: '6263e6cb70634d5da523345a2cdbc071',
address_id: this.props.addressId,
order_item: this.props.order_item
}
console.log("INI PARAMETER : " + JSON.stringify(params));
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))
this.setState({
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,
})
let setGrabProps = {
grabtype: this.state.grabtype,
grabamount: this.state.grabamount,
grabpickup: this.state.grabpickup,
grabdropoff: this.state.grabdropoff,
grabdestination: this.state.grabdestination,
}
this.props.setGrab(setGrabProps);
let setOrdersProps = {
balanceUsed: this.state.balanceused,
pointused: this.state.pointsused,
}
this.props.setOrder(setOrdersProps);
}).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))
......@@ -270,6 +294,9 @@ class ShoppingCart extends React.Component {
})
}
}
getBalance() {
let params = {
session_id: this.props.session_id
......@@ -519,7 +546,7 @@ class ShoppingCart extends React.Component {
<Text style={{ fontSize: 35, color: '#ccb46c' }}>Total</Text>
</View>
<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 style={{ flexDirection: 'row', marginTop: 10, justifyContent: 'space-between' }}>
......@@ -708,7 +735,7 @@ const mapDispatchToProps = (dispacth) => {
type: ActionType.SET_ORDERS,
data: {
balanceUsed: setOrdersProps.balanceUsed,
pointused: setOrdersProps.pointsused,
pointused: setOrdersProps.pointused,
}
}),
}
......@@ -723,7 +750,12 @@ const mapStateToProps = (state) => {
order_item: state.order_item,
quantity: state.quantity,
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