|
|
@ -4,6 +4,7 @@ import { ActivatedRoute } from "@angular/router"
|
|
|
|
import { HttpService } from 'src/app/services/http.service';
|
|
|
|
import { HttpService } from 'src/app/services/http.service';
|
|
|
|
import { CartService } from 'src/app/services/cart.service';
|
|
|
|
import { CartService } from 'src/app/services/cart.service';
|
|
|
|
import { FormControl } from '@angular/forms';
|
|
|
|
import { FormControl } from '@angular/forms';
|
|
|
|
|
|
|
|
import { MatSnackBar } from '@angular/material/snack-bar'
|
|
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
@Component({
|
|
|
|
selector: 'app-product-item-details',
|
|
|
|
selector: 'app-product-item-details',
|
|
|
@ -24,10 +25,13 @@ export class ProductItemDetailsComponent implements OnInit {
|
|
|
|
productId: number = 0
|
|
|
|
productId: number = 0
|
|
|
|
quantity: string = '1'
|
|
|
|
quantity: string = '1'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
snackBarDuration = 7;
|
|
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
constructor(
|
|
|
|
private httpService: HttpService,
|
|
|
|
private httpService: HttpService,
|
|
|
|
private route: ActivatedRoute,
|
|
|
|
private route: ActivatedRoute,
|
|
|
|
private cartService: CartService
|
|
|
|
private cartService: CartService,
|
|
|
|
|
|
|
|
private _snackBar: MatSnackBar
|
|
|
|
) { }
|
|
|
|
) { }
|
|
|
|
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
ngOnInit(): void {
|
|
|
@ -42,7 +46,13 @@ export class ProductItemDetailsComponent implements OnInit {
|
|
|
|
addToCart(product: Product) {
|
|
|
|
addToCart(product: Product) {
|
|
|
|
this.product.quantity = parseInt(this.quantity)
|
|
|
|
this.product.quantity = parseInt(this.quantity)
|
|
|
|
this.cartService.addToCart(product);
|
|
|
|
this.cartService.addToCart(product);
|
|
|
|
window.alert('Your product has been added to the cart!');
|
|
|
|
this.openSnackBar(product.name, product.quantity)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
openSnackBar(productName: string, productQuantity: number) {
|
|
|
|
|
|
|
|
this._snackBar.open( productName + " x" + productQuantity + " " + "added to cart", 'Close', {
|
|
|
|
|
|
|
|
duration: this.snackBarDuration * 100
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|