diff --git a/Angular-UrbanBazaar/src/app/components/cart/cart.component.html b/Angular-UrbanBazaar/src/app/components/cart/cart.component.html index a93fe44..2eadaef 100644 --- a/Angular-UrbanBazaar/src/app/components/cart/cart.component.html +++ b/Angular-UrbanBazaar/src/app/components/cart/cart.component.html @@ -8,7 +8,7 @@ S.No ProductName ProductPrice - + Quantity Action @@ -19,7 +19,9 @@ {{c.product.productprice}} {{c.quantity}} - +   +   + diff --git a/Angular-UrbanBazaar/src/app/components/cart/cart.component.ts b/Angular-UrbanBazaar/src/app/components/cart/cart.component.ts index 4b966ad..32ca5d8 100644 --- a/Angular-UrbanBazaar/src/app/components/cart/cart.component.ts +++ b/Angular-UrbanBazaar/src/app/components/cart/cart.component.ts @@ -15,18 +15,25 @@ export class CartComponent implements OnInit { totalPrice: number = 0; username: String = ''; authcode: String = ''; + constructor(private cartService: CartService, private route: Router) {} ngOnInit(): void { this.username = window.sessionStorage.getItem('username'); this.authcode = window.sessionStorage.getItem('authcode'); - if (this.authcode !== null) { + if (this.authcode != null) { this.uid = window.sessionStorage.getItem('user_id'); } + this.reloadCartData(); + } + + public reloadCartData() { this.cartService.getCartByUser(this.uid).subscribe((data1) => { this.cartNo = data1.length; this.cartItems = data1; - console.log(this.cartItems); + this.cartItems.forEach(element => { + console.log(element); + }); this.cartItems.forEach((i, index) => { this.totalPrice = this.totalPrice + i.price; }); @@ -44,7 +51,7 @@ export class CartComponent implements OnInit { }; console.log(qty, amount); this.cartItems.forEach((i, index) => { - if (i.cartid == cid) { + if (i.cart_id == cid) { this.cartItems[index].quantity = qty; this.cartItems[index].price = amount; } @@ -55,58 +62,33 @@ export class CartComponent implements OnInit { }); } - public decreaseQty(cid: number, quantity: number, price: number) { + decreaseQty(cid:number,quantity:number,price:number) { this.totalPrice = 0; - console.log('Decrease Quantity'); - let amount: number = price - price / quantity; - let qty: number = quantity - 1; - let cart: Cart = { - quantity: qty, - price: amount, - }; - console.log(quantity, qty, price, amount); - this.cartItems.forEach((i, index) => { - if (i.cartid == cid) { + console.log("Decrease Quantity") + let amount:number = (price*quantity)-price; + let qty:number = quantity - 1; + let cart:Cart = { + quantity : qty, + price : amount + } + console.log(quantity,qty,price,amount); + this.cartItems.forEach((i,index) => { + if (i.cart_id == cid) { this.cartItems[index].quantity = qty; this.cartItems[index].price = amount; } - }); - this.cartService.editCartItem(cart, cid).subscribe((data) => {}); - this.cartItems.forEach((i, index) => { + }) + this.cartService.editCartItem(cart,cid).subscribe(data => { + }) + this.cartItems.forEach((i,index) => { this.totalPrice = this.totalPrice + i.price; - }); + }) } - public deleteCartItems(cid: number) { + public deleteCartItem(cid: number) { this.totalPrice = 0; - this.cartService.deleteCartItem(cid).subscribe((data) => { - this.cartItems.forEach((i, index) => { - if (i.cartid == cid) { - this.cartItems.splice(index, 1); - } - }); - this.cartService.getCartByUser(this.uid).subscribe((data1) => { - this.cartNo = data1.length; - this.cartItems = data1; - console.log(this.cartItems); - this.cartItems.forEach((i, index) => { - this.totalPrice = this.totalPrice + i.price; - }); - }); - }); - } - - public onLogout() { - if (this.authcode != null) { - this.authcode = null; - this.username = null; - window.sessionStorage.removeItem('username'); - window.sessionStorage.removeItem('user_id'); - window.sessionStorage.removeItem('authcode'); - window.sessionStorage.removeItem('isLoggedIn'); - this.cartNo = 0; - this.route.navigateByUrl('/home'); - } + this.cartService.deleteCartItem(cid).subscribe(); + this.reloadCartData(); } public emptyCartForUser() { diff --git a/Angular-UrbanBazaar/src/app/components/home/home.component.html b/Angular-UrbanBazaar/src/app/components/home/home.component.html index 594e8d2..93a2fde 100644 --- a/Angular-UrbanBazaar/src/app/components/home/home.component.html +++ b/Angular-UrbanBazaar/src/app/components/home/home.component.html @@ -1,10 +1,12 @@   + background-color: white; border-color: forestgreen;" class="EditProfile" (click)=EditProfile()> + Edit Profile   - -

+   + + +

diff --git a/Angular-UrbanBazaar/src/app/components/home/home.component.ts b/Angular-UrbanBazaar/src/app/components/home/home.component.ts index e9693f2..e873464 100644 --- a/Angular-UrbanBazaar/src/app/components/home/home.component.ts +++ b/Angular-UrbanBazaar/src/app/components/home/home.component.ts @@ -11,9 +11,9 @@ import { Cart } from 'src/app/models/cart'; styleUrls: ['./home.component.css'], }) export class HomeComponent implements OnInit { - uid:any = 0; - username:any = ''; - authcode:any = ''; + uid: any = 0; + username: String = ''; + authcode: String = ''; public products: Product[]; public Searchedproducts: Product[]; searchValue: string = ''; @@ -28,16 +28,20 @@ export class HomeComponent implements OnInit { this.router.navigateByUrl('/showCart'); } - addCart(productPrice: number, pid: number) { + public addCart(productPrice: number, pid: number) { let cartData: Cart = { - quantity : 1, - price: productPrice - } - this.cartservice.postCart(cartData, this.uid, pid); - alert("Added "+pid+" with price "+productPrice); + quantity: 1, + price: productPrice, + }; + this.cartservice.postCart(cartData, this.uid, pid).subscribe( + ()=> alert('Added ' + pid + ' with price ' + productPrice) + ); + console.log('Added ' + pid + ' with price ' + productPrice); + console.log(cartData); + // alert('Added ' + pid + ' with price ' + productPrice); } - searchProduct() { + public searchProduct() { if (this.searchValue == '') { this.Searchedproducts = this.products; } else { @@ -46,17 +50,20 @@ export class HomeComponent implements OnInit { ); } } + EditProfile() { - this.router.navigateByUrl('/user-profile-details'); + this.router.navigateByUrl('/userprofile'); } + Members() { this.router.navigateByUrl('/memberlist'); } + ngOnInit(): void { - this.username = window.sessionStorage.getItem("username"); - this.authcode = window.sessionStorage.getItem("authcode"); + this.username = window.sessionStorage.getItem('username'); + this.authcode = window.sessionStorage.getItem('authcode'); if (this.authcode !== null) { - this.uid = window.sessionStorage.getItem("user_id"); + this.uid = window.sessionStorage.getItem('user_id'); } this.productservice.showAllProduct().subscribe((res) => { @@ -64,4 +71,16 @@ export class HomeComponent implements OnInit { this.Searchedproducts = res; }); } + + public onLogout() { + if (this.authcode != null) { + this.authcode = null; + this.username = null; + window.sessionStorage.removeItem("username"); + window.sessionStorage.removeItem("user_id"); + window.sessionStorage.removeItem("authcode"); + window.sessionStorage.removeItem("isLoggedIn"); + this.router.navigateByUrl("/login"); + } + } } diff --git a/Angular-UrbanBazaar/src/app/components/page-nav-bar/page-nav-bar.component.html b/Angular-UrbanBazaar/src/app/components/page-nav-bar/page-nav-bar.component.html index 7ebff71..6c184b7 100644 --- a/Angular-UrbanBazaar/src/app/components/page-nav-bar/page-nav-bar.component.html +++ b/Angular-UrbanBazaar/src/app/components/page-nav-bar/page-nav-bar.component.html @@ -1,5 +1,5 @@