Browse Source

Added PromoCodes to Cart Items

master
prahalad 4 years ago
parent
commit
d798ab7b88
10 changed files with 185 additions and 121 deletions
  1. +6
    -5
      src/app/cart/cart.page.html
  2. +123
    -109
      src/app/cart/cart.page.ts
  3. +3
    -0
      src/app/faq/faq.component.html
  4. +0
    -0
      src/app/faq/faq.component.scss
  5. +27
    -0
      src/app/faq/faq.component.spec.ts
  6. +14
    -0
      src/app/faq/faq.component.ts
  7. +2
    -2
      src/app/login/login.page.ts
  8. +0
    -3
      src/app/outlet-details/outlet-details.page.html
  9. +7
    -0
      src/app/profile/profile.page.html
  10. +3
    -2
      src/app/profile/profile.page.scss

+ 6
- 5
src/app/cart/cart.page.html View File

@@ -64,9 +64,9 @@
<ul class="breakups">
<li> <label> Total after discounts </label> <span> &#8377; {{ getTotalCartAmount() }} </span> </li>
<li> <label> Promocode </label> <span>
<ion-button fill="clear" *ngIf="!selected_promocode" (click)="show_promocodes = true"> Apply </ion-button>
<ion-button fill="clear" *ngIf="selected_promocode" (click)="selected_promocode = ''">
Remove {{ selected_promocode }}
<ion-button fill="clear" *ngIf="!selected_promo" (click)="show_promocodes = true"> Apply </ion-button>
<ion-button fill="clear" *ngIf="selected_promo" (click)="selected_promo = ''">
Remove {{ selected_promo.offersCode }}
<ion-icon name="close-circle"></ion-icon>
</ion-button>
</span> </li>
@@ -87,9 +87,9 @@
APPLY PROMOCODE <button (click)="show_promocodes = false"> Done </button>
</header>
<ion-list *ngFor="let promoCodes of mallPromoCodes">
<ion-item (click)="selected_promocode = code.offersCode"
<ion-item (click)="selected_promo = code"
*ngFor="let code of promoCodes">
<ion-radio slot="start" [checked]="selected_promocode === code.offersCode"></ion-radio>
<ion-radio slot="start" [checked]="selected_promo === code"></ion-radio>
<ion-label class="ion-text-wrap">
<div class="heading"> {{ code.offersTitle }} </div>
<div class="code"> Promocode: <span> {{ code.offersCode }} </span> </div>
@@ -98,6 +98,7 @@
</ion-label>
</ion-item>
</ion-list>

</div>

<div class="common-semi-modal instant-menu" [ngClass]="{'active' : showInstantMenu }" *ngIf="temp_outlet_details">


+ 123
- 109
src/app/cart/cart.page.ts View File

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


+ 3
- 0
src/app/faq/faq.component.html View File

@@ -0,0 +1,3 @@
<p>
faq works!
</p>

+ 0
- 0
src/app/faq/faq.component.scss View File


+ 27
- 0
src/app/faq/faq.component.spec.ts View File

@@ -0,0 +1,27 @@
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { FaqComponent } from './faq.component';

describe('FaqComponent', () => {
let component: FaqComponent;
let fixture: ComponentFixture<FaqComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ FaqComponent ],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(FaqComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});

+ 14
- 0
src/app/faq/faq.component.ts View File

@@ -0,0 +1,14 @@
import { Component, OnInit } from '@angular/core';

@Component({
selector: 'app-faq',
templateUrl: './faq.component.html',
styleUrls: ['./faq.component.scss'],
})
export class FaqComponent implements OnInit {

constructor() { }

ngOnInit() {}

}

+ 2
- 2
src/app/login/login.page.ts View File

@@ -11,8 +11,8 @@ import { LoadingController } from '@ionic/angular';
})
export class LoginPage implements OnInit {
credentials = {
username: 'geethu',
password: '123456789',
username: 'prahalad1',
password: 'Reset@123',
login_type: 'user'
};



+ 0
- 3
src/app/outlet-details/outlet-details.page.html View File

@@ -47,9 +47,6 @@
<div class="card">
<h3>
{{ outlet_details.outlet_name }}
<ion-button size="small" fill="clear">
<ion-icon name="information-circle"></ion-icon>
</ion-button>
</h3>
<p> {{ outlet_details.description }} </p>
<div class="stats-holder">


+ 7
- 0
src/app/profile/profile.page.html View File

@@ -51,6 +51,13 @@
</figure>
<span> NOTIFICATION </span>
</div>
<div class="tab" [ngClass]="{'active' : selected_tab === 'NOTIFICATION'}"
(click)="selected_tab = 'NOTIFICATION'">
<figure>
<img src="assets/custom/hotel-bell.svg">
</figure>
<span> FAQ </span>
</div>
<div class="tab" (click)="logout()">
<figure>
<img src="assets/custom/logout.svg">


+ 3
- 2
src/app/profile/profile.page.scss View File

@@ -93,12 +93,13 @@
}

.tabs-holder {
display: flex;
display: -webkit-box;;
align-items: stretch;
padding: 10px 0;
overflow: auto;

.tab {
width: 25%;
width: 90px;

&.active {
figure {


Loading…
Cancel
Save