|
|
|
@@ -38,30 +38,30 @@ export class CartPage implements OnInit { |
|
|
|
tempPickupTime: any; |
|
|
|
showInstantMenu: boolean = false; |
|
|
|
temp_outlet_details: any; |
|
|
|
selectedTempMallId: string; |
|
|
|
selectedTempMallId: string; |
|
|
|
show_promocodes: boolean = false; |
|
|
|
selected_promocode: string = ''; |
|
|
|
userInfo: any; |
|
|
|
mallPromoCodes: Array<any> = []; |
|
|
|
invoiceData: any; |
|
|
|
selected_promo: any = ''; |
|
|
|
|
|
|
|
constructor( |
|
|
|
private location: Location, |
|
|
|
private orderService: OrderService, |
|
|
|
private toastService: ToastService, |
|
|
|
private router: Router, |
|
|
|
private orderService: OrderService, |
|
|
|
private toastService: ToastService, |
|
|
|
private router: Router, |
|
|
|
public modalController: ModalController, |
|
|
|
private mallService: MallService |
|
|
|
) { } |
|
|
|
|
|
|
|
ngOnInit() { |
|
|
|
this.hideMenuButton(); |
|
|
|
ngOnInit() { |
|
|
|
this.hideMenuButton(); |
|
|
|
this.userInfo = JSON.parse(localStorage.userInfo)['User Info']; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
ngOnDestroy() { |
|
|
|
this.showMenuButton(); |
|
|
|
} |
|
|
|
ngOnDestroy() { |
|
|
|
this.showMenuButton(); |
|
|
|
} |
|
|
|
|
|
|
|
ionViewDidEnter() { |
|
|
|
this.fetchCartItems(); |
|
|
|
@@ -70,7 +70,7 @@ export class CartPage implements OnInit { |
|
|
|
}, (error) => { |
|
|
|
console.log(error); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
fetchCartItems() { |
|
|
|
this.cart_outlets = []; |
|
|
|
@@ -86,7 +86,7 @@ export class CartPage implements OnInit { |
|
|
|
for (let i = 0; i < this.userCart.orderedlist.length; i += 1) { |
|
|
|
let tempOutlet = this.cart_outlets.find((outlet) => { |
|
|
|
return outlet.outlet_id === this.userCart.orderedlist[i].outlet_id && |
|
|
|
outlet.mall_id === this.userCart.orderedlist[i].mall_id |
|
|
|
outlet.mall_id === this.userCart.orderedlist[i].mall_id |
|
|
|
}); |
|
|
|
|
|
|
|
if (!tempOutlet) { |
|
|
|
@@ -100,6 +100,7 @@ export class CartPage implements OnInit { |
|
|
|
this.cart_outlets.forEach((cart) => { |
|
|
|
this.orderService.getPromoCodes(cart.mall_id).then((data) => { |
|
|
|
this.mallPromoCodes.push(data); |
|
|
|
|
|
|
|
}, (err) => console.log(err)); |
|
|
|
}); |
|
|
|
} |
|
|
|
@@ -136,7 +137,7 @@ export class CartPage implements OnInit { |
|
|
|
} |
|
|
|
|
|
|
|
getItemDetails(item) { |
|
|
|
let mall, outlet, outletitem; |
|
|
|
let mall, outlet, outletitem |
|
|
|
mall = this.allMalls.find((mall) => { |
|
|
|
return mall.mall.mall_id === item.mall_id; |
|
|
|
}); |
|
|
|
@@ -163,61 +164,61 @@ export class CartPage implements OnInit { |
|
|
|
} |
|
|
|
|
|
|
|
back() { |
|
|
|
this.showMenuButton(); |
|
|
|
this.storeData(); |
|
|
|
this.showMenuButton(); |
|
|
|
this.storeData(); |
|
|
|
this.location.back(); |
|
|
|
} |
|
|
|
|
|
|
|
openInstantMenu(outlet) { |
|
|
|
this.selectedTempMallId = outlet.mall_id; |
|
|
|
this.selectedTempMallId = outlet.mall_id; |
|
|
|
this.showInstantMenu = true; |
|
|
|
this.temp_outlet_details = this.getOutletDetails(outlet); |
|
|
|
} |
|
|
|
|
|
|
|
isPresentInCart(outletId: number, itemId: number, tempMallId: number) { |
|
|
|
let item: any; |
|
|
|
|
|
|
|
item = this.userCart.orderedlist.find((order) => { |
|
|
|
return order.menuitem_id === itemId && order.outlet_id === outletId && order.mall_id === tempMallId; |
|
|
|
}); |
|
|
|
|
|
|
|
return item? item.quantity: 0; |
|
|
|
} |
|
|
|
|
|
|
|
incrementCartCount(outletId: number, itemId: number, tempMallId: number) { |
|
|
|
let outletitem = this.getItemDetailsByIds(outletId, itemId, tempMallId); |
|
|
|
|
|
|
|
if (outletitem) { |
|
|
|
let i = this.userCart.orderedlist.findIndex((order) => { |
|
|
|
return order.menuitem_id === itemId && order.outlet_id === outletId && order.mall_id === tempMallId; |
|
|
|
}); |
|
|
|
|
|
|
|
this.userCart.orderedlist[i].quantity += 1; |
|
|
|
this.userCart.orderedlist[i].total_price = (outletitem.item_price - outletitem.item_discount) * this.userCart.orderedlist[i].quantity; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
decrementCartCount(outletId: number, itemId: number, tempMallId: number) { |
|
|
|
let outletitem = this.getItemDetailsByIds(outletId, itemId, tempMallId); |
|
|
|
|
|
|
|
if (outletitem) { |
|
|
|
let i = this.userCart.orderedlist.findIndex((order) => { |
|
|
|
return order.menuitem_id === itemId && order.outlet_id === outletId && order.mall_id === tempMallId; |
|
|
|
}); |
|
|
|
|
|
|
|
if (this.userCart.orderedlist[i].quantity > 1) { |
|
|
|
this.userCart.orderedlist[i].quantity -= 1; |
|
|
|
this.userCart.orderedlist[i].total_price = (outletitem.item_price - outletitem.item_discount) * this.userCart.orderedlist[i].quantity; |
|
|
|
} else if (this.userCart.orderedlist[i].quantity === 1) { |
|
|
|
this.userCart.orderedlist.splice(i, 1); |
|
|
|
this.storeData(); |
|
|
|
this.fetchCartItems(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
getItemDetailsByIds(outletId: number, itemId: number, tempMallId: number) { |
|
|
|
let mall, outlet, outletitem; |
|
|
|
isPresentInCart(outletId: number, itemId: number, tempMallId: number) { |
|
|
|
let item: any; |
|
|
|
|
|
|
|
item = this.userCart.orderedlist.find((order) => { |
|
|
|
return order.menuitem_id === itemId && order.outlet_id === outletId && order.mall_id === tempMallId; |
|
|
|
}); |
|
|
|
|
|
|
|
return item ? item.quantity : 0; |
|
|
|
} |
|
|
|
|
|
|
|
incrementCartCount(outletId: number, itemId: number, tempMallId: number) { |
|
|
|
let outletitem = this.getItemDetailsByIds(outletId, itemId, tempMallId); |
|
|
|
|
|
|
|
if (outletitem) { |
|
|
|
let i = this.userCart.orderedlist.findIndex((order) => { |
|
|
|
return order.menuitem_id === itemId && order.outlet_id === outletId && order.mall_id === tempMallId; |
|
|
|
}); |
|
|
|
|
|
|
|
this.userCart.orderedlist[i].quantity += 1; |
|
|
|
this.userCart.orderedlist[i].total_price = (outletitem.item_price - outletitem.item_discount) * this.userCart.orderedlist[i].quantity; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
decrementCartCount(outletId: number, itemId: number, tempMallId: number) { |
|
|
|
let outletitem = this.getItemDetailsByIds(outletId, itemId, tempMallId); |
|
|
|
|
|
|
|
if (outletitem) { |
|
|
|
let i = this.userCart.orderedlist.findIndex((order) => { |
|
|
|
return order.menuitem_id === itemId && order.outlet_id === outletId && order.mall_id === tempMallId; |
|
|
|
}); |
|
|
|
|
|
|
|
if (this.userCart.orderedlist[i].quantity > 1) { |
|
|
|
this.userCart.orderedlist[i].quantity -= 1; |
|
|
|
this.userCart.orderedlist[i].total_price = (outletitem.item_price - outletitem.item_discount) * this.userCart.orderedlist[i].quantity; |
|
|
|
} else if (this.userCart.orderedlist[i].quantity === 1) { |
|
|
|
this.userCart.orderedlist.splice(i, 1); |
|
|
|
this.storeData(); |
|
|
|
this.fetchCartItems(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
getItemDetailsByIds(outletId: number, itemId: number, tempMallId: number) { |
|
|
|
let mall, outlet, outletitem; |
|
|
|
mall = this.allMalls.find((mall) => { |
|
|
|
return mall.mall.mall_id === tempMallId; |
|
|
|
}); |
|
|
|
@@ -233,47 +234,59 @@ export class CartPage implements OnInit { |
|
|
|
return menu.menuitem_id === itemId; |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
addToCart(outletId: number, itemId: number, tempMallId: number) { |
|
|
|
let outletitem = this.getItemDetailsByIds(outletId, itemId, tempMallId); |
|
|
|
if (outletitem) { |
|
|
|
this.userCart.orderedlist.push({ |
|
|
|
mall_id: tempMallId, |
|
|
|
outlet_id: outletId, |
|
|
|
menuitem_id: itemId, |
|
|
|
quantity: 1, |
|
|
|
pickup_time: moment().add(moment.duration(outletitem.wait_duration).asMinutes(), 'minutes').format(), |
|
|
|
take_away: true, |
|
|
|
order_status: false, |
|
|
|
total_price: outletitem.item_price - outletitem.item_discount, |
|
|
|
soft_delete: false |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
getTotalCartAmount() { |
|
|
|
let total: number = 0; |
|
|
|
|
|
|
|
this.userCart.orderedlist.forEach((order) => { |
|
|
|
total = order.total_price + total; |
|
|
|
}); |
|
|
|
|
|
|
|
return total; |
|
|
|
} |
|
|
|
|
|
|
|
placeOrder() { |
|
|
|
this.orderService.createOrder(this.userInfo.id, { |
|
|
|
soft_delete: false, |
|
|
|
orderedlist: this.userCart.orderedlist |
|
|
|
}).then(() => { |
|
|
|
localStorage.removeItem('userCart'); |
|
|
|
this.toastService.presentToast("Order has been created", "success"); |
|
|
|
this.router.navigate(['/profile']); |
|
|
|
}, () => { |
|
|
|
this.toastService.presentToast("Failed to create order!", "danger"); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
addToCart(outletId: number, itemId: number, tempMallId: number) { |
|
|
|
let outletitem = this.getItemDetailsByIds(outletId, itemId, tempMallId); |
|
|
|
if (outletitem) { |
|
|
|
this.userCart.orderedlist.push({ |
|
|
|
mall_id: tempMallId, |
|
|
|
outlet_id: outletId, |
|
|
|
menuitem_id: itemId, |
|
|
|
quantity: 1, |
|
|
|
pickup_time: moment().add(moment.duration(outletitem.wait_duration).asMinutes(), 'minutes').format(), |
|
|
|
take_away: true, |
|
|
|
order_status: false, |
|
|
|
total_price: outletitem.item_price - outletitem.item_discount, |
|
|
|
soft_delete: false |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
getTotalCartAmount() { |
|
|
|
let total: number = 0, discountValue: number = 0 |
|
|
|
|
|
|
|
this.userCart.orderedlist.forEach((order) => { |
|
|
|
total = order.total_price + total; |
|
|
|
discountValue = (total * this.selected_promo.offer_precentage/100) |
|
|
|
}); |
|
|
|
|
|
|
|
if(!discountValue){ |
|
|
|
return total |
|
|
|
}else{ |
|
|
|
if(discountValue>=this.selected_promo.offersMaxcount){ |
|
|
|
total = total-this.selected_promo.offersMaxcount |
|
|
|
}else{ |
|
|
|
total = total-discountValue |
|
|
|
} |
|
|
|
return total |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
placeOrder() { |
|
|
|
this.orderService.createOrder(this.userInfo.id, { |
|
|
|
soft_delete: false, |
|
|
|
orderedlist: this.userCart.orderedlist |
|
|
|
}).then(() => { |
|
|
|
localStorage.removeItem('userCart'); |
|
|
|
this.toastService.presentToast("Order has been created", "success"); |
|
|
|
|
|
|
|
this.router.navigate(['/profile']); |
|
|
|
}, () => { |
|
|
|
this.toastService.presentToast("Failed to create order!", "danger"); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
requestInvoice() { |
|
|
|
let invoice_data = { |
|
|
|
@@ -283,12 +296,13 @@ export class CartPage implements OnInit { |
|
|
|
"total_amt": (this.getTotalCartAmount() + (this.getTotalCartAmount() * (18 / 100)) + 20), |
|
|
|
"description": "This payment is towards testing Invoice feature", |
|
|
|
"receipt": "#asdsdsdf", |
|
|
|
"email_notify": 1 |
|
|
|
"email_notify": 1, |
|
|
|
}; |
|
|
|
|
|
|
|
this.orderService.generateInvoice(invoice_data).then((data: any) => { |
|
|
|
this.invoiceData = data; |
|
|
|
this.presentModal(data.shorturl); |
|
|
|
|
|
|
|
}, (err) => { |
|
|
|
this.toastService.presentToast("Oops, something went wrong", "danger"); |
|
|
|
}); |
|
|
|
@@ -297,15 +311,15 @@ export class CartPage implements OnInit { |
|
|
|
|
|
|
|
async presentModal(url: string) { |
|
|
|
const modal = await this.modalController.create({ |
|
|
|
component: InAppBrowserPage, |
|
|
|
componentProps: { |
|
|
|
url: url |
|
|
|
} |
|
|
|
component: InAppBrowserPage, |
|
|
|
componentProps: { |
|
|
|
url: url |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
modal.onDidDismiss().then(() => { |
|
|
|
this.showMenuButton(); |
|
|
|
|
|
|
|
this.showMenuButton(); |
|
|
|
|
|
|
|
this.orderService.getPaymentDetailsByOrderID(this.invoiceData.orderId).then((paymentDetails: any) => { |
|
|
|
if (paymentDetails.Status === "paid") { |
|
|
|
this.placeOrder(); |
|
|
|
|