Added the ability to have mutliple buy options for product
This commit is contained in:
parent
538c585cc1
commit
d94df9f206
@ -6,8 +6,9 @@ import { MatDialog } from '@angular/material';
|
|||||||
import { LoginComponent } from './login/login.component';
|
import { LoginComponent } from './login/login.component';
|
||||||
import { LocalStorage } from 'webstorage-decorators';
|
import { LocalStorage } from 'webstorage-decorators';
|
||||||
import { AppStore } from './app.store';
|
import { AppStore } from './app.store';
|
||||||
import { AngularFireAuth } from '../../node_modules/angularfire2/auth';
|
import { AngularFireAuth } from 'angularfire2/auth';
|
||||||
import { SwUpdate } from '../../node_modules/@angular/service-worker';
|
import { SwUpdate } from '@angular/service-worker';
|
||||||
|
import { POption } from './store/products/product';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-root',
|
selector: 'app-root',
|
||||||
@ -15,7 +16,7 @@ import { SwUpdate } from '../../node_modules/@angular/service-worker';
|
|||||||
})
|
})
|
||||||
export class AppComponent implements OnInit {
|
export class AppComponent implements OnInit {
|
||||||
@LocalStorage({ defaultValue: [], encryptionKey: 'HmRoBFUEVWqW5uvy' })
|
@LocalStorage({ defaultValue: [], encryptionKey: 'HmRoBFUEVWqW5uvy' })
|
||||||
cart: { id: string; item: string; price: number; currency: 'CAD' | 'USD'; quantity: number }[];
|
cart: { id: string; item: string; option: POption, quantity: number}[];
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private router: Router,
|
private router: Router,
|
||||||
@ -30,8 +31,8 @@ export class AppComponent implements OnInit {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
cartAdd(id: string, item: string, price: number, currency: 'CAD' | 'USD', quantity: number) {
|
cartAdd(id: string, name: string, option: POption, quantity: number) {
|
||||||
this.cart = [{ id: id, item: item, price: Number(price), currency: currency, quantity: Number(quantity) }].concat(
|
this.cart = [{ id: id, item: name, option: option, quantity: Number(quantity)}].concat(
|
||||||
this.cart
|
this.cart
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -76,9 +76,8 @@ export class AppStore {
|
|||||||
temp.originalImage = temp.image;
|
temp.originalImage = temp.image;
|
||||||
temp.image = this.domSanitizer.bypassSecurityTrustUrl(temp.image);
|
temp.image = this.domSanitizer.bypassSecurityTrustUrl(temp.image);
|
||||||
temp.originalDescription = temp.description;
|
temp.originalDescription = temp.description;
|
||||||
temp.description = this.domSanitizer.bypassSecurityTrustHtml(
|
temp.description = this.domSanitizer.bypassSecurityTrustHtml(temp.description);
|
||||||
temp.description.replace(/(\r\n|\r|\n)/g, '<br>')
|
|
||||||
);
|
|
||||||
return <Product>temp;
|
return <Product>temp;
|
||||||
})
|
})
|
||||||
),
|
),
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { Component, Inject } from '@angular/core';
|
import { Component, Inject } from '@angular/core';
|
||||||
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
|
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
|
||||||
import { AngularFirestore } from 'angularfire2/firestore';
|
import { AngularFirestore } from 'angularfire2/firestore';
|
||||||
import {LocalStorage} from '../../../../node_modules/webstorage-decorators';
|
import { LocalStorage } from 'webstorage-decorators';
|
||||||
import { AppStore } from '../../app.store';
|
import { AppStore } from '../../app.store';
|
||||||
import { ConvertToGPipe } from '../units.pipe';
|
import { ConvertToGPipe } from '../units.pipe';
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ export class CartComponent {
|
|||||||
constructor(public app: AppComponent) {}
|
constructor(public app: AppComponent) {}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
|
console.log(this.app.cart);
|
||||||
if (this.app.cartCount()) {
|
if (this.app.cartCount()) {
|
||||||
window['paypal'].Button.render(
|
window['paypal'].Button.render(
|
||||||
{
|
{
|
||||||
|
@ -13,20 +13,52 @@
|
|||||||
<mat-form-field class="w-100">
|
<mat-form-field class="w-100">
|
||||||
<textarea matInput rows="5" placeholder="Description" name="description" [(ngModel)]="description"></textarea>
|
<textarea matInput rows="5" placeholder="Description" name="description" [(ngModel)]="description"></textarea>
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
|
<div class="mt-3 p-3 border rounded border-muted">
|
||||||
|
<h5 mat-subheader class="mb-4 pl-0">Buying Options</h5>
|
||||||
|
<button mat-stroked-button class="mb-4" color="accent" (click)="addOption()">Add</button>
|
||||||
|
<mat-accordion>
|
||||||
|
<mat-expansion-panel *ngFor="let o of options; let i = index">
|
||||||
|
<mat-expansion-panel-header>
|
||||||
|
<mat-panel-title>
|
||||||
|
{{o.name || 'Option'}}
|
||||||
|
</mat-panel-title>
|
||||||
|
<mat-panel-description>
|
||||||
|
{{o.currency}} {{o.price | currency}}
|
||||||
|
</mat-panel-description>
|
||||||
|
</mat-expansion-panel-header>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-4">
|
||||||
|
<mat-form-field>
|
||||||
|
<input matInput placeholder="Name" [(ngModel)]="o.name">
|
||||||
|
</mat-form-field>
|
||||||
|
</div>
|
||||||
|
<div class="col-4 text-center">
|
||||||
<mat-form-field>
|
<mat-form-field>
|
||||||
<span matPrefix>$ </span>
|
<span matPrefix>$ </span>
|
||||||
<input matInput placeholder="Price" type="number" name="price" [(ngModel)]="price">
|
<input matInput placeholder="Price" type="number" name="price" [(ngModel)]="o.price">
|
||||||
<mat-hint *ngIf="!price" align="start">0 will display "Contact For Price"</mat-hint>
|
<mat-hint *ngIf="!price" align="start">0 will display "Contact For Price"</mat-hint>
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
<mat-radio-group [(ngModel)]="currency" name="currency">
|
<mat-radio-group [(ngModel)]="o.currency" name="currency">
|
||||||
<mat-radio-button value="CAD" class="pl-3">CAD</mat-radio-button>
|
<mat-radio-button value="CAD" class="pl-3">CAD</mat-radio-button>
|
||||||
<mat-radio-button value="USD" class="pl-3">USD</mat-radio-button>
|
<mat-radio-button value="USD" class="pl-3">USD</mat-radio-button>
|
||||||
</mat-radio-group>
|
</mat-radio-group>
|
||||||
<input #fileInput type="file" (change)="imageChanged($event)" hidden>
|
</div>
|
||||||
|
<div class="col-4">
|
||||||
<mat-form-field class="float-right" style="width: 150px">
|
<mat-form-field class="float-right" style="width: 150px">
|
||||||
<input matInput type="number" placeholder="Weight For Shipping" [(ngModel)]="weight">
|
<input matInput type="number" placeholder="Weight For Shipping" [(ngModel)]="o.weight">
|
||||||
<span matSuffix>lb</span>
|
<span matSuffix>lb</span>
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<input #fileInput type="file" (change)="imageChanged($event)" hidden>
|
||||||
|
<mat-action-row>
|
||||||
|
<button mat-button color="warn" (click)="options.splice(i, 1)">
|
||||||
|
Delete
|
||||||
|
</button>
|
||||||
|
</mat-action-row>
|
||||||
|
</mat-expansion-panel>
|
||||||
|
</mat-accordion>
|
||||||
|
</div>
|
||||||
<div class="mt-3 p-3 border rounded border-muted">
|
<div class="mt-3 p-3 border rounded border-muted">
|
||||||
<h5 mat-subheader class="pl-0">Uploads</h5>
|
<h5 mat-subheader class="pl-0">Uploads</h5>
|
||||||
<mat-progress-bar *ngIf="uploading" mode="indeterminate"></mat-progress-bar>
|
<mat-progress-bar *ngIf="uploading" mode="indeterminate"></mat-progress-bar>
|
||||||
|
@ -2,7 +2,7 @@ import {Component, Inject} from '@angular/core';
|
|||||||
import { AngularFirestore } from 'angularfire2/firestore';
|
import { AngularFirestore } from 'angularfire2/firestore';
|
||||||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material';
|
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material';
|
||||||
import { AppStore } from '../../app.store';
|
import { AppStore } from '../../app.store';
|
||||||
import {AngularFireStorage} from '../../../../node_modules/angularfire2/storage';
|
import { AngularFireStorage } from 'angularfire2/storage';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'new-item',
|
selector: 'new-item',
|
||||||
@ -10,14 +10,12 @@ import {AngularFireStorage} from '../../../../node_modules/angularfire2/storage'
|
|||||||
})
|
})
|
||||||
export class NewProductComponent {
|
export class NewProductComponent {
|
||||||
category;
|
category;
|
||||||
currency = 'CAD';
|
|
||||||
description: string;
|
description: string;
|
||||||
files: { name: string; link: string; type: string }[] = [];
|
files: { name: string; link: string; type: string }[] = [];
|
||||||
image: string;
|
image: string;
|
||||||
linkError = false;
|
linkError = false;
|
||||||
name: string;
|
name: string;
|
||||||
price: number = 0.0;
|
options: { name: string, price: number, currency: 'CAD' | 'USD', weight: number }[] = [];
|
||||||
weight: number = 0;
|
|
||||||
uploading = false;
|
uploading = false;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@ -31,12 +29,12 @@ export class NewProductComponent {
|
|||||||
|
|
||||||
if (data.product) {
|
if (data.product) {
|
||||||
this.category = data.product.category;
|
this.category = data.product.category;
|
||||||
this.currency = data.product.currency;
|
|
||||||
this.description = data.product.originalDescription;
|
this.description = data.product.originalDescription;
|
||||||
this.files = data.product.files;
|
this.files = data.product.files;
|
||||||
this.name = data.product.name;
|
this.name = data.product.name;
|
||||||
this.price = data.product.price;
|
this.options = data.product.options;
|
||||||
this.weight = data.product.weight;
|
} else {
|
||||||
|
this.addOption();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,6 +62,10 @@ export class NewProductComponent {
|
|||||||
return !!valid;
|
return !!valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addOption() {
|
||||||
|
this.options.push({ name: '', price: 0, currency: 'CAD', weight: 0 });
|
||||||
|
}
|
||||||
|
|
||||||
imageChanged(event) {
|
imageChanged(event) {
|
||||||
let reader = new FileReader();
|
let reader = new FileReader();
|
||||||
reader.readAsDataURL(event.target.files[0]);
|
reader.readAsDataURL(event.target.files[0]);
|
||||||
@ -73,12 +75,14 @@ export class NewProductComponent {
|
|||||||
submit() {
|
submit() {
|
||||||
let newProduct = {
|
let newProduct = {
|
||||||
category: this.category,
|
category: this.category,
|
||||||
currency: this.currency,
|
|
||||||
description: this.description,
|
description: this.description,
|
||||||
files: this.files,
|
files: this.files,
|
||||||
name: this.name,
|
name: this.name,
|
||||||
price: Number(this.price),
|
options: this.options.map(row => {
|
||||||
weight: Number(this.weight) || 0
|
row.price = <number>row.price;
|
||||||
|
row.weight = <number>row.weight;
|
||||||
|
return row;
|
||||||
|
})
|
||||||
};
|
};
|
||||||
if (this.image) newProduct['image'] = this.image;
|
if (this.image) newProduct['image'] = this.image;
|
||||||
|
|
||||||
|
25
src/app/store/products/product.ts
Normal file
25
src/app/store/products/product.ts
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import { SafeUrl, SafeHtml } from "@angular/platform-browser";
|
||||||
|
|
||||||
|
export interface PFile {
|
||||||
|
link: string;
|
||||||
|
name: string;
|
||||||
|
type: 'link' | 'other' | 'preview';
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface POption {
|
||||||
|
currency: 'CAD' | 'USD';
|
||||||
|
name: string;
|
||||||
|
price: number;
|
||||||
|
weight: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Product {
|
||||||
|
category: string;
|
||||||
|
description: string | SafeHtml;
|
||||||
|
files: any[]
|
||||||
|
image: string | SafeUrl;
|
||||||
|
name: string;
|
||||||
|
options: POption[];
|
||||||
|
originalDescription: string;
|
||||||
|
originalImage: string;
|
||||||
|
}
|
@ -16,18 +16,26 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="col-12 col-md-9">
|
<div class="col-12 col-md-9">
|
||||||
<h2 class="roboto">{{product.name}}</h2>
|
<h2 class="roboto">{{product.name}}</h2>
|
||||||
<h5 *ngIf="product.price" class="text-muted">{{product.currency}} {{product.price | currency}}</h5>
|
<mat-form-field *ngIf="product.options.length > 1">
|
||||||
<h5 *ngIf="!product.price" class="text-muted">Contact For Price</h5>
|
<mat-select placeholder="Buying Options" [(ngModel)]="option">
|
||||||
<mat-divider class="my-3"></mat-divider>
|
<mat-option *ngFor="let o of product.options" [value]="o">
|
||||||
<p style="overflow: hidden;" [innerHtml]="product.description"></p>
|
{{o.name}} <span class="float-right text-muted">{{o.currency}} {{o.price | currency}}</span>
|
||||||
<div class="float-right">
|
</mat-option>
|
||||||
|
</mat-select>
|
||||||
|
</mat-form-field>
|
||||||
|
<div class="d-inline ml-3">
|
||||||
<mat-form-field class="mr-1" style="width: 40px">
|
<mat-form-field class="mr-1" style="width: 40px">
|
||||||
|
<span matPrefix>x</span>
|
||||||
<input #quantity matInput type="number" value="1" min="1">
|
<input #quantity matInput type="number" value="1" min="1">
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
<button mat-raised-button color="primary" [disabled]="quantity.value < 1" (click)="app.cartAdd(product.id, product.name, product.price, product.currency, quantity.value)">
|
<button mat-raised-button color="primary" [disabled]="quantity.value < 1" (click)="app.cartAdd(product.id, product.name, option, quantity.value)">
|
||||||
<mat-icon>add_shopping_cart</mat-icon> Buy
|
<mat-icon>add_shopping_cart</mat-icon> Buy
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
<h5 *ngIf="product.options.length == 1 && product.options[0].price > 0" class="text-muted">{{product.options[0].currency}} {{product.options[0].price | currency}}</h5>
|
||||||
|
<h5 *ngIf="product.options.length == 1 && product.options[0].price == 0" class="text-muted">Contact For Price</h5>
|
||||||
|
<mat-divider class="my-3"></mat-divider>
|
||||||
|
<p style="overflow: hidden;" [innerHtml]="product.description"></p>
|
||||||
<mat-divider class="my-3"></mat-divider>
|
<mat-divider class="my-3"></mat-divider>
|
||||||
<div *ngIf="attachments?.length">
|
<div *ngIf="attachments?.length">
|
||||||
<h5 class="ml-3">
|
<h5 class="ml-3">
|
||||||
|
@ -4,7 +4,7 @@ import {AppComponent} from '../../app.component';
|
|||||||
import { map } from 'rxjs/operators';
|
import { map } from 'rxjs/operators';
|
||||||
import { AppStore } from '../../app.store';
|
import { AppStore } from '../../app.store';
|
||||||
import { Product } from '../product';
|
import { Product } from '../product';
|
||||||
import {SafeUrl, DomSanitizer} from '../../../../node_modules/@angular/platform-browser';
|
import { SafeUrl, DomSanitizer } from '@angular/platform-browser';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'products',
|
selector: 'products',
|
||||||
@ -15,6 +15,7 @@ export class ProductsComponent {
|
|||||||
preview: SafeUrl[];
|
preview: SafeUrl[];
|
||||||
links: { name: string; link: string; type: string }[];
|
links: { name: string; link: string; type: string }[];
|
||||||
attachments: { name: string; link: string; type: string }[];
|
attachments: { name: string; link: string; type: string }[];
|
||||||
|
option;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private store: AppStore,
|
private store: AppStore,
|
||||||
|
Loading…
Reference in New Issue
Block a user