Skip to content

Commit

Permalink
#115 order cart now working, now need a check out page
Browse files Browse the repository at this point in the history
  • Loading branch information
tareq89 committed Aug 21, 2016
1 parent 14bd49b commit a174c79
Show file tree
Hide file tree
Showing 10 changed files with 165 additions and 43 deletions.
11 changes: 11 additions & 0 deletions app/cart/cart-icon/cart-icon.component.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,15 @@ i {
margin-left: 5px;
width: 20px;
text-align: center;
}


textarea {
width: 100%;
padding: 10px;
}


#item-quanity {
width: 15%;
}
69 changes: 67 additions & 2 deletions app/cart/cart-icon/cart-icon.component.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,71 @@
<div (click)="update()">
<div (click)="openShoppingCartModal()">
<i class="fa fa-shopping-cart fa-lg" aria-hidden="true"></i>
<div class="quantity-background">
<strong>{{numberOfItems}}</strong>
</div>
</div>
</div>


<modal #shoppingCart class="modal_vcenter">
<modal-header [show-close]="true">
<h1>SHOPPING CART</h1>
</modal-header>
<modal-body>
<table class="table table-sm table-hover">
<thead>
<tr>
<th>#</th>
<th>Item</th>
<th>Qty</th>
<th>Unit Price</th>
<th>Weight</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let item of orderCart.OrderCart.PackageList; let i = index">
<th scope="row">{{i+1}}</th>
<td>
{{ item.Item }}
<ul class="list-inline">
<li><a class="pointer" (click)="removeItem(i)">Remove</a></li>
</ul>
</td>
<td id="item-quanity">
<input type="number" class="form-control" [(ngModel)]="item.Quantity" (ngModelChange)="itemChanged($event)">
</td>
<td>{{ item.Price }}</td>
<td>{{ item.Weight }}</td>
<td>{{ item.Total | number:'1.2-2' }}</td>
</tr>
<tr>
<td colspan="2" class="text-right">Total Weight</td>
<td>{{ orderCart.OrderCart.TotalWeight }}</td>
<td colspan="2" class="text-right">Subtotal</td>
<td>{{ orderCart.OrderCart.SubTotal | number:'1.2-2' }}</td>
</tr>
<tr>
<td colspan="5" class="text-right">Delivery Charge</td>
<td>{{ orderCart.OrderCart.ServiceCharge }}</td>
</tr>
<tr>
<td colspan="5" class="text-right">Total</td>
<td>{{ orderCart.OrderCart.TotalToPay | number:'1.2-2' }}</td>
</tr>
</tbody>
</table>

<div *ngIf="orderCart.Description">
<h3>CUSTOM ORDER</h3>
<textarea [(ngModel)]="orderCart.Description"></textarea>
</div>

</modal-body>
<modal-footer>
<form>
<div class="form-group">
<button class="btn btn-primary pull-right" (click)="checkOut()">CHECKOUT</button>
</div>
</form>
</modal-footer>
</modal>
51 changes: 36 additions & 15 deletions app/cart/cart-icon/cart-icon.component.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,55 @@
import { Component, OnInit } from '@angular/core';
import { OrderCart } from '../../shared/model/order-cart'
import { Component, OnInit, ViewChild } from '@angular/core';
import { MODAL_DIRECTIVES, ModalComponent } from 'ng2-bs3-modal/ng2-bs3-modal';

import { OrderModel, PackageListModel } from '../../shared/model/order-model'
import { OrderCart } from '../../shared/model/order-cart'
import { Observable } from 'rxjs';


@Component({
selector: 'cart-icon',
templateUrl: 'app/cart/cart-icon/cart-icon.component.html',
styleUrls: ['app/cart/cart-icon/cart-icon.component.css']
styleUrls: ['app/cart/cart-icon/cart-icon.component.css'],
directives: [MODAL_DIRECTIVES, ModalComponent]
})


export class CartIconComponent implements OnInit{
numberOfItems: number = 0;

orderCart: OrderModel;
ngOnInit(){
this.orderCart = OrderCart.getOrderCart();
this.update();
}

public update(){
if(OrderCart.getOrderCart().OrderCart.PackageList){
this.numberOfItems = 0;
OrderCart.getOrderCart().OrderCart.PackageList.forEach(item => {
this.numberOfItems += item.Quantity;
});

if(OrderCart.getOrderCart().Description){
this.numberOfItems += 1;
}
}
OrderCart.update();
this.numberOfItems = OrderCart.totalQuantity();
}

itemChanged(value){
this.update();
}

removeItem(index: number) {
this.orderCart.OrderCart.PackageList.splice(index);
this.update();
}


checkOut(){
console.log(this.orderCart);

}

@ViewChild('shoppingCart')
shoppingCart: ModalComponent;
openShoppingCartModal(){
this.update();
this.shoppingCart.open();
}

closeShoppingCartModal(){
this.shoppingCart.close();
}


Expand Down
1 change: 0 additions & 1 deletion app/dashboard/order/order.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ <h1 class="control-label">{{formTitle}}</h1>
</div>
</div>
</div>

</div>

<div class="form-group">
Expand Down
6 changes: 3 additions & 3 deletions app/navbar/navbar.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
</div>
<div class="navbar-collapse collapse" [collapse]="isCollapsed">
<ul class="nav navbar-nav navbar-right">
<li *ngFor="let elm of navBarElementDict[State]">
<a class="pointer" (click)="elm.Event()">{{elm.Title}}</a>
</li>
<li>
<a class="pointer">
<cart-icon></cart-icon>
</a>
</li>
<li *ngFor="let elm of navBarElementDict[State]">
<a class="pointer" (click)="elm.Event()">{{elm.Title}}</a>
</li>
</ul>
</div>
<!--/.nav-collapse -->
Expand Down
32 changes: 31 additions & 1 deletion app/shared/model/order-cart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,42 @@ import { OrderModel } from './order-model'

export class OrderCart {
private static orderCart : OrderModel = new OrderModel();

private static numberOfItems: number = 0;
public static getOrderCart(){
return OrderCart.orderCart;
}

public static resetOrderCart(){
OrderCart.orderCart = new OrderModel();
}

public static update(){
if(this.orderCart.OrderCart.PackageList){

this.orderCart.OrderCart.SubTotal = 0;
this.orderCart.OrderCart.TotalToPay = 0;
this.orderCart.OrderCart.ServiceCharge = 150;

this.orderCart.OrderCart.PackageList.forEach(item => {
this.orderCart.OrderCart.SubTotal += (item.Price * item.Quantity);
this.orderCart.OrderCart.TotalToPay += this.orderCart.OrderCart.SubTotal +
this.orderCart.OrderCart.ServiceCharge;
item.Total = 0;
item.Total = (item.Price * item.Quantity);
})
}
}

public static totalQuantity(){
this.numberOfItems = 0;
if(this.orderCart.OrderCart.PackageList){
this.orderCart.OrderCart.PackageList.forEach(item => {
this.numberOfItems += item.Quantity;
});
}
if(this.orderCart.Description){
this.numberOfItems += 1;
}
return this.numberOfItems;
}
}
24 changes: 12 additions & 12 deletions app/shared/model/order-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ export class OrderModel {

export class OrderCartModel {
public PackageList: PackageListModel[];
public TotalVATAmount: number;
public SubTotal: number;
public ServiceCharge: number;
public TotalWeight: number;
public TotalToPay: number;
public TotalVATAmount: number = 0;
public SubTotal: number = 0;
public ServiceCharge: number = 0;
public TotalWeight: number = 0;
public TotalToPay: number = 0;
constructor() {

}
Expand All @@ -39,13 +39,13 @@ export class OrderCartModel {
export class PackageListModel {
public Item: string;
public PicUrl: string;
public Quantity: number;
public Price: number;
public VAT: number;
public Total: number;
public VATAmount: number;
public TotalPlusVAT: number;
public Weight: number;
public Quantity: number = 0;
public Price: number = 0;
public VAT: number = 0;
public Total: number = 0;
public VATAmount: number = 0;
public TotalPlusVAT: number = 0;
public Weight: number = 0;
constructor() {

}
Expand Down
1 change: 1 addition & 0 deletions app/vendor-menu/vendor-menu.component.css
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,5 @@ li a {

textarea {
width: 100%;
padding: 10px;
}
2 changes: 1 addition & 1 deletion app/vendor-menu/vendor-menu.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ <h3>ADD YOUR CUSTOM ORDER</h3>
<modal #cartModal class="modal_vcenter">
<modal-header [show-close]="true">
<h1> {{selectedItem.Item}} </h1>
<h3> {{selectedItem.Price}} </h3>
<h3> {{selectedItem.Total}} </h3>
</modal-header>
<modal-body>
<img class="selected-item-img" src="/assets/img/pop-up-pizza.jpg" alt="{{selectedItem.Item}}">
Expand Down
11 changes: 3 additions & 8 deletions app/vendor-menu/vendor-menu.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,27 +61,22 @@ export class VendorMenuComponent implements OnInit {
addItem(item) {
this.selectedItem.Item = item.item;
this.selectedItem.Price = item.price;
this.selectedItem.Total = item.price;
this.selectedItem.Quantity = 1;

console.log(OrderCart.getOrderCart().OrderCart.PackageList);

}

addMore(){
if(this.selectedItem.Quantity === 1)
{
this.selectedItem.Price += this.selectedItem.Price;
}
else {
this.selectedItem.Price += (this.selectedItem.Price/this.selectedItem.Quantity);
}
this.selectedItem.Total += this.selectedItem.Price;
this.selectedItem.Quantity += 1;
}

addLess(){
if(this.selectedItem.Quantity != 1)
{
this.selectedItem.Price -= (this.selectedItem.Price/this.selectedItem.Quantity);
this.selectedItem.Total -= this.selectedItem.Price;
this.selectedItem.Quantity -= 1;
}

Expand Down

0 comments on commit a174c79

Please sign in to comment.