Commit e5a9da76 by Adarsh K

Merge branch 'adarsh' into 'master'

Adarsh See merge request !101
parents c11d67ac 4e83b7aa
...@@ -27,11 +27,11 @@ const routes: Routes = [ ...@@ -27,11 +27,11 @@ const routes: Routes = [
IonicModule, IonicModule,
AgmDirectionModule, AgmDirectionModule,
AgmCoreModule.forRoot({ AgmCoreModule.forRoot({
apiKey: 'AIzaSyBnCzDk6ec1OJFcW5FYgxP3LWVHMNumGDM' apiKey: 'AIzaSyBn6hOlr6YHcZAmbptlsmbhvH5iQllWflE'
}), }),
RouterModule.forChild(routes) RouterModule.forChild(routes)
], ],
declarations: [HomePage] declarations: [HomePage]
}) })
export class HomePageModule { } export class HomePageModule { }
// AIzaSyBn6hOlr6YHcZAmbptlsmbhvH5iQllWflE // //AIzaSyBnCzDk6ec1OJFcW5FYgxP3LWVHMNumGDM
\ No newline at end of file \ No newline at end of file
...@@ -24,10 +24,10 @@ const routes: Routes = [ ...@@ -24,10 +24,10 @@ const routes: Routes = [
IonicModule, IonicModule,
AgmDirectionModule, AgmDirectionModule,
AgmCoreModule.forRoot({ AgmCoreModule.forRoot({
apiKey: 'AIzaSyBn6hOlr6YHcZAmbptlsmbhvH5iQllWflE' apiKey: 'AIzaSyBnCzDk6ec1OJFcW5FYgxP3LWVHMNumGDM'
}), }),
RouterModule.forChild(routes) RouterModule.forChild(routes)
], ],
declarations: [TrackorderPage] declarations: [TrackorderPage]
}) })
export class TrackorderPageModule {} export class TrackorderPageModule { }
...@@ -76,22 +76,28 @@ export class WishlistPage implements OnInit { ...@@ -76,22 +76,28 @@ export class WishlistPage implements OnInit {
this.wishService this.wishService
.addToCart(this.custId, this.wishService.whishItem) .addToCart(this.custId, this.wishService.whishItem)
.then(data => { .then(data => {
this.wishService console.log(data);
.clearWish(this.custId) if (data === false) {
.then(datas => { this.loader = false;
this.loader = false; this.service.showToast('You have items from another Shopping Centre', 'top', 'my-error', 2000);
this.service.showToast('Added to cart', 'top', 'my-toast', 2000); } else {
this.router.navigateByUrl('cart', { replaceUrl: true, queryParams: data }); this.wishService
}) .clearWish(this.custId)
.catch(err => { .then(datas => {
this.loader = false; this.loader = false;
this.service.showToast( this.service.showToast('Added to cart', 'top', 'my-toast', 2000);
'Something went wrong', this.router.navigateByUrl('cart', { replaceUrl: true, queryParams: data });
'top', })
'my-error', .catch(err => {
1000 this.loader = false;
); this.service.showToast(
}); 'Something went wrong',
'top',
'my-error',
1000
);
});
}
}) })
.catch(err => { .catch(err => {
this.loader = false; this.loader = false;
......
...@@ -21,6 +21,13 @@ export class AddressService { ...@@ -21,6 +21,13 @@ export class AddressService {
addressState: number; addressState: number;
constructor(public afs: AngularFirestore, public subject: SubjectService) { constructor(public afs: AngularFirestore, public subject: SubjectService) {
this.addressState = 0; this.addressState = 0;
this.subject.getUserData().subscribe(userData => {
if (userData) {
console.log('address reinitialized');
const userDatas = JSON.parse(userData);
this.addList(userDatas.uid);
}
});
} }
public async addList(userId: string) { public async addList(userId: string) {
...@@ -146,8 +153,11 @@ export class AddressService { ...@@ -146,8 +153,11 @@ export class AddressService {
} }
public async getNearBy(centerId, userId, distance) { public async getNearBy(centerId, userId, distance) {
// latitude, longitude, distance, userId // latitude, longitude, distance, userId
console.log(centerId, userId, distance); console.log(centerId, userId, distance);
this.custAddress = undefined;
if (centerId) { if (centerId) {
this.afs.collection('centers').doc(centerId).ref.get().then((doc) => { this.afs.collection('centers').doc(centerId).ref.get().then((doc) => {
if (doc.exists) { if (doc.exists) {
...@@ -221,15 +231,24 @@ export class AddressService { ...@@ -221,15 +231,24 @@ export class AddressService {
// alert('No Orders Found'); // alert('No Orders Found');
} }
if (this.addressList.length > 0 && this.nearestList.length > 0) { if (this.addressList.length > 0) {
this.addressList.forEach((address) => { if (this.nearestList.length > 0) {
const index = this.nearestList.findIndex(x => x.addressId === address.addressId); this.addressList.forEach((address) => {
if (index >= 0) { const index = this.nearestList.findIndex(x => x.addressId === address.addressId);
address.nearest = true; if (index >= 0) {
} address.nearest = true;
}); }
});
} else {
this.addressList.forEach((address) => {
address.nearest = false;
});
}
console.log(this.addressList);
} }
console.log(this.addressList);
this.addressList = this.addressList.sort((a: any, b: any) => { this.addressList = this.addressList.sort((a: any, b: any) => {
return b.nearest - a.nearest; return b.nearest - a.nearest;
...@@ -246,6 +265,7 @@ export class AddressService { ...@@ -246,6 +265,7 @@ export class AddressService {
} }
setAddress() { setAddress() {
this.custAddress = undefined;
console.log(this.nearestList); console.log(this.nearestList);
if (this.nearestList.length > 0) { if (this.nearestList.length > 0) {
this.custAddress = this.nearestList.find( this.custAddress = this.nearestList.find(
......
...@@ -153,11 +153,11 @@ export class CartsService { ...@@ -153,11 +153,11 @@ export class CartsService {
const res = value; const res = value;
this.cartTotal = 0; this.cartTotal = 0;
if (res.length > 0) { if (res.length > 0) {
if (this.cartCenter === '') { // if (this.cartCenter === '') {
this.cartCenter = res[0].centerId; this.cartCenter = res[0].centerId;
this.addressService.defaultAddress(this.custId); // }
this.addressService.getNearBy(this.cartCenter, this.custId, this.service.distance); this.addressService.defaultAddress(this.custId);
} this.addressService.getNearBy(this.cartCenter, this.custId, this.service.distance);
res.forEach(item => { res.forEach(item => {
const cartItem: CartItem = { const cartItem: CartItem = {
cartId: item.cartId, cartId: item.cartId,
......
...@@ -120,11 +120,13 @@ export class WishService { ...@@ -120,11 +120,13 @@ export class WishService {
} }
addToCart(custId, items) { addToCart(custId, items) {
console.log(items);
const promise = new Promise(resolve => { const promise = new Promise(resolve => {
items.forEach(item => { items.forEach(item => {
this.cartService.buyNow(item); this.cartService.buyNow(item).then(res => {
resolve(res);
});
}); });
resolve(true);
}); });
return promise; return promise;
} }
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
<body> <body>
<script <script
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBn6hOlr6YHcZAmbptlsmbhvH5iQllWflE&libraries=geometry"></script> src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBnCzDk6ec1OJFcW5FYgxP3LWVHMNumGDM&libraries=geometry"></script>
<app-root></app-root> <app-root></app-root>
</body> </body>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment