Browse Source

Added Order creation module

master
kj1352 6 years ago
parent
commit
7b358c61a9
10 changed files with 1052 additions and 996 deletions
  1. +954
    -952
      .firebase/hosting.d3d3.cache
  2. +2
    -0
      src/app/app.module.ts
  3. +2
    -2
      src/app/cart/cart.page.html
  4. +30
    -1
      src/app/cart/cart.page.ts
  5. +2
    -19
      src/app/orders/orders.component.ts
  6. +0
    -1
      src/app/outlet-details/outlet-details.page.ts
  7. +4
    -0
      src/app/services/cart-item.service.ts
  8. +12
    -0
      src/app/services/order.service.spec.ts
  9. +45
    -0
      src/app/services/order.service.ts
  10. +1
    -21
      src/app/services/user-data.service.ts

+ 954
- 952
.firebase/hosting.d3d3.cache
File diff suppressed because it is too large
View File


+ 2
- 0
src/app/app.module.ts View File

@@ -14,6 +14,7 @@ import { OfferService } from './services/offer.service';
import { OutletService } from './services/outlet.service';
import { CartItemService } from './services/cart-item.service';
import { UserDataService } from './services/user-data.service';
import { OrderService } from './services/order.service';

import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';
@@ -38,6 +39,7 @@ import { environment } from '../environments/environment';
OutletService,
CartItemService,
UserDataService,
OrderService,
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
],
bootstrap: [AppComponent]


+ 2
- 2
src/app/cart/cart.page.html View File

@@ -78,7 +78,8 @@
<ion-button fill="clear"> &#8377; {{ total_savings }} </ion-button>
</div>

<ion-button shape="round" expand="block" class="pay-button"> Pay Now </ion-button>
<ion-button shape="round" expand="block" class="pay-button" (click)="placeOrder()"
[disabled]="cart_items.length === 0"> Pay Now </ion-button>

<div class="common-semi-modal filter-holder with-border" [ngClass]="{'active' : show_promocodes }">
<header>
@@ -144,7 +145,6 @@
</div>
</div>
</div>

</div>
</section>
</div>


+ 30
- 1
src/app/cart/cart.page.ts View File

@@ -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();
}

}

+ 2
- 19
src/app/orders/orders.component.ts View File

@@ -2,8 +2,7 @@ import { Component, OnInit } from '@angular/core';
import { IMall } from '../models/mall';
import { MallService } from '../services/mall.service';
import { CartItemService } from '../services/cart-item.service';
import CartItem from '../models/cart-item';
import * as moment from 'moment';
import { OrderService } from '../services/order.service';

@Component({
selector: 'app-orders',
@@ -16,27 +15,11 @@ export class OrdersComponent implements OnInit {

constructor(
private mallService: MallService,
private cartService: CartItemService,
private orderService: OrderService
) { }

ngOnInit() {
this.mallService.getAllMalls().then((malls: Array<IMall>) => {
this.all_malls = malls;
});

this.cartService.getAllCartItems().then((cart_items: Array<CartItem>) => {
this.cart_items = cart_items;

let i: number;

for (i = 0; i < this.cart_items.length; i += 1) {
let mall = this.all_malls.find(mall => mall.id === this.cart_items[i].mall_id);
let outlet = mall.outlets.find(outlet => outlet.id === this.cart_items[i].outlet_id);
this.cart_items[i].menu_details = outlet.menu_items.find(item => item.id === this.cart_items[i].menu_item);
}

console.log(this.cart_items);
});
}

}

+ 0
- 1
src/app/outlet-details/outlet-details.page.ts View File

@@ -50,7 +50,6 @@ export class OutletDetailsPage implements OnInit {
this.mall_details = data;
this.outlet_details = this.mall_details.outlets.find((outlet) => outlet.id === outlet_id);
this.temp_outlet_details = JSON.parse(JSON.stringify(this.outlet_details));
console.log(this.temp_outlet_details);
});
}



+ 4
- 0
src/app/services/cart-item.service.ts View File

@@ -28,4 +28,8 @@ export class CartItemService {
});
}

async clearCartItems() {
return await this.storage.set('cart_items', '[]');
}

}

+ 12
- 0
src/app/services/order.service.spec.ts View File

@@ -0,0 +1,12 @@
import { TestBed } from '@angular/core/testing';

import { OrderService } from './order.service';

describe('OrderService', () => {
beforeEach(() => TestBed.configureTestingModule({}));

it('should be created', () => {
const service: OrderService = TestBed.get(OrderService);
expect(service).toBeTruthy();
});
});

+ 45
- 0
src/app/services/order.service.ts View File

@@ -0,0 +1,45 @@
import { Injectable } from '@angular/core';
import { Storage } from '@ionic/storage';
import * as uuid from 'uuid';
import CartItem from '../models/cart-item';

@Injectable({
providedIn: 'root'
})
export class OrderService {
orders: any = [];

constructor(
private storage: Storage
) { }

async createOrder(cart_items: Array<CartItem>) {
return this.storage.get('orders').then((data: string) => {
if (data === null) {
this.orders.push({
id: uuid(),
order_items: cart_items
});
this.storage.set('orders', JSON.stringify(this.orders)).then((data) => {
console.log(data);
});
} else {
this.orders = JSON.parse(data);
this.orders.push({
id: uuid(),
order_items: cart_items
});
this.storage.set('orders', JSON.stringify(this.orders));
}
}, () => {
console.log("failed");
});
}

async getCreatedOrders() {
return await this.storage.get('orders').then((data: string) => {
return JSON.parse(data);
});
}

}

+ 1
- 21
src/app/services/user-data.service.ts View File

@@ -1,30 +1,10 @@
import { Injectable } from '@angular/core';
import CartItem from '../models/cart-item';
import { Storage } from '@ionic/storage';

@Injectable({
providedIn: 'root'
})
export class UserDataService {
orders: Array<CartItem> = [];

constructor(
private storage: Storage
) { }

async updateUserOrders(orders: Array<CartItem>) {
this.orders = orders;
this.storage.set('user_orders', JSON.stringify(this.orders));
return await this.orders;
}

async getAllUserOrders() {
return await this.storage.get('user_orders').then((data: string) => {
if (data) {
return JSON.parse(data);
} else {
return [];
}
});
}
) { }
}

Loading…
Cancel
Save