Browse Source
checkout is working fine and project is almost complete use the db that is provided in git repo
gauravfullcomponent
checkout is working fine and project is almost complete use the db that is provided in git repo
gauravfullcomponent
8 changed files with 111 additions and 4 deletions
Split View
Diff Options
-
2Angular-UrbanBazaar/src/app/app-routing.module.ts
-
2Angular-UrbanBazaar/src/app/app.module.ts
-
4Angular-UrbanBazaar/src/app/components/cart/cart.component.html
-
15Angular-UrbanBazaar/src/app/components/cart/cart.component.ts
-
5Angular-UrbanBazaar/src/app/components/checkout/checkout.component.css
-
23Angular-UrbanBazaar/src/app/components/checkout/checkout.component.html
-
25Angular-UrbanBazaar/src/app/components/checkout/checkout.component.spec.ts
-
39Angular-UrbanBazaar/src/app/components/checkout/checkout.component.ts
@ -0,0 +1,5 @@ |
|||
.CartButtons{ |
|||
border-radius: 15px; |
|||
border-color:antiquewhite ; |
|||
background-color: beige; |
|||
} |
|||
@ -0,0 +1,23 @@ |
|||
<ng-container *ngIf="cartdetails.length !=0"> |
|||
<div class="container"> |
|||
<table> |
|||
<thead> |
|||
<tr> |
|||
<th>S.No</th> |
|||
<th>ProductName</th> |
|||
<th>ProductPrice</th> |
|||
</tr> |
|||
</thead> |
|||
|
|||
<tbody> |
|||
<tr *ngFor="let c of cartdetails; let i = index"> |
|||
<td>{{i+1}}</td> |
|||
<td>{{c.productname}}</td> |
|||
<td>{{c.productprice}}</td> |
|||
</tr> |
|||
<td><strong>Grand Total : Rs.{{grandTotal}}</strong></td> |
|||
</tbody> |
|||
</table> |
|||
<button (click)=logout() class="CartButtons">log out</button> |
|||
</div> |
|||
</ng-container> |
|||
@ -0,0 +1,25 @@ |
|||
import { ComponentFixture, TestBed } from '@angular/core/testing'; |
|||
|
|||
import { CheckoutComponent } from './checkout.component'; |
|||
|
|||
describe('CheckoutComponent', () => { |
|||
let component: CheckoutComponent; |
|||
let fixture: ComponentFixture<CheckoutComponent>; |
|||
|
|||
beforeEach(async () => { |
|||
await TestBed.configureTestingModule({ |
|||
declarations: [ CheckoutComponent ] |
|||
}) |
|||
.compileComponents(); |
|||
}); |
|||
|
|||
beforeEach(() => { |
|||
fixture = TestBed.createComponent(CheckoutComponent); |
|||
component = fixture.componentInstance; |
|||
fixture.detectChanges(); |
|||
}); |
|||
|
|||
it('should create', () => { |
|||
expect(component).toBeTruthy(); |
|||
}); |
|||
}); |
|||
@ -0,0 +1,39 @@ |
|||
import { Component, OnInit } from '@angular/core'; |
|||
import { Router } from '@angular/router'; |
|||
import { Cart } from 'src/app/models/cart'; |
|||
import { CartService } from 'src/app/services/cart.service'; |
|||
|
|||
@Component({ |
|||
selector: 'app-checkout', |
|||
templateUrl: './checkout.component.html', |
|||
styleUrls: ['./checkout.component.css'] |
|||
}) |
|||
export class CheckoutComponent implements OnInit { |
|||
public cartdetails:Cart[]; |
|||
public grandTotal = 0; |
|||
constructor(private cartservice:CartService,private router: Router) { |
|||
|
|||
} |
|||
|
|||
logout() |
|||
{ |
|||
this.router.navigateByUrl("/"); |
|||
this.cartservice.deleteAll().subscribe(b=>{ |
|||
this.cartdetails.forEach((i,index)=>{ |
|||
this.cartdetails.splice(index); |
|||
}) |
|||
}); |
|||
// alert("db cleaned")
|
|||
} |
|||
|
|||
ngOnInit(): void { |
|||
this.cartservice.showCart() |
|||
.subscribe(res=>{ |
|||
this.cartdetails = res; |
|||
this.cartdetails.forEach((i,index)=>{ |
|||
this.grandTotal+=i.productprice; |
|||
}) |
|||
}) |
|||
} |
|||
|
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue