updateMyCartItemByKey method

Future<WooCartItem> updateMyCartItemByKey({
  1. required String key,
  2. required int id,
  3. required int quantity,
  4. List<WooProductVariation>? variations,
})

Implementation

Future<WooCartItem> updateMyCartItemByKey(
    {required String key,
    required int id,
    required int quantity,
    List<WooProductVariation>? variations}) async {
  Map<String, dynamic> data = {
    'key': key,
    'id': id.toString(),
    'quantity': quantity.toString(),
  };
  if (variations != null) data['variations'] = variations;
  await getAuthTokenFromDb();
  _urlHeader['Authorization'] = 'Bearer ' + _authToken!;
  final response = await http.put(
      Uri.parse(this.baseUrl + URL_STORE_API_PATH + 'cart/items/' + key),
      headers: _urlHeader,
      body: data);

  if (response.statusCode >= 200 && response.statusCode < 300) {
    final jsonStr = json.decode(response.body);

    _printToLog('added to my cart : ' + jsonStr.toString());
    return WooCartItem.fromJson(jsonStr);
  } else {
    WooCommerceError err =
        WooCommerceError.fromJson(json.decode(response.body));
    throw err;
  }
}