Merge branch 'adarsh' into 'master'
Adarsh
See merge request !34
Showing
... | @@ -3,16 +3,18 @@ | ... | @@ -3,16 +3,18 @@ |
<ion-menu> | <ion-menu> | ||
<ion-content> | <ion-content> | ||
<div class="side_menu_wrapper"> | <div class="side_menu_wrapper"> | ||
<ion-menu-toggle> | |||
<div class="top_banner"> | <div class="top_banner"> | ||
<div class="top_image"> | <div class="top_image"> | ||
</div> | </div> | ||
<div class="top_detail"> | <div class="top_detail" > | ||
<h4>John Doe</h4> | <h4>John Doe</h4> | ||
<p>[email protected]</p> | <p>[email protected]</p> | ||
</div> | </div> | ||
<div class="clear"></div> | <div class="clear"></div> | ||
</div> | </div> | ||
</ion-menu-toggle> | |||
<div class="sidemenu_list"> | <div class="sidemenu_list"> | ||
<ul> | <ul> | ||
<ion-menu-toggle> | <ion-menu-toggle> | ||
... | ... |
import { Injectable } from "@angular/core"; | import { Injectable } from '@angular/core'; | ||
import { | import { AngularFirestore, AngularFirestoreDocument, AngularFirestoreCollection } from '@angular/fire/firestore'; | ||
AngularFirestore, | import { Router, ActivatedRoute } from '@angular/router'; | ||
AngularFirestoreDocument, | import { Products } from './services/product'; | ||
AngularFirestoreCollection | import { Cart, CartItem } from './services/cart'; | ||
} from "@angular/fire/firestore"; | import { ServiceService } from './service.service'; | ||
import { Router, ActivatedRoute } from "@angular/router"; | import * as firebase from 'firebase'; | ||
import { Products } from "./services/product"; | import { take } from 'rxjs/operators'; | ||
import { Cart, CartItem } from "./services/cart"; | import { User } from './services/user'; | ||
import { ServiceService } from "./service.service"; | import { from } from 'rxjs'; | ||
import * as firebase from "firebase"; | |||
import { take } from "rxjs/operators"; | |||
import { User } from "./services/user"; | |||
import { from } from "rxjs"; | |||
@Injectable({ | @Injectable({ | ||
providedIn: "root" | providedIn: 'root' | ||
}) | }) | ||
export class CartsService { | export class CartsService { | ||
size: string; | size: string; | ||
... | @@ -31,15 +27,13 @@ export class CartsService { | ... | @@ -31,15 +27,13 @@ export class CartsService { |
public router: Router, | public router: Router, | ||
public service: ServiceService | public service: ServiceService | ||
) { | ) { | ||
this.custId = ""; | this.custId = ''; | ||
this.carts = []; | this.carts = []; | ||
const users = this.service.get("user").then(data => { | const users = this.service.get('user').then(data => { | ||
if (data) { | if (data) { | ||
data = JSON.parse(data); | data = JSON.parse(data); | ||
this.custId = data.uid; | this.custId = data.uid; | ||
console.log(this.custId); | console.log(this.custId); | ||
} else { | |||
this.custId = "WwHnLICVY2dvZGUHuKqasiTB91a2"; | |||
} | } | ||
}); | }); | ||
} | } | ||
... | @@ -48,20 +42,20 @@ export class CartsService { | ... | @@ -48,20 +42,20 @@ export class CartsService { |
this.prodId = product.prodId; | this.prodId = product.prodId; | ||
const prodRef = firebase | const prodRef = firebase | ||
.firestore() | .firestore() | ||
.collection("products") | .collection('products') | ||
.doc(this.prodId); | .doc(this.prodId); | ||
this.size = this.size === undefined ? product.size[0] : this.size; | this.size = this.size === undefined ? product.size[0] : this.size; | ||
this.color = this.color === undefined ? product.color[0] : this.color; | this.color = this.color === undefined ? product.color[0] : this.color; | ||
const cartRef: AngularFirestoreCollection<any> = this.afs.collection( | const cartRef: AngularFirestoreCollection<any> = this.afs.collection( | ||
"carts", | 'carts', | ||
ref => | ref => | ||
ref | ref | ||
.where("size", "==", this.size) | .where('size', '==', this.size) | ||
.where("color", "==", this.color) | .where('color', '==', this.color) | ||
.where("custId", "==", this.custId) | .where('custId', '==', this.custId) | ||
.where("product", "==", prodRef) | .where('product', '==', prodRef) | ||
); | ); | ||
cartRef | cartRef | ||
.valueChanges() | .valueChanges() | ||
... | @@ -71,7 +65,7 @@ export class CartsService { | ... | @@ -71,7 +65,7 @@ export class CartsService { |
if (value.length === 0) { | if (value.length === 0) { | ||
product.image = | product.image = | ||
product.image === undefined | product.image === undefined | ||
? "../assets/[email protected]" | ? '../assets/[email protected]' | ||
: product.image; | : product.image; | ||
const cart: Cart = { | const cart: Cart = { | ||
color: this.color, | color: this.color, | ||
... | @@ -88,21 +82,21 @@ export class CartsService { | ... | @@ -88,21 +82,21 @@ export class CartsService { |
}; | }; | ||
console.log(cart); | console.log(cart); | ||
this.afs | this.afs | ||
.collection("carts") | .collection('carts') | ||
.add(cart) | .add(cart) | ||
.then(docRef => { | .then(docRef => { | ||
const neworderId = docRef.id; | const neworderId = docRef.id; | ||
this.afs | this.afs | ||
.collection("carts") | .collection('carts') | ||
.doc(neworderId) | .doc(neworderId) | ||
.update({ cartId: docRef.id }) | .update({ cartId: docRef.id }) | ||
.then(() => { | .then(() => { | ||
console.log("Booking Successfully"); | console.log('Booking Successfully'); | ||
document.body.scrollTop = document.documentElement.scrollTop = 0; | document.body.scrollTop = document.documentElement.scrollTop = 0; | ||
}); | }); | ||
}) | }) | ||
.catch(error => { | .catch(error => { | ||
console.error("Error adding document: ", error); | console.error('Error adding document: ', error); | ||
}); | }); | ||
} else { | } else { | ||
console.log(value); | console.log(value); | ||
... | @@ -111,11 +105,11 @@ export class CartsService { | ... | @@ -111,11 +105,11 @@ export class CartsService { |
// tslint:disable-next-line:radix | // tslint:disable-next-line:radix | ||
const qty = parseInt(value[0].qty) + 1; | const qty = parseInt(value[0].qty) + 1; | ||
this.afs | this.afs | ||
.collection("carts") | .collection('carts') | ||
.doc(cartId) | .doc(cartId) | ||
.update({ qty: `${qty}` }) | .update({ qty: `${qty}` }) | ||
.then(() => { | .then(() => { | ||
console.log("Booking Successfully"); | console.log('Booking Successfully'); | ||
document.body.scrollTop = document.documentElement.scrollTop = 0; | document.body.scrollTop = document.documentElement.scrollTop = 0; | ||
}); | }); | ||
} | } | ||
... | @@ -124,8 +118,8 @@ export class CartsService { | ... | @@ -124,8 +118,8 @@ export class CartsService { |
public async cartList() { | public async cartList() { | ||
const cartRef: AngularFirestoreCollection<any> = this.afs.collection( | const cartRef: AngularFirestoreCollection<any> = this.afs.collection( | ||
"carts", | 'carts', | ||
ref => ref.where("custId", "==", this.custId) | ref => ref.where('custId', '==', this.custId) | ||
); | ); | ||
cartRef.valueChanges().subscribe(value => { | cartRef.valueChanges().subscribe(value => { | ||
this.carts = []; | this.carts = []; | ||
... | @@ -183,7 +177,7 @@ export class CartsService { | ... | @@ -183,7 +177,7 @@ export class CartsService { |
this.carts[index].qty = qty; | this.carts[index].qty = qty; | ||
console.log(this.carts[index].qty); | console.log(this.carts[index].qty); | ||
this.afs | this.afs | ||
.collection("carts") | .collection('carts') | ||
.doc(this.carts[index].cartId) | .doc(this.carts[index].cartId) | ||
.update({ | .update({ | ||
qty: this.carts[index].qty | qty: this.carts[index].qty | ||
... | @@ -195,7 +189,7 @@ export class CartsService { | ... | @@ -195,7 +189,7 @@ export class CartsService { |
this.cartTotal = 0; | this.cartTotal = 0; | ||
this.carts[index].qty = qty; | this.carts[index].qty = qty; | ||
this.afs | this.afs | ||
.collection("carts") | .collection('carts') | ||
.doc(this.carts[index].cartId) | .doc(this.carts[index].cartId) | ||
.update({ | .update({ | ||
qty: this.carts[index].qty | qty: this.carts[index].qty | ||
... | @@ -204,8 +198,21 @@ export class CartsService { | ... | @@ -204,8 +198,21 @@ export class CartsService { |
removeItem(index) { | removeItem(index) { | ||
this.afs | this.afs | ||
.collection("carts") | .collection('carts') | ||
.doc(this.carts[index].cartId) | .doc(this.carts[index].cartId) | ||
.delete(); | .delete(); | ||
} | } | ||
checkPromo(promoCode: string) { | |||
console.log(promoCode); | |||
const state = true; | |||
const promoRef: AngularFirestoreCollection<any> = this.afs.collection('promocode', ref => ref.where('promoCode', '==', promoCode) | |||
.where('status', '==', state)); | |||
return promoRef.valueChanges(); | |||
} | |||
} | } |
Please
register
or
sign in
to comment