Ecommerce Frontend Project
Ecommerce Frontend Project
================================
$ ng new ashokit_ecomm_frontend
$ cd ashokit_ecomm_frontend
$ ng serve --open
=================================================================
Step-2 : Retrieve Products From Backend and Display In Frontend
=================================================================
constructor(
public id: number,
public name: string,
public title: string,
public description: string,
public unitPrice: number,
public imageUrl: string,
public active: boolean,
public unitsInStock: number,
public dateCreated: Date,
public lastUpdated: Date
){}
}
getProducts(): Observable<Product[]>{
return this.httpClient.get<GetResponse>(this.apiUrl)
.pipe(map(response=> response._embedded.products));
}
}
interface GetResponse{
_embedded: {
products: Product[];
}
}
$ ng g c product-list
ngOnInit(): void {
this.productService.getProducts().subscribe(data => {
this.products = data;
})
}
}
<app-product-list></app-product-list>
====================================================
Step-3 : Beautify Products Display in Table Format
====================================================
<table class="table">
<thead class="table-dark">
<tr>
<th></th>
<th>Name</th>
<th>Price</th>
<th>Units in Stock</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let tempProduct of products">
<td class="align-middle">
<img src="{{tempProduct.imageUrl}}" height="50"/>
</td>
<td>{{tempProduct.name}}</td>
<td>{{tempProduct.unitPrice}}</td>
<td>{{tempProduct.unitsInStock}}</td>
</tr>
</tbody>
</table>
===========================================
Step-4 : eCommerce Template Integration
===========================================
## 1) Install bootstap
## 2) Install FontAwesome
## 5) Add custom styles in styles.css file (copy and paste from our template)
<div class="page-wrapper">
<!-- MENU SIDEBAR-->
<aside class="menu-sidebar d-none d-lg-block">
<div class="logo">
<a href="#">
<img src="assets/images/logo.png" alt="ashokit" class="img-
responsive">
</a>
</div>
<div class="menu-sidebar-content js-scrollbar1">
<nav class="navbar-sidebar">
<ul class="list-unstyled navbar-list">
<li>
<a href="#">Laptops</a>
</li>
<li>
<a href="#">Mobiles</a>
</li>
<li>
<a href="#">Shirts</a>
</li>
<li>
<a href="#">Beauty</a>
</li>
</ul>
</nav>
</div>
</aside>
<!-- END MENU SIDEBAR-->
<div class="page-container">
<!-- HEADER DESKTOP-->
<header class="header-desktop">
<div class="section-content section-content-p30">
<div class="container-fluid">
<div class="header-wrap">
<form class="form-header" onsubmit="return false;"
method="GET">
<input class="au-input au-input-xl" type="text"
name="search"
placeholder="Search for data ..." />
<button class="au-btn-submit" type="submit">
Search
</button>
</form>
<div class="cart-area d-n">
<a href="shopping-detail.html">
<div class="total">19.22 <span> 2</span> </div> <i
class="fa fa-shopping-cart"
aria-hidden="true"></i>
</a>
</div>
</div>
<div class="account-wrap"></div>
</div>
</div>
</header>
<!-- END HEADER DESKTOP-->
<!-- MAIN CONTENT-->
<app-product-list></app-product-list>
</div>
<footer>
<ul>
<li><a href="#">About Us</a></li>
<li><a href="#">Contact Us</a></li>
<li><a href="#">Help</a></li>
</ul>
</footer>
<div class="main-content">
<div class="section-content section-content-p30">
<div class="row">
<!-- loop over the collection of products -->
<div *ngFor="let tempProduct of products" class="col-md-3">
<div class="product-box">
<img src="{{ tempProduct.imageUrl }}" class="img-responsive">
<h1>{{ tempProduct.name }}</h1>
<div class="price">{{ tempProduct.unitPrice }}</div>
<a href="#" class="primary-btn">Add to cart</a>
</div>
</div>
</div>
</div>
</div>