addDeliveryAddresses method
Future<Cart>
addDeliveryAddresses({
- required String cartId,
- required List<
CartSelectableAddressInput> addresses, - bool reverse = false,
Adds delivery addresses to an existing cart.
Replaces passing deliveryAddressPreferences through
updateBuyerIdentityInCart, which Shopify deprecated. The added
addresses are available on Cart.delivery.
If the reverse is set to true, the line items in the cart will be in reverse order.
Implementation
Future<Cart> addDeliveryAddresses({
required String cartId,
required List<CartSelectableAddressInput> addresses,
bool reverse = false,
}) async {
final MutationOptions addAddresses = MutationOptions(
document: gql(cartDeliveryAddressesAddMutation),
variables: {
'cartId': cartId,
'addresses': addresses.map((e) => e.toJson()).toList(),
'reverse': reverse,
'country': ShopifyLocalization.countryCode,
},
);
QueryResult result = await _graphQLClient!.mutate(addAddresses);
checkForError(result,
key: 'cartDeliveryAddressesAdd', errorKey: 'userErrors');
return Cart.fromJson(
((result.data!['cartDeliveryAddressesAdd'] ?? const {})['cart'] ??
const {}));
}