|
|
|
@@ -7,6 +7,8 @@ import { IMall } from '../models/mall'; |
|
|
|
import * as moment from 'moment'; |
|
|
|
import { Router } from '@angular/router'; |
|
|
|
import { IOutlet } from '../models/outlet'; |
|
|
|
import { OrderService } from '../services/order.service'; |
|
|
|
import { ToastController } from '@ionic/angular'; |
|
|
|
|
|
|
|
@Component({ |
|
|
|
selector: 'app-cart', |
|
|
|
@@ -31,7 +33,9 @@ export class CartPage implements OnInit { |
|
|
|
private location: Location, |
|
|
|
private cartService: CartItemService, |
|
|
|
private mallService: MallService, |
|
|
|
private router: Router |
|
|
|
private router: Router, |
|
|
|
private orderService: OrderService, |
|
|
|
public toastController: ToastController |
|
|
|
) { } |
|
|
|
|
|
|
|
ngOnInit() {} |
|
|
|
@@ -222,4 +226,29 @@ export class CartPage implements OnInit { |
|
|
|
this.cartService.updateCartItems(this.cart_items); |
|
|
|
} |
|
|
|
|
|
|
|
placeOrder() { |
|
|
|
this.orderService.createOrder(this.cart_items).then(() => { |
|
|
|
this.presentToast('Order has been created! :-)', 'dark'); |
|
|
|
this.cartService.clearCartItems(); |
|
|
|
this.router.navigate(['/profile']); |
|
|
|
}, () => { |
|
|
|
this.presentToast('Failed to create the order, We\'re sorry for the inconvenience', 'danger'); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
async presentToast(text: string, color: string) { |
|
|
|
const toast = await this.toastController.create({ |
|
|
|
message: text, |
|
|
|
position: 'bottom', |
|
|
|
duration: 4000, |
|
|
|
color: color, |
|
|
|
buttons: [ |
|
|
|
{ |
|
|
|
text: 'Done', |
|
|
|
} |
|
|
|
] |
|
|
|
}); |
|
|
|
toast.present(); |
|
|
|
} |
|
|
|
|
|
|
|
} |