setCustomerCartShippingInformation method
Set shipping information for customer cart
Implementation
Future<Cart> setCustomerCartShippingInformation({
required Address address,
required String methodCode,
required String carrierCode,
}) async {
try {
final response = await _client.authenticatedRequest<Map<String, dynamic>>(
'/rest/V1/carts/mine/shipping-information',
options: Options(method: 'POST'),
data: {
'addressInformation': {
'shipping_address': address.toJson(),
'billing_address': address.toJson(),
'shipping_method_code': methodCode,
'shipping_carrier_code': carrierCode,
},
},
);
if (response.statusCode == 200) {
return Cart.fromJson(response.data!);
} else {
throw Exception(
'Failed to set customer cart shipping information: ${response.statusMessage}',
);
}
} on DioException catch (e) {
throw Exception(
'Failed to set customer cart shipping information: ${e.message}',
);
} catch (e) {
throw Exception('Failed to set customer cart shipping information: $e');
}
}