|
|
@ -1,4 +1,5 @@ |
|
|
import { Component, OnInit } from '@angular/core'; |
|
|
import { Component, OnInit } from '@angular/core'; |
|
|
|
|
|
import { Router } from '@angular/router'; |
|
|
import { Observable } from 'rxjs'; |
|
|
import { Observable } from 'rxjs'; |
|
|
import { Cart } from 'src/app/models/cart'; |
|
|
import { Cart } from 'src/app/models/cart'; |
|
|
import { Product } from 'src/app/models/product'; |
|
|
import { Product } from 'src/app/models/product'; |
|
|
@ -14,7 +15,8 @@ import { UserService } from 'src/app/services/user.service'; |
|
|
export class CartComponent implements OnInit { |
|
|
export class CartComponent implements OnInit { |
|
|
|
|
|
|
|
|
public cartdetails:Cart[]; |
|
|
public cartdetails:Cart[]; |
|
|
constructor(private cartservice:CartService,private userservice:UserService) { |
|
|
|
|
|
|
|
|
public grandTotal = 0; |
|
|
|
|
|
constructor(private cartservice:CartService,private userservice:UserService,private router: Router) { |
|
|
// this.cartdetails = this.cartservice.showCart();
|
|
|
// this.cartdetails = this.cartservice.showCart();
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -23,7 +25,9 @@ export class CartComponent implements OnInit { |
|
|
this.cartservice.showCart() |
|
|
this.cartservice.showCart() |
|
|
.subscribe(res=>{ |
|
|
.subscribe(res=>{ |
|
|
this.cartdetails = res; |
|
|
this.cartdetails = res; |
|
|
// this.grandTotal = this.cartservice.getTotalPrice();
|
|
|
|
|
|
|
|
|
this.cartdetails.forEach((i,index)=>{ |
|
|
|
|
|
this.grandTotal+=i.productprice; |
|
|
|
|
|
}) |
|
|
}) |
|
|
}) |
|
|
// let uid = this.userservice.currentUser.userid;
|
|
|
// let uid = this.userservice.currentUser.userid;
|
|
|
// this.cartservice.showCart(uid).subscribe(data1=>{
|
|
|
// this.cartservice.showCart(uid).subscribe(data1=>{
|
|
|
@ -36,12 +40,19 @@ export class CartComponent implements OnInit { |
|
|
// })
|
|
|
// })
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
checkout() |
|
|
|
|
|
{ |
|
|
|
|
|
this.router.navigateByUrl('/checkout'); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
removeItem(id:number){ |
|
|
removeItem(id:number){ |
|
|
this.cartservice.deleteCart(id).subscribe(a=>{ |
|
|
this.cartservice.deleteCart(id).subscribe(a=>{ |
|
|
this.cartdetails.forEach((i,index)=>{ |
|
|
this.cartdetails.forEach((i,index)=>{ |
|
|
if(i.cartid == id) |
|
|
if(i.cartid == id) |
|
|
{ |
|
|
{ |
|
|
this.cartdetails.splice(index,1) |
|
|
this.cartdetails.splice(index,1) |
|
|
|
|
|
this.grandTotal-=i.productprice; |
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |
|
|
}); |
|
|
}); |
|
|
|