Using Eclipse Build A Simple Online Shopping Site With Angular IDE Plugin

In this article, we will explore about creating a simple online shopping site using Angular with Eclipse IDE. Most of all we use IDE’s like visual studio code, visual studio, etc. But there are some other tools which are very useful for developing Angular applications. One of the most used IDE is Eclipse. The Eclipse is an open-source popular IDE used by many developers around the globe. The Eclipse is also a user-friendly IDE especially developed for JAVA developers, and Eclipse comes in a variety of categories such as Eclipse for JAVA developers, Eclipse for C & C++ developers and Eclipse for JavaScript and web developers. You can find more information about Eclipse from the following link. Here we are going to use Eclipse for JavaScript and web developers IDE and you can download the following mentioned IDE from the following link.
 
Comparing with visual studio code, the Eclipse has some slight difference for example: In VS code we use Angular commands to create a component, class or a service. But here in Eclipse, the way of creating a component, class & as well as creating service is an easy way and we will explore it in the following steps as mentioned below.
 
After downloading the IDE from the following link, we need to install some of the supporting plugins. Download the Angular IDE plugin from the following below link. Open Eclipse->help->install new software and paste the following link in work with label. By downloading the plugin from this link, the required plugins will be automatically added to Eclipse IDE.
 
http://www.genuitec.com/updates/codemix/ci/
 
Using Eclipse Build A Simple Online Shopping Site With Angular IDE Plugin
 
The first step is to create a new Angular project, for that select->file->new->project-> Angular project and click-> Next, and select the Angular CLI to version 8.3.12 and select->next.
 
Using Eclipse Build A Simple Online Shopping Site With Angular IDE Plugin
 
Using Eclipse Build A Simple Online Shopping Site With Angular IDE Plugin
 
The Eclipse IDE will automatically execute the necessary process in order to create a Angular project, so click-> finish.
 
Using Eclipse Build A Simple Online Shopping Site With Angular IDE Plugin
 
Using Eclipse Build A Simple Online Shopping Site With Angular IDE Plugin
 
The next step is to install bootstrap to our project, which helps in providing a better UI experience, for that use the following command in the terminal. For using terminal in eclipse use the shortcut key ctrl+alt+T and enter the following command.
 
npm install bootstrap --save
 
After that open index.html and add the following code inside of the head tag as shown below.
  1. <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">  
  2. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">  
Using Eclipse Build A Simple Online Shopping Site With Angular IDE Plugin
 
The next step is to we will create two new components named as shopping-cart and product-list, follow the below mentioned steps to create the components, Right click->app->new-> component
 
Then provide the name of the components and click->finish.
 
Using Eclipse Build A Simple Online Shopping Site With Angular IDE Plugin
 
Using Eclipse Build A Simple Online Shopping Site With Angular IDE Plugin
 
Using Eclipse Build A Simple Online Shopping Site With Angular IDE Plugin
 
Now open app.component.html file and replace the following code inside of it.
  1. <!-- <app-navbar></app-navbar> -->  
  2. <div class="container-fluid">  
  3.     <div class="row">  
  4.         <!-- <div class="col-sm-12"><app-header></app-header></div>-->  
  5.     </div>  
  6.     <div class="row">  
  7.         <div class="col-sm-12">  
  8.             <app-shopping-cart></app-shopping-cart>  
  9.         </div>  
  10.     </div>  
  11.     <div class="row">  
  12.         <div class="col-sm-12">  
  13.             <!-- <app-footer></app-footer> -->  
  14.         </div>  
  15.     </div>  
  16. </div>  
  17. <router-outlet></router-outlet>  
Then create a class file named as product, for that right click-> app->new->class and provide the name as product & click->finish.
 
Using Eclipse Build A Simple Online Shopping Site With Angular IDE Plugin
 
Using Eclipse Build A Simple Online Shopping Site With Angular IDE Plugin
 
Continue to further step, now we need to create a service file named as cart-list.service and for that right click->app->new->service and provide the name for the service and then click->finish.
 
Using Eclipse Build A Simple Online Shopping Site With Angular IDE Plugin
 
Using Eclipse Build A Simple Online Shopping Site With Angular IDE Plugin
 
The next step is to create a new folder inside the assets folder. Create a new folder by right click->assets->new->folder and provide a name as a product for the folder. In addition to that, you can have some of the product images inside of that folder.
 
Using Eclipse Build A Simple Online Shopping Site With Angular IDE Plugin
 
Now coming to the main point.
 
Step 1
 
Open the product.ts file and replace the following code inside of it. Then we can keep proceeding to next step.
  1. export class Product {  
  2.     constructor(public productId: number, public productImage: string, public productName: string, public productCost: number, public productDescription: string) {}  
  3. }  
  4. export class CartList {  
  5.     public sno: number;  
  6.     public productId: number;  
  7.     public quantity: number;  
  8.     public productName: string;  
  9.     public productImage: string;  
  10.     public productCost: number;  
  11. }  
Step 2
 
Open product-list.component.html file and place the following code inside of it.
  1. <nav class="navbar navbar-expand-lg navbar-light bg-dark">  
  2.     <a class="navbar-brand text-light" href="#">Shopcart</a>  
  3.     <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"  
  4.   
  5. aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">  
  6.         <span class="navbar-toggler-icon"></span>  
  7.     </button>  
  8.     <div class="collapse navbar-collapse" id="navbarSupportedContent">  
  9.         <ul class="navbar-nav mr-auto">  
  10.             <li class="nav-item active">  
  11.                 <a class="nav-link text-light" (click)="onList()" href="#">List   
  12.                     <span class="sr-only">(current)</span>  
  13.                 </a>  
  14.             </li>  
  15.             <li class="nav-item">  
  16.                 <a class="nav-link text-light" (click)="onCart()" href="#">Cart   
  17.                     <span class="badge badge-secondary">{{addToCart.length}}</span>  
  18.                 </a>  
  19.             </li>  
  20.         </ul>  
  21.         <div class="form-group has-search" *ngIf="(showblock == 'list')">  
  22.             <span class="fa fa-search form-control-feedback"></span>  
  23.             <input type="text" (keyup) = "onSearch($event)" autocomplete="off" class="form-control" placeholder="Search">  
  24.             </div>  
  25.         </div>  
  26.     </nav>  
  27.     <div class="row" *ngIf="(showblock == 'list')">  
  28.         <div class="col-sm-12">  
  29.             <div class="page-header">  
  30.                 <h1>Smartphone's</h1>  
  31.             </div>  
  32.         </div>  
  33.         <div class="col-sm-4 mb-3" *ngFor="let product of productList ; let i = index">  
  34.             <div class="card card-block">  
  35.                 <img src="{{product.productImage}}" (click)="onChange(i)" class="card-img-top" alt="..." height="400px"  
  36.   
  37. width="100%">  
  38.                     <div class="card-body">  
  39.                         <h5 class="card-title">{{product.productName}}</h5>  
  40.                         <!-- <p class="card-text">{{product.productDescription}}</p> -->  
  41.                         <p class="card-text">  
  42.                             <strong>₹ {{product.productCost}}</strong>  
  43.                         </p>  
  44.                     </div>  
  45.                 </div>  
  46.             </div>  
  47.         </div>  
  48.         <div class="row" *ngIf="(showblock == 'description')">  
  49.             <div class="col-sm-4 mb-3">  
  50.                 <div class="card card-block">  
  51.                     <img src="{{description.productImage}}" class="card-img-top" alt="..." height="400px" width="100%">  
  52.                         <div class="row">  
  53.                             <div class="card-body col-sm-4">  
  54.                                 <h5 class="card-title">{{description.productName}}</h5>  
  55.                                 <!-- <p class="card-text">{{description.productDescription}}</p> -->  
  56.                                 <p class="card-text">  
  57.                                     <strong>₹ {{description.productCost}}</strong>  
  58.                                 </p>  
  59.                             </div>  
  60.                             <form (ngSubmit)="onSubmit()" #qty>  
  61.                                 <div class="ml-5 mt-3 col-sm-4">  
  62.                                     <input type="number" id="txtqty" #quantity name="quantity" min="1" max="100" step="1" value="1">  
  63.                                     </div>  
  64.                                 </form>  
  65.                                 <div class="col mt-3 col-sm-4">  
  66.                                     <button class="btn btn-warning" (click)="addCart(description.productId, currentIndex)">Add to cart</button>  
  67.                                 </div>  
  68.                             </div>  
  69.                         </div>  
  70.                     </div>  
  71.                     <div class="col-sm-8 mb-3">  
  72.                         <div class="card card-block">  
  73.                             <div class="card-body">  
  74.                                 <h3>Product Description</h3>  
  75.                                 <p>{{description.productDescription}}</p>  
  76.                             </div>  
  77.                         </div>  
  78.                     </div>  
  79.                 </div>  
  80.                 <div class="row" *ngIf="(showblock == 'cart')">  
  81.                     <div class="col-sm-12">  
  82.                         <table class="table table-hover">  
  83.                             <thead>  
  84.                                 <th>S.no</th>  
  85.                                 <th>Image</th>  
  86.                                 <th>Product name</th>  
  87.                                 <th>Price</th>  
  88.                                 <th>Quantity</th>  
  89.                                 <th>Total amount</th>  
  90.                             </thead>  
  91.                             <tbody>  
  92.                                 <tr *ngFor="let cList of addToCart; let i = index">  
  93.                                     <td width = "1%">{{i+1}}</td>  
  94.                                     <td width = "15%">  
  95.                                         <img src="{{cList.productImage}}" class="ml-2" alt="..." height="10%">  
  96.                                         </td>  
  97.                                         <td width = "15%">{{cList.productName}}</td>  
  98.                                         <td width = "15%">{{cList.productCost}}</td>  
  99.                                         <td width = "15%">  
  100.                                             <input type="number" #qty name="quantity" (keyup)="onKey($event, i)" [value] = "cList.quantity" min="1" max="500" step="1" value="1">  
  101.                                             </td>  
  102.                                             <td width = "15%">{{cList.quantity*cList.productCost}}</td>  
  103.                                             <td>  
  104.                                                 <button class="btn btn-danger" (click) = "remove(i)"></button>  
  105.                                             </td>  
  106.                                         </tr>  
  107.                                     </tbody>  
  108.                                 </table>  
  109.                                 <div class="row">  
  110.                                     <div class="col-sm-8">  
  111.                                         <p class="float-right">Payable Amount</p>  
  112.                                     </div>  
  113.                                     <div class="col-sm-4">  
  114.                                         <p class="ml-3">₹ {{totalamt}}</p>  
  115.                                     </div>  
  116.                                 </div>  
  117.                             </div>  
  118.                         </div>  
open product-list.component.ts file and replace the following code inside of it.
  1. import {  
  2.     Component,  
  3.     OnInit  
  4. } from '@angular/core';  
  5. import {  
  6.     Product,  
  7.     CartList  
  8. } from 'src/app/product';  
  9. import {  
  10.     CartListService  
  11. } from 'src/app/cart-list.service';  
  12. import {  
  13.     isString  
  14. } from 'util';  
  15. @Component({  
  16.     selector: 'app-product-list',  
  17.     templateUrl: './product-list.component.html',  
  18.     styleUrls: ['./product-list.component.css']  
  19. })  
  20. export class ProductListComponent implements OnInit {  
  21.     name = 'Angular';  
  22.     public showblock: string;  
  23.     public description: Product;  
  24.     public currentIndex: number;  
  25.     public noofitem: number;  
  26.     public findText: string;  
  27.     public totalamt: number;  
  28.     public sno: number;  
  29.     public navname: string;  
  30.     public qty: number;  
  31.     public searchText: string;  
  32.     private addToCart: Array < CartList > = [];  
  33.     public productList: Array < Product > = [];  
  34.     constructor(private srvProducts: CartListService) {  
  35.         this.showblock = 'list';  
  36.     }  
  37.     ngOnInit() {  
  38.         this.productList = this.srvProducts.getProductList();  
  39.         // this.getProductList();  
  40.     }  
  41.     onChange(index: number) {  
  42.         this.currentIndex = index;  
  43.         this.description = this.productList[index];  
  44.         // tslint:disable-next-line: no-unused-expression  
  45.         this.showblock = 'description';  
  46.     }  
  47.     onCart() {  
  48.         this.showblock = 'cart';  
  49.     }  
  50.     onList() {  
  51.         this.showblock = 'list';  
  52.     }  
  53.     public findProductIndex(ID: number) {  
  54.         // tslint:disable-next-line: prefer-for-of  
  55.         for (let i = 0; i < this.addToCart.length; i++) {  
  56.             if (this.addToCart[i].productId === ID) {  
  57.                 return i;  
  58.             }  
  59.         }  
  60.         return -1;  
  61.     }  
  62.     addCart(id: number, index: number) {  
  63.         // tslint:disable-next-line: triple-equals  
  64.         // console.log(id);  
  65.         const cid = this.findProductIndex(id);  
  66.         console.log(cid);  
  67.         const qty = parseInt(((document.getElementById('txtqty') as HTMLInputElement).value), 10);  
  68.         if (qty >= 1 && qty <= 100) {  
  69.             this.showblock = 'cart';  
  70.             // tslint:disable-next-line: align  
  71.         } else {  
  72.             alert('Quantity should be min value 1 and max value 100');  
  73.         }  
  74.         if (cid === -1) {  
  75.             // tslint:disable-next-line: no-use-before-declare  
  76.             const cartObj = new CartList();  
  77.             cartObj.productId = this.productList[index].productId;  
  78.             cartObj.productName = this.productList[index].productName;  
  79.             cartObj.productImage = this.productList[index].productImage;  
  80.             cartObj.productCost = this.productList[index].productCost;  
  81.             // tslint:disable-next-line: radix  
  82.             cartObj.quantity = qty;  
  83.             this.qty = qty;  
  84.             this.addToCart.push(cartObj);  
  85.             this.totalamt = 0;  
  86.             for (let i = 0; i <= this.addToCart.length; i++) {  
  87.                 this.totalamt = this.totalamt + (this.addToCart[i].productCost * this.addToCart[i].quantity);  
  88.             }  
  89.         } else {  
  90.             this.addToCart[index].quantity = this.addToCart[index].quantity + qty;  
  91.         }  
  92.     }  
  93.     remove(sno: number) {  
  94.         alert('Product was successfully removed in your cart');  
  95.         this.addToCart.splice(sno, 1);  
  96.         this.totalamt = 0;  
  97.         for (let i = 0; i <= this.addToCart.length; i++) {  
  98.             this.totalamt = this.totalamt + (this.addToCart[i].productCost * this.addToCart[i].quantity);  
  99.         }  
  100.     }  
  101.     onKey(event: any, index: number) { // without type info  
  102.         const cartObj = new CartList();  
  103.         cartObj.quantity += parseInt((event.target.value), 10);  
  104.         // console.log(event.target.value);  
  105.         this.addToCart[index].quantity = parseInt((event.target.value), 10);  
  106.         this.totalamt = 0;  
  107.         for (let i = 0; i <= this.addToCart.length; i++) {  
  108.             this.totalamt = this.totalamt + (this.addToCart[i].productCost * this.addToCart[i].quantity);  
  109.         }  
  110.     }  
  111.     onSearch(event: any) {  
  112.         this.findText = event.target.value.toLowerCase();  
  113.         this.productList = this.srvProducts.getProductList().filter(name => name.productName.toLowerCase().includes(this.findText));  
  114.     }  
  115. }  
Then open product-list.component.css file and place the following code inside of it.
  1. .has - search.form - control - feedback {  
  2.     positionabsolute;  
  3.     z - index: 2;  
  4.     displayblock;  
  5.     width2.375 rem;  
  6.     height2.375 rem;  
  7.     line - height2.375 rem;  
  8.     text - align: center;  
  9.     pointer - events: none;  
  10.     color#aaa;  
  11. }.has - search.form - control {  
  12.     padding - left: 2.375 rem;  
  13.     margin - bottom: -10 px;  
  14. }.tAmount {  
  15.     margin - left: 76 % ;  
  16.     margin - top: -25 px;  
  17. }.labelAmount {  
  18.     margin - left: 50 % ;  
  19.     margin - top: -25 px;  
  20. }.pay {  
  21.     floatright;  
  22.     /* margin-left: 500px; */  
  23. }  
Step 3
 
Now open the cart-list.service.ts file and replace the following code inside of it.
  1. import { Injectable } from '@angular/core';  
  2. import { Product } from 'src/app/product';  
  3. @Injectable({  
  4.    providedIn: 'root'  
  5. })  
  6. export class CartListService {  
  7. private lstProduct: Array<Product>;  
  8. constructor() {  
  9. this.lstProduct = [  
  10. new Product(1, '/assets/product/redmi.jpg''Redmi', 12000.00,  
  11. // tslint:disable-next-line: max-line-length  
  12. 'It\'s time to go big with the Redmi Note 7 Pro\'s 16-cm (6.3) FHD+ Dot Notch display. Powered by a 2.0 GHz Qualcomm Snapdragon 675 processor and 4 GB of RAM'),  
  13. new Product(2, '/assets/product/realme2.jpg''Realme', 11000.00,  
  14. 'The Realme C2 features a Diamond-back design with nanoscale composite particles that give it a shiny and premium look.'),  
  15. new Product(3, '/assets/product/oppo.jpg''Oppo', 14990.00,  
  16. 'With the OPPO A37, you will never have to retake selfies. Capture your best self with this smartphone\'s 5 MP front camera.'),  
  17. ];  
  18. }  
  19. getProductList() {  
  20.    return this.lstProduct;  
  21.    }  
  22. }  
Step 4
 
The next step is to open shopping-cart.component.html file and add the following code inside of it.
  1. <app-product-list></app-product-list>  
Step 5
 
The final step of the project is to open app.module.ts file and replace the following code inside of it.
  1. import { BrowserModule } from '@angular/platform-browser';  
  2. import { NgModule } from '@angular/core';  
  3. import { FormsModule } from '@angular/forms';  
  4. import { AppRoutingModule, } from './app-routing.module';  
  5. import { AppComponent } from './app.component';  
  6. import { ShoppingCartComponent } from './components/shopping-cart/shopping-cart.component';  
  7. import { ProductListComponent } from './components/shopping-cart/product-list/product-list.component';  
  8. import { CartListService } from './cart-list.service';  
  9. @NgModule({  
  10.    declarations: [  
  11.       AppComponent,  
  12.       ShoppingCartComponent,  
  13.       // routingComponents,  
  14.       ProductListComponent,  
  15.    ],  
  16. imports: [  
  17.    BrowserModule, FormsModule,  
  18.    AppRoutingModule  
  19.    ],  
  20.    providers: [CartListService],  
  21.    bootstrap: [AppComponent]  
  22. })  
  23. export class AppModule { }  
Now here comes the main picture we have been waiting for, click-> Run->Run As-> and select Angular web application, open the browser to view the output.
 
Using Eclipse Build A Simple Online Shopping Site With Angular IDE Plugin
 
Using Eclipse Build A Simple Online Shopping Site With Angular IDE Plugin
 
Now we can see the output of the project, we can select the product which we want to see the details about the project and the list page will display the details of the product which we have selected here. Now select the quantity of the product and click-> Add to cart.
 
Using Eclipse Build A Simple Online Shopping Site With Angular IDE Plugin

Using Eclipse Build A Simple Online Shopping Site With Angular IDE Plugin
 
So, after that, the page will be redirected to the cart page from the list page. The cart page will display the products which have been selected from the product list and calculation of the product cost will be increased/decreased depending upon the product quantity selection.
 
Using Eclipse Build A Simple Online Shopping Site With Angular IDE Plugin
 
Using Eclipse Build A Simple Online Shopping Site With Angular IDE Plugin
 
Using Eclipse Build A Simple Online Shopping Site With Angular IDE Plugin
 
Using Eclipse Build A Simple Online Shopping Site With Angular IDE Plugin
 
Also, we can  delete the product from the cart, if  we don’t need the product. so, that the cost of other products which have been selected will be displayed alone. So, that’s it. We have explored creating a simple online shopping site using Angular with Eclipse. I hope this article will be useful for you if you have any queries kindly comment below.