services
Showing
... | ... | @@ -3,110 +3,122 @@ import { Injectable } from '@angular/core'; |
import { AngularFirestore } from '@angular/fire/firestore'; | ||
import { Router } from '@angular/router'; | ||
import { ServiceService } from './service.service'; | ||
import { AddressService } from './address.service'; | ||
import * as firebase from 'firebase'; | ||
import { take } from 'rxjs/operators'; | ||
let CartsService = class CartsService { | ||
constructor(afs, router, service) { | ||
constructor(afs, router, service, addressService) { | ||
this.afs = afs; | ||
this.router = router; | ||
this.service = service; | ||
this.addressService = addressService; | ||
this.carts = []; | ||
this.custId = ''; | ||
this.cartCenter = ''; | ||
this.carts = []; | ||
const users = this.service.get('user').then(data => { | ||
if (data) { | ||
data = JSON.parse(data); | ||
this.custId = data.uid; | ||
// console.log(this.custId); | ||
console.log(this.custId); | ||
} | ||
}); | ||
} | ||
buyNow(product) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
this.prodId = product.prodId; | ||
const prodRef = firebase | ||
.firestore() | ||
.collection('products') | ||
.doc(this.prodId); | ||
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).then(() => { | ||
const cartRef = 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 = { | ||
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; | ||
const promise = new Promise(resolve => { | ||
this.prodId = product.prodId; | ||
const prodRef = firebase | ||
.firestore() | ||
.collection('products') | ||
.doc(this.prodId); | ||
this.size = this.size === undefined ? product.size[0] : this.size; | ||
this.color = this.color === undefined ? product.color[0] : this.color; | ||
if (this.cartCenter === '' || (this.cartCenter === product.centerId)) { | ||
if (this.cartCenter === '') { | ||
this.cartCenter = product.centerId; | ||
this.addressService.defaultAddress(this.custId); | ||
this.addressService.getNearBy(this.cartCenter, this.custId, this.service.distance); | ||
} | ||
const cartRef = 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 = { | ||
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, | ||
centerId: product.centerId, | ||
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(cartId) | ||
.update({ qty: `${qty}` }) | ||
.doc(neworderId) | ||
.update({ cartId: docRef.id }) | ||
.then(() => { | ||
// console.log('Booking Successfully'); | ||
document.body.scrollTop = document.documentElement.scrollTop = 0; | ||
}); | ||
} | ||
}); | ||
resolve(true); | ||
}) | ||
.catch(error => { | ||
console.error('Error adding document: ', error); | ||
resolve(false); | ||
}); | ||
} | ||
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; | ||
}); | ||
resolve(true); | ||
} | ||
}); | ||
} | ||
else { | ||
this.service.showToast('Your cart is not empty', 'top', 'my-error', 2000); | ||
resolve(false); | ||
} | ||
}); | ||
return promise; | ||
}); | ||
} | ||
cartList() { | ||
cartList(custId) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
this.custId = custId; | ||
console.log('called'); | ||
const cartRef = this.afs.collection('carts', ref => ref.where('custId', '==', this.custId)); | ||
cartRef.valueChanges().subscribe(value => { | ||
... | ... | @@ -114,6 +126,11 @@ let CartsService = class CartsService { |
const res = value; | ||
this.cartTotal = 0; | ||
if (res.length > 0) { | ||
if (this.cartCenter === '') { | ||
this.cartCenter = res[0].centerId; | ||
this.addressService.defaultAddress(this.custId); | ||
this.addressService.getNearBy(this.cartCenter, this.custId, this.service.distance); | ||
} | ||
res.forEach(item => { | ||
const cartItem = { | ||
cartId: item.cartId, | ||
... | ... | @@ -144,7 +161,7 @@ let CartsService = class CartsService { |
}); | ||
} | ||
else { | ||
this.service.remove('cartCenter'); | ||
this.cartCenter = ''; | ||
// alert('No Products Found'); | ||
} | ||
}); | ||
... | ... | @@ -200,7 +217,8 @@ CartsService = tslib_1.__decorate([ |
}), | ||
tslib_1.__metadata("design:paramtypes", [AngularFirestore, | ||
Router, | ||
ServiceService]) | ||
ServiceService, | ||
AddressService]) | ||
], CartsService); | ||
export { CartsService }; | ||
//# sourceMappingURL=cart.service.js.map | ||
\ No newline at end of file |
... | ... | @@ -6,8 +6,8 @@ |
<ion-row class="no-gutter"> | ||
<ion-col class="no-gutter" size="2"> | ||
<button class="nav_btn nav_back_white floatLeft" (click)="goBack()"> | ||
<img src="../assets/arrow_white.png" /> | ||
</button> | ||
<img src="../assets/arrow_white.png" /> | ||
</button> | ||
</ion-col> | ||
<ion-col class="no-gutter" size="8"> | ||
<div class="nav_title floatLeft"> | ||
... | ... | @@ -68,14 +68,15 @@ |
<ul> | ||
<li (click)="goToPage('productlist')"> | ||
<div class="nearby_image"> | ||
<img [src]="data.product[0].image" onerror="this.src='../assets/[email protected]'" /> | ||
<img [src]="data.product[0].image" | ||
onerror="this.src='../assets/[email protected]'" /> | ||
</div> | ||
<div class="nearby_detail"> | ||
<h5> | ||
<span class="floatLeft">{{data.shopperName}}</span> | ||
<span class="floatRight">{{data.product[0].qty}} | ||
<img src="../assets/Path61_2.png" /> | ||
</span> | ||
<img src="../assets/Path61_2.png" /> | ||
</span> | ||
<div class="clear"></div> | ||
</h5> | ||
<p class="prodName">{{unEscape(data.product[0].prodName)}}</p> | ||
... | ... | @@ -91,9 +92,10 @@ |
</h6> | ||
<h5>Quantity : <span>{{product.qty}}</span></h5> | ||
<h5> | ||
Amount : <strong>A$ {{service.formatNumber(product.price)}}</strong><span class="afterpay">{{data.paymentMode}}</span> | ||
Amount : <strong>A$ {{service.formatNumber(product.price)}}</strong><span | ||
class="afterpay">{{data.paymentMode}}</span> | ||
</h5> | ||
<h5 *ngIf="data.orderStatus >= 3 && data.orderStatus < 7"> | ||
<h5 *ngIf="data.orderStatus >= 3 || data.orderStatus < 7"> | ||
Delivery time : <span>{{deliveryTime}}</span> | ||
</h5> | ||
<h5>Order Status : <span>{{getStatus(data.orderStatus)}}</span></h5> | ||
... | ... | @@ -103,8 +105,9 @@ |
<div class="delivery-wrap"> | ||
<h4 class="floatLeft">DELIVERY</h4> | ||
<span class="floatRight" *ngIf="cancelDelivery > 0 && data.orderStatus != 0 && data.orderStatus != 8"><img | ||
class="ng-tns-c3-0" src="../../assets/edit.png" (click)="changeAddress(data.orderId)" /></span> | ||
<span class="floatRight" | ||
*ngIf="cancelDelivery > 0 && data.orderStatus != 0 && data.orderStatus != 8"><img | ||
class="ng-tns-c3-0" src="../../assets/edit.png" (click)="changeAddress(data.orderId)" /></span> | ||
<div class="clear"></div> | ||
</div> | ||
... | ... | @@ -113,9 +116,10 @@ |
{{data.deliveryAddress.addressType}},<br />{{data.deliveryAddress.address}}, | ||
<br /> {{data.deliveryAddress.building}}, <br /> {{data.deliveryAddress.landmark}} | ||
</h5> | ||
<button class="cancel_btn" (click)="cancelOrder(data.orderId)" *ngIf="cancelDelivery > 0 && data.orderStatus != 0 && data.orderStatus != 8"> | ||
CANCEL THIS ORDER | ||
</button> | ||
<button class="cancel_btn" (click)="cancelOrder(data.orderId)" | ||
*ngIf="cancelDelivery > 0 && data.orderStatus != 0 && data.orderStatus != 8"> | ||
CANCEL THIS ORDER | ||
</button> | ||
<!-- <hr /> --> | ||
</div> | ||
... | ... |
Please
register
or
sign in
to comment