fetchProducts method

Future<ShopifyProduct?> fetchProducts({
  1. List<int>? ids,
  2. int limit = 50,
  3. int? sinceId,
  4. String? title,
  5. String? vendor,
  6. String? handle,
  7. String? productType,
  8. String status = 'active',
  9. int? collectionId,
  10. String? createdAtMin,
  11. String? createdAtMax,
  12. String? updatedAtMin,
  13. String? updatedAtMax,
  14. String? publishedAtMin,
  15. String? publishedAtMax,
  16. dynamic publishedStatus = 'any',
  17. List<String>? fields,
  18. List<String>? presentmentCurrencies,
  19. String? pageInfo,
})

Implementation

Future<ShopifyProduct?> fetchProducts(
    {List<int>? ids,
    int limit = 50,
    int? sinceId,
    String? title,
    String? vendor,
    String? handle,
    String? productType,
    String status = 'active', // active, archived, draft
    int? collectionId,
    String? createdAtMin,
    String? createdAtMax,
    String? updatedAtMin,
    String? updatedAtMax,
    String? publishedAtMin,
    String? publishedAtMax,
    publishedStatus = 'any', // any, published, unpublished
    List<String>? fields,
    List<String>? presentmentCurrencies,
    String? pageInfo}) async {
  Map query = {
    'ids': ids,
    'limit': limit,
    'since_id': sinceId,
    'title': title,
    'vendor': vendor,
    'handle': handle,
    'product_type': productType,
    'status': status,
    'collection_id': collectionId,
    'created_at_min': createdAtMin,
    'created_at_max': createdAtMax,
    'updated_at_min': updatedAtMin,
    'updated_at_max': updatedAtMax,
    'published_at_min': publishedAtMin,
    'published_at_max': publishedAtMax,
    'published_status': publishedStatus,
    'fields': fields,
    'presentment_currencies': presentmentCurrencies,
    'page_info': pageInfo
  };

  query.removeWhere((key, value) => value == null);

  try {
    Response response = await this.client.post("/products", data: query);
    return ShopifyProduct.fromJson(response.data);
  } on Exception catch (e) {
    logResponse(e.toString());
  }
  return null;
}