Skip to content

Commit

Permalink
Added guest user redirection (#247)
Browse files Browse the repository at this point in the history
## Why?
* To redirect guest user for login when he want to checkout.
   When guest user want to checkouts the order,  he will be redirected login page.

## This change addresses the need by: 
So user need to be login to complete his purchase.

delivers[#160167918]
[Story](https://www.pivotaltracker.com/story/show/160167918)
  • Loading branch information
gopalshimpi authored and pkrawat1 committed Aug 30, 2018
1 parent 448ce21 commit 5006b6f
Showing 1 changed file with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Store } from '@ngrx/store';
import { Subscription } from 'rxjs';
import { Component, OnInit, Input, OnDestroy, OnChanges } from '@angular/core';
import { environment } from '../../../../../environments/environment';
import { getAuthStatus } from '../../../../auth/reducers/selectors';

@Component({
selector: 'app-order-total-summary',
Expand All @@ -25,12 +26,19 @@ export class OrderTotalSummaryComponent implements OnInit, OnDestroy, OnChanges
shippingProgress;
currency = environment.config.currency_symbol;
freeShippingAmount = environment.config.freeShippingAmount;
isAuthenticated: boolean;

constructor(private store: Store<AppState>,
private checkoutService: CheckoutService,
private router: Router) {
this.stateSub$ = this.store.select(getOrderState)
.subscribe(state => this.orderState = state);

this.store.select(getAuthStatus).
subscribe(authStatus => {
this.isAuthenticated = authStatus
})

}

ngOnInit() {
Expand All @@ -42,14 +50,18 @@ export class OrderTotalSummaryComponent implements OnInit, OnDestroy, OnChanges
}

placeOrder() {
if (this.orderState === 'cart') {
this.checkoutService.changeOrderState().pipe(
tap(() => {
this.router.navigate(['/checkout', 'address']);
}))
.subscribe();
if (this.isAuthenticated) {
if (this.orderState === 'cart') {
this.checkoutService.changeOrderState().pipe(
tap(() => {
this.router.navigate(['/checkout', 'address']);
}))
.subscribe();
} else {
this.router.navigate(['/checkout', 'address']);
}
} else {
this.router.navigate(['/checkout', 'address']);
this.router.navigate(['/auth', 'login']);
}
}

Expand Down

0 comments on commit 5006b6f

Please sign in to comment.