getMyCartItems method

Future<List<WooCartItem>> getMyCartItems()

Returns a list of all WooCartItem.

Related endpoint : wc/store/cart/items

Implementation

Future<List<WooCartItem>> getMyCartItems() async {
  await getAuthTokenFromDb();
  _urlHeader['Authorization'] = 'Bearer ' + _authToken!;
  final response = await http.get(
      Uri.parse(this.baseUrl + URL_STORE_API_PATH + 'cart/items'),
      headers: _urlHeader);

  if (response.statusCode >= 200 && response.statusCode < 300) {
    final jsonStr = json.decode(response.body);
    List<WooCartItem> cartItems = [];
    _printToLog('response gotten : ' + response.toString());
    for (var p in jsonStr) {
      var prod = WooCartItem.fromJson(p);
      _printToLog('prod gotten here : ' + prod.name.toString());
      cartItems.add(prod);
    }

    _printToLog('account user fetch : ' + jsonStr.toString());
    return cartItems;
  } else {
    _printToLog(' error : ' + response.body);
    WooCommerceError err =
        WooCommerceError.fromJson(json.decode(response.body));
    throw err;
  }
}