Commit b11164ec by Adarsh K

changes

parent 43e28941
......@@ -27,11 +27,11 @@ const routes: Routes = [
IonicModule,
AgmDirectionModule,
AgmCoreModule.forRoot({
apiKey: 'AIzaSyBnCzDk6ec1OJFcW5FYgxP3LWVHMNumGDM'
apiKey: 'AIzaSyBn6hOlr6YHcZAmbptlsmbhvH5iQllWflE'
}),
RouterModule.forChild(routes)
],
declarations: [HomePage]
})
export class HomePageModule { }
// AIzaSyBn6hOlr6YHcZAmbptlsmbhvH5iQllWflE
\ No newline at end of file
// //AIzaSyBnCzDk6ec1OJFcW5FYgxP3LWVHMNumGDM
\ No newline at end of file
......@@ -24,10 +24,10 @@ const routes: Routes = [
IonicModule,
AgmDirectionModule,
AgmCoreModule.forRoot({
apiKey: 'AIzaSyBn6hOlr6YHcZAmbptlsmbhvH5iQllWflE'
apiKey: 'AIzaSyBnCzDk6ec1OJFcW5FYgxP3LWVHMNumGDM'
}),
RouterModule.forChild(routes)
],
declarations: [TrackorderPage]
})
export class TrackorderPageModule {}
export class TrackorderPageModule { }
......@@ -76,22 +76,28 @@ export class WishlistPage implements OnInit {
this.wishService
.addToCart(this.custId, this.wishService.whishItem)
.then(data => {
this.wishService
.clearWish(this.custId)
.then(datas => {
this.loader = false;
this.service.showToast('Added to cart', 'top', 'my-toast', 2000);
this.router.navigateByUrl('cart', { replaceUrl: true, queryParams: data });
})
.catch(err => {
this.loader = false;
this.service.showToast(
'Something went wrong',
'top',
'my-error',
1000
);
});
console.log(data);
if (data === false) {
this.loader = false;
this.service.showToast('You have items from another Shopping Centre', 'top', 'my-error', 2000);
} else {
this.wishService
.clearWish(this.custId)
.then(datas => {
this.loader = false;
this.service.showToast('Added to cart', 'top', 'my-toast', 2000);
this.router.navigateByUrl('cart', { replaceUrl: true, queryParams: data });
})
.catch(err => {
this.loader = false;
this.service.showToast(
'Something went wrong',
'top',
'my-error',
1000
);
});
}
})
.catch(err => {
this.loader = false;
......
......@@ -21,6 +21,13 @@ export class AddressService {
addressState: number;
constructor(public afs: AngularFirestore, public subject: SubjectService) {
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) {
......@@ -146,8 +153,11 @@ export class AddressService {
}
public async getNearBy(centerId, userId, distance) {
// latitude, longitude, distance, userId
console.log(centerId, userId, distance);
this.custAddress = undefined;
if (centerId) {
this.afs.collection('centers').doc(centerId).ref.get().then((doc) => {
if (doc.exists) {
......@@ -221,15 +231,24 @@ export class AddressService {
// alert('No Orders Found');
}
if (this.addressList.length > 0 && this.nearestList.length > 0) {
this.addressList.forEach((address) => {
const index = this.nearestList.findIndex(x => x.addressId === address.addressId);
if (index >= 0) {
address.nearest = true;
}
});
if (this.addressList.length > 0) {
if (this.nearestList.length > 0) {
this.addressList.forEach((address) => {
const index = this.nearestList.findIndex(x => x.addressId === address.addressId);
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) => {
return b.nearest - a.nearest;
......@@ -246,6 +265,7 @@ export class AddressService {
}
setAddress() {
this.custAddress = undefined;
console.log(this.nearestList);
if (this.nearestList.length > 0) {
this.custAddress = this.nearestList.find(
......
......@@ -153,11 +153,11 @@ export 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);
}
// 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: CartItem = {
cartId: item.cartId,
......
......@@ -120,11 +120,13 @@ export class WishService {
}
addToCart(custId, items) {
console.log(items);
const promise = new Promise(resolve => {
items.forEach(item => {
this.cartService.buyNow(item);
this.cartService.buyNow(item).then(res => {
resolve(res);
});
});
resolve(true);
});
return promise;
}
......
......@@ -19,7 +19,7 @@
<body>
<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>
</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