setShippingAddressesOnCart
Set shipping addresses on cart.
Signature
declare function setShippingAddressesOnCart(
context: Context,
input: SetShippingAddressesOnCartInput,
customQuery?: CustomQuery,
customHeaders?: CustomHeaders
): Promise<FetchResult<SetShippingAddressesOnCartMutation>>;Parameters
| Name | Required | Type | Description |
|---|---|---|---|
context | Required | Context | |
input | Required | SetShippingAddressesOnCartInput | |
customQuery | Optional | CustomQuery | |
customHeaders | Optional | CustomHeaders |
Referenced Types
- Context
- SetShippingAddressesOnCartInput
- CustomQuery
- CustomHeaders
FetchResultSetShippingAddressesOnCartMutation
Examples
Simple usage:
import { sdk } from '~/sdk.config.ts';
// set shipping address on cart
const result = await sdk.magento.setShippingAddressesOnCart({
cart_id: 'some-cart-id',
shipping_addresses: [{
address: {
firstname: 'John',
lastname: 'Doe',
street: ['123 Main St'],
city: 'New York',
postcode: '10001',
country_code: 'US'
}
}]
});Creating a custom GraphQL query for setting shipping addresses on cart
module.exports = {
integrations: {
magento: {
customQueries: {
'set-shipping-addresses-on-cart-custom-query': ({ variables, metadata }) => ({
variables,
query: `
mutation setShippingAddressesOnCart($input: SetShippingAddressesOnCartInput) {
setShippingAddressesOnCart(input: $input) {
cart {
${metadata.fields}
}
}
}`
}),
},
}
}
};Using a custom GraphQL query to set shipping addresses on cart
import { sdk } from '~/sdk.config.ts';
// reduce the amount of fields returned by the query, when compared to the default query
const customQuery = {
setShippingAddressesOnCart: 'set-shipping-addresses-on-cart-custom-query',
metadata: {
fields: 'id shipping_addresses { firstname lastname }'
}
};
const result = await sdk.magento.setShippingAddressesOnCart({
cart_id: 'some-cart-id',
shipping_addresses: [{
address: {
firstname: 'John',
lastname: 'Doe',
street: ['123 Main St'],
city: 'New York',
postcode: '10001',
country_code: 'US'
}
}]
}, customQuery);
// result will contain only the fields specified in the custom query.