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
-
-
+
+
+
+