diff --git a/Frontend/src/app/components/hot-deals-widget/hot-deals-widget.component.html b/Frontend/src/app/components/hot-deals-widget/hot-deals-widget.component.html index a77fc6f..7def010 100644 --- a/Frontend/src/app/components/hot-deals-widget/hot-deals-widget.component.html +++ b/Frontend/src/app/components/hot-deals-widget/hot-deals-widget.component.html @@ -9,18 +9,18 @@
-
+
-
+
-
{{product.name}}
+
{{productsPricesMap[productId]?.product.name}}
-
Amazon: {{product.price}}$
+
Amazon: {{productsPricesMap[productId]?.amazonPrice.price_in_cents}}$
-
Plantshub: 599,00$
+
Plantshub: {{productsPricesMap[productId]?.lowestPrice.price_in_cents}}
diff --git a/Frontend/src/app/components/hot-deals-widget/hot-deals-widget.component.ts b/Frontend/src/app/components/hot-deals-widget/hot-deals-widget.component.ts index 3f5d6d4..688a951 100644 --- a/Frontend/src/app/components/hot-deals-widget/hot-deals-widget.component.ts +++ b/Frontend/src/app/components/hot-deals-widget/hot-deals-widget.component.ts @@ -12,6 +12,8 @@ export class HotDealsWidgetComponent implements OnInit { products: Product[] = []; bestDealsProductIds = []; + amazonPrices = []; + productsPricesMap: any = {}; @Input() numberOfProducts: number; @Input() showProductPicture: boolean; @Input() searchQuery: string; @@ -26,7 +28,6 @@ export class HotDealsWidgetComponent implements OnInit { ngOnInit(): void { - this.loadParams(); this.getBestDeals(); } @@ -46,11 +47,11 @@ export class HotDealsWidgetComponent implements OnInit { switch (this.type) { case 'search': { - this.getSearchedProducts(); break; } default: { this.getProductsByIds(); + this.getAmazonPricesForBestDeals(); break; } } @@ -58,27 +59,47 @@ export class HotDealsWidgetComponent implements OnInit { getProductsByIds(): void { this.apiService.getProductsByIds(this.bestDealsProductIds).subscribe( - products => this.products = products + products => { + products.forEach(product => { + this.productsPricesMap [product.product_id].product = product; + }); + } ); } - getBestDeals(): void { this.apiService.getBestDeals(9).subscribe( deals => { deals.forEach(deal => { this.bestDealsProductIds.push(deal.product_id); + this.productsPricesMap [deal.product_id] = {lowestPrice: deal} }); + this.loadParams(); } ); } + + + getAmazonPricesForBestDeals(): void{ + this.bestDealsProductIds.forEach(id => { + this.apiService.getAmazonPrice(id).subscribe( + price => { + this.amazonPrices.push(price); + this.productsPricesMap[price.product_id].amazonPrice = price; + } + ); + } + ); + console.log(this.amazonPrices); + } + getSearchedProducts(): void { this.apiService.getProductsByQuery(this.searchQuery).subscribe(products => this.products = products); } - clickedProduct(product: Product): void { - this.router.navigate([('/product/' + product.product_id)]); + clickedProduct(productId: string): void { + this.router.navigate([('/product/' + productId)]); } diff --git a/Frontend/src/app/components/top-bar/top-bar.component.html b/Frontend/src/app/components/top-bar/top-bar.component.html index b8b6697..6a41f7d 100644 --- a/Frontend/src/app/components/top-bar/top-bar.component.html +++ b/Frontend/src/app/components/top-bar/top-bar.component.html @@ -15,6 +15,7 @@ +