WIP: problems with best deals.

This commit is contained in:
2021-06-16 09:59:57 +02:00
parent 8eba80f7d4
commit c88efc5484
5 changed files with 30 additions and 9 deletions
@@ -11,6 +11,7 @@ import {ActivatedRoute, Router} from '@angular/router';
export class HotDealsWidgetComponent implements OnInit {
products: Product[] = [];
bestDealsProductIds = [];
@Input() numberOfProducts: number;
@Input() showProductPicture: boolean;
@Input() searchQuery: string;
@@ -24,12 +25,14 @@ export class HotDealsWidgetComponent implements OnInit {
}
ngOnInit(): void {
this.loadParams();
this.getBestDeals();
}
loadParams(): void {
if (!this.numberOfProducts) {
this.numberOfProducts = 10;
this.numberOfProducts = 9;
}
if (!this.showProductPicture) {
this.showProductPicture = false;
@@ -47,14 +50,27 @@ export class HotDealsWidgetComponent implements OnInit {
break;
}
default: {
this.getProducts();
this.getProductsByIds();
break;
}
}
}
getProducts(): void {
this.apiService.getProducts().subscribe(products => this.products = products);
getProductsByIds(): void {
this.apiService.getProductsByIds(this.bestDealsProductIds).subscribe(
products => this.products = products
);
}
getBestDeals(): void {
this.apiService.getBestDeals(9).subscribe(
deals => {
deals.forEach(deal => {
this.bestDealsProductIds.push(deal.product_id);
});
}
);
}
getSearchedProducts(): void {