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