i Am building an app with woocommerce and i am stuck at one problem while fetching the products with json api.
Actually by default it returns only 10 products but i need more than 10 products at once.
getFilterdProducts() {
if (this.page == 1) { this.products = []; //this.loading.show(); this.loadingServerData = false;
}
let query = '&page=' + this.page;
if (this.sortOrder == "Newest") query = query + "&order=desc&orderby=date";
else if (this.sortOrder == "A - Z") query = query + "&order=asc&orderby=title";
else if (this.sortOrder == "Z - A") query = query + "&order=desc&orderby=title";
if (this.type == "featured" || this.filterFeatured) { query = query + "&featured=true"; this.filterFeatured = true; }
if (this.type == "sale" || this.type == "on_sale" || this.filterOnSale) { query = query + "&on_sale=true"; this.filterOnSale = true; }
if (this.price.lower != this.minAmount && this.applyFilter == true) query = query + "&min_price=" + this.price.lower;
if (this.price.upper != this.maxAmount && this.applyFilter == true) query = query + "&max_price=" + this.price.upper;
if (this.selectedTab != '') query = query + '&cat_id=' + this.selectedTab;
//query = query + '&page=' + this.page;
//query = query + this.queryAttributes;
console.log("custom Id = " + query);
//this.getAllAttributes();
this.http.get(this.config.url + '/api/appsettings/ionic_filter_products/?insecure=cool' + query).map(res => res.json()).subscribe(data => {
if (data.data)
this.listOfFilteredIdsFromCustom = data.data;
this.applicationRef.tick();
this.getFilterdProductsFromWoo();
});
}
getFilterdProductsFromWoo() {
if (this.listOfFilteredIdsFromCustom.length == 0) { this.infinite.enable(false); //this.loadingServerData = true; this.loading.hide();
return 0; }
let q = 'products?per_page=50&include=' + this.listOfFilteredIdsFromCustom + "&status=publish";
console.log(this.listOfFilteredIdsFromCustom);
if (this.sortOrder == "Newest") q = q + "&order=desc&orderby=date";
else if (this.sortOrder == "A - Z") q = q + "&order=asc&orderby=title";
else if (this.sortOrder == "Z - A") q = q + "&order=desc&orderby=title";
// if (this.type == "featured" || this.filterFeatured) { q = q + "&featured=true"; this.filterFeatured = true; }
// if (this.type == "sale" || this.type == "on_sale" || this.filterOnSale) { q = q + "&on_sale=true"; this.filterOnSale = true; }
console.log(q);
this.config.Woocommerce.getAsync(q + "&" + this.config.productsArguments).then((dat) => {
//this.loading.hide();
console.log('this products');
//console.log(dat.body);
let data = JSON.parse(dat.body);
this.infinite.complete();
if (this.page == 1) { this.products = new Array;this.infinite.enable(true); }
if (data.length != 0) {
this.page++;
for (let value of data) {
this.products.push(value);
}
//this.getFilterdProducts();
}
console.log('this is product data');
console.log(this.products);
if (data.length == 0 || data.length < 10) {
this.infinite.enable(false);
}
this.applicationRef.tick();
//this.loadingServerData = true;
});
}
help me guys!! thanks