Merge branch 'adarsh' into 'master'
Adarsh
See merge request !74
Showing
| ... | ... | @@ -51,73 +51,83 @@ export class CartsService { |
| this.size = this.size === undefined ? product.size[0] : this.size; | ||
| this.color = this.color === undefined ? product.color[0] : this.color; | ||
| this.service.get('cartCenter').then((centerData) => { | ||
| console.log(centerData); | ||
| if (centerData === null || (centerData === product.centerId)) { | ||
| this.service.set('cartCenter', product.centerId); | ||
| const cartRef: AngularFirestoreCollection<any> = this.afs.collection( | ||
| 'carts', | ||
| ref => | ||
| ref | ||
| .where('size', '==', this.size) | ||
| .where('color', '==', this.color) | ||
| .where('custId', '==', this.custId) | ||
| .where('product', '==', prodRef) | ||
| ); | ||
| cartRef | ||
| .valueChanges() | ||
| .pipe(take(1)) | ||
| .subscribe(value => { | ||
| // console.log(value); | ||
| const cartRef: AngularFirestoreCollection<any> = this.afs.collection( | ||
| 'carts', | ||
| ref => | ||
| ref | ||
| .where('size', '==', this.size) | ||
| .where('color', '==', this.color) | ||
| .where('custId', '==', this.custId) | ||
| .where('product', '==', prodRef) | ||
| ); | ||
| cartRef | ||
| .valueChanges() | ||
| .pipe(take(1)) | ||
| .subscribe(value => { | ||
| // console.log(value); | ||
| if (value.length === 0) { | ||
| product.image = | ||
| product.image === undefined | ||
| ? '../assets/[email protected]' | ||
| : product.image; | ||
| const cart: Cart = { | ||
| color: this.color, | ||
| custId: this.custId, | ||
| shopperId: product.shopperId, | ||
| product: firebase.firestore().doc(`products/${this.prodId}`), | ||
| image: product.image, | ||
| prodId: product.prodId, | ||
| price: product.price, | ||
| prodName: product.prodName, | ||
| shopper: product.shopper, | ||
| qty: 1, | ||
| size: this.size | ||
| }; | ||
| // console.log(cart); | ||
| this.afs | ||
| .collection('carts') | ||
| .add(cart) | ||
| .then(docRef => { | ||
| const neworderId = docRef.id; | ||
| if (value.length === 0) { | ||
| product.image = | ||
| product.image === undefined | ||
| ? '../assets/[email protected]' | ||
| : product.image; | ||
| const cart: Cart = { | ||
| color: this.color, | ||
| custId: this.custId, | ||
| shopperId: product.shopperId, | ||
| product: firebase.firestore().doc(`products/${this.prodId}`), | ||
| image: product.image, | ||
| prodId: product.prodId, | ||
| price: product.price, | ||
| prodName: product.prodName, | ||
| shopper: product.shopper, | ||
| qty: 1, | ||
| size: this.size | ||
| }; | ||
| // console.log(cart); | ||
| this.afs | ||
| .collection('carts') | ||
| .add(cart) | ||
| .then(docRef => { | ||
| const neworderId = docRef.id; | ||
| this.afs | ||
| .collection('carts') | ||
| .doc(neworderId) | ||
| .update({ cartId: docRef.id }) | ||
| .then(() => { | ||
| // console.log('Booking Successfully'); | ||
| document.body.scrollTop = document.documentElement.scrollTop = 0; | ||
| }); | ||
| }) | ||
| .catch(error => { | ||
| console.error('Error adding document: ', error); | ||
| }); | ||
| } else { | ||
| // console.log(value); | ||
| // alert('Item already added in the cart'); | ||
| const cartId = value[0].cartId; | ||
| // tslint:disable-next-line:radix | ||
| const qty = parseInt(value[0].qty) + 1; | ||
| this.afs | ||
| .collection('carts') | ||
| .doc(neworderId) | ||
| .update({ cartId: docRef.id }) | ||
| .doc(cartId) | ||
| .update({ qty: `${qty}` }) | ||
| .then(() => { | ||
| // console.log('Booking Successfully'); | ||
| document.body.scrollTop = document.documentElement.scrollTop = 0; | ||
| }); | ||
| }) | ||
| .catch(error => { | ||
| console.error('Error adding document: ', error); | ||
| }); | ||
| } else { | ||
| // console.log(value); | ||
| // alert('Item already added in the cart'); | ||
| const cartId = value[0].cartId; | ||
| // tslint:disable-next-line:radix | ||
| const qty = parseInt(value[0].qty) + 1; | ||
| this.afs | ||
| .collection('carts') | ||
| .doc(cartId) | ||
| .update({ qty: `${qty}` }) | ||
| .then(() => { | ||
| // console.log('Booking Successfully'); | ||
| document.body.scrollTop = document.documentElement.scrollTop = 0; | ||
| }); | ||
| } | ||
| }); | ||
| } | ||
| }); | ||
| } else { | ||
| this.service.showToast('Your cart is not empty', 'top', 'my-error', 2000); | ||
| } | ||
| }); | ||
| } | ||
| public async cartList() { | ||
| ... | ... | @@ -160,6 +170,7 @@ export class CartsService { |
| this.carts.push(cartItem); | ||
| }); | ||
| } else { | ||
| this.service.remove('cartCenter'); | ||
| // alert('No Products Found'); | ||
| } | ||
| }); | ||
| ... | ... |
Please
register
or
sign in
to comment