We are developing an iOS app for a Magento website using Magento2 rest apis. App is fetching and showing all products added to the magneto website. But some of the products are not being added to the customer/guest cart as they are unavailable as of now.
In order to achieve this functionality we have added a new filter to show the products based on their stock and quantity's availability status. for this we have added "quantity_and_stock_status" filter to the products api, which is not working.
Here are the details of the api we have implemented for filtration of products:
func fetchItems(field:String?, value:String?) {
//Check for internet connection.
guard self.isNetworkAvailable() == true else {
return
}
self.showProgressHUD()
var productSearchAPI = API.host + "/rest/V1/products?"
if let fieldName = field, let fieldValue = value {
productSearchAPI += "searchCriteria[filter_groups][0][filters][0][field]=\(fieldName)"
productSearchAPI += "&searchCriteria[filter_groups][0][filters][0][value]=\(fieldValue)"
productSearchAPI += "&searchCriteria[filter_groups][0][filters][0][condition_type]=eq&"
}
productSearchAPI += "searchCriteria[filter_groups][0][filters][1][field]=status"
productSearchAPI += "&searchCriteria[filter_groups][0][filters][1][value]=1"
productSearchAPI += "&searchCriteria[filter_groups][0][filters][1][condition_type]=eq&"
/*productSearchAPI += "searchCriteria[filter_groups][0][filters][2][field]=quantity_and_stock_status"
productSearchAPI += "&searchCriteria[filter_groups][0][filters][2][value]=0"
productSearchAPI += "&searchCriteria[filter_groups][0][filters][2][condition_type]=gt&"*/
productSearchAPI += "searchCriteria[pageSize]=\(pageSize)"
productSearchAPI += "&searchCriteria[currentPage]=\(currentPage)"
Alamofire.request(productSearchAPI, method: .get, parameters: nil, encoding: URLEncoding.default, headers: ["Authorization":API.key]).responseJSON { response in
self.hideProgressHUD()
guard let JSON = response.result.value as? [String:AnyObject], let items = JSON["items"] as? [[String:AnyObject]], let pages = JSON["total_count"] as? Int else {
return
}
if self.currentPage == 1 {
self.items = items
} else {
self.items?.append(contentsOf: items)
}
self.totalPages = pages
self.collectionView.reloadData()
}
}
Can you please help us by pointing what is wrong with our product list filter's implementation?