Browse Source

checkout is working fine and project is almost complete use the db that is provided in git repo

gauravfullcomponent
Gaurav Daharia 4 years ago
parent
commit
50dbc2519f
8 changed files with 111 additions and 4 deletions
  1. 2
      Angular-UrbanBazaar/src/app/app-routing.module.ts
  2. 2
      Angular-UrbanBazaar/src/app/app.module.ts
  3. 4
      Angular-UrbanBazaar/src/app/components/cart/cart.component.html
  4. 15
      Angular-UrbanBazaar/src/app/components/cart/cart.component.ts
  5. 5
      Angular-UrbanBazaar/src/app/components/checkout/checkout.component.css
  6. 23
      Angular-UrbanBazaar/src/app/components/checkout/checkout.component.html
  7. 25
      Angular-UrbanBazaar/src/app/components/checkout/checkout.component.spec.ts
  8. 39
      Angular-UrbanBazaar/src/app/components/checkout/checkout.component.ts

2
Angular-UrbanBazaar/src/app/app-routing.module.ts

@ -3,11 +3,13 @@ import { RouterModule, Routes } from '@angular/router';
import { LoginComponent } from './auth/login/login.component'; import { LoginComponent } from './auth/login/login.component';
import { SignUpComponent } from './auth/sign-up/sign-up.component'; import { SignUpComponent } from './auth/sign-up/sign-up.component';
import { CartComponent } from './components/cart/cart.component'; import { CartComponent } from './components/cart/cart.component';
import { CheckoutComponent } from './components/checkout/checkout.component';
import { HomeComponent } from './components/home/home.component'; import { HomeComponent } from './components/home/home.component';
import { MemberlistComponent } from './components/memberlist/memberlist.component'; import { MemberlistComponent } from './components/memberlist/memberlist.component';
import { UserProfileDetailsComponent } from './components/user-profile-details/user-profile-details.component'; import { UserProfileDetailsComponent } from './components/user-profile-details/user-profile-details.component';
const routes: Routes = [ const routes: Routes = [
{path:'checkout', component:CheckoutComponent},
{ path: '', component: LoginComponent}, { path: '', component: LoginComponent},
{ path: 'login', component: LoginComponent}, { path: 'login', component: LoginComponent},
{ path: 'signup', component: SignUpComponent}, { path: 'signup', component: SignUpComponent},

2
Angular-UrbanBazaar/src/app/app.module.ts

@ -18,6 +18,7 @@ import { FlexLayoutModule } from '@angular/flex-layout';
import { LoginComponent } from './auth/login/login.component'; import { LoginComponent } from './auth/login/login.component';
import { SignUpComponent } from './auth/sign-up/sign-up.component'; import { SignUpComponent } from './auth/sign-up/sign-up.component';
import { MemberlistComponent } from './components/memberlist/memberlist.component'; import { MemberlistComponent } from './components/memberlist/memberlist.component';
import { CheckoutComponent } from './components/checkout/checkout.component';
@NgModule({ @NgModule({
declarations: [ declarations: [
@ -29,6 +30,7 @@ import { MemberlistComponent } from './components/memberlist/memberlist.componen
LoginComponent, LoginComponent,
SignUpComponent, SignUpComponent,
MemberlistComponent, MemberlistComponent,
CheckoutComponent,
], ],
imports: [ imports: [
BrowserModule, BrowserModule,

4
Angular-UrbanBazaar/src/app/components/cart/cart.component.html

@ -24,8 +24,8 @@
<td colspan="4"></td> <td colspan="4"></td>
<td><button (click)=emptyCart() class="CartButtons">Empty Cart</button></td> <td><button (click)=emptyCart() class="CartButtons">Empty Cart</button></td>
<td><button routerLink='/home' class="CartButtons">Shop More</button></td> <td><button routerLink='/home' class="CartButtons">Shop More</button></td>
<td><button class="CartButtons">Checkout</button></td>
<!-- <td><strong>Grand Total : Rs.{{grandTotal}}</strong></td> -->
<td><button (click)=checkout() class="CartButtons">Checkout</button></td>
<td><strong>Grand Total : Rs.{{grandTotal}}</strong></td>
</tr> </tr>
</tbody> </tbody>
</div> </div>

15
Angular-UrbanBazaar/src/app/components/cart/cart.component.ts

@ -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;
} }
}) })
}); });

5
Angular-UrbanBazaar/src/app/components/checkout/checkout.component.css

@ -0,0 +1,5 @@
.CartButtons{
border-radius: 15px;
border-color:antiquewhite ;
background-color: beige;
}

23
Angular-UrbanBazaar/src/app/components/checkout/checkout.component.html

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

25
Angular-UrbanBazaar/src/app/components/checkout/checkout.component.spec.ts

@ -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();
});
});

39
Angular-UrbanBazaar/src/app/components/checkout/checkout.component.ts

@ -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;
})
})
}
}
Loading…
Cancel
Save