10" style="color: green;">In Stock
0" style="color: green;"> Only {{cartItem.book.inStockNumber}} In Stock
diff --git a/store-front/src/app/components/shopping-cart/shopping-cart.component.ts b/store-front/src/app/components/shopping-cart/shopping-cart.component.ts index c133081..289108a 100644 --- a/store-front/src/app/components/shopping-cart/shopping-cart.component.ts +++ b/store-front/src/app/components/shopping-cart/shopping-cart.component.ts @@ -18,6 +18,8 @@ export class ShoppingCartComponent implements OnInit { private cartItemNumber: number; private shoppingCart: ShoppingCart = new ShoppingCart(); private cartItemUpdated:boolean; + private emptyCart: boolean; + private notEnoughStock: boolean; constructor(private router:Router, private cartService: CartService) { } @@ -76,6 +78,25 @@ export class ShoppingCartComponent implements OnInit { ); } + onCheckout() { + if (this.cartItemNumber==0) { + this.emptyCart=true; + } else { + + for (let item of this.cartItemList) { + if(item.qty > item.book.inStockNumber) { + console.log("not enough stock"); + + this.notEnoughStock = true; + + return; + } + } + + this.router.navigate(['/order']); + } + } + ngOnInit() { this.getCartItemList();