setBillingAddressOnCart
Set billing address on cart.
Signature
declare function setBillingAddressOnCart(
context: Context,
input: SetBillingAddressOnCartInput,
customQuery?: CustomQuery,
customHeaders?: CustomHeaders
): Promise<FetchResult<SetBillingAddressOnCartMutation>>;Parameters
| Name | Required | Type | Description |
|---|---|---|---|
context | Required | Context | |
input | Required | SetBillingAddressOnCartInput | |
customQuery | Optional | CustomQuery | |
customHeaders | Optional | CustomHeaders |
Referenced Types
- Context
- SetBillingAddressOnCartInput
- CustomQuery
- CustomHeaders
FetchResultSetBillingAddressOnCartMutation
Examples
Simple usage:
import { sdk } from '~/sdk.config.ts';
// set billing address on cart
const result = await sdk.magento.setBillingAddressOnCart({
cart_id: 'some-cart-id',
billing_address: {
address: {
firstname: 'John',
lastname: 'Doe',
street: ['123 Main St'],
city: 'New York',
postcode: '10001',
country_code: 'US'
}
}
});Creating a custom GraphQL query for setting billing address on cart
module.exports = {
integrations: {
magento: {
customQueries: {
'set-billing-address-on-cart-custom-query': ({ variables, metadata }) => ({
variables,
query: `
mutation setBillingAddressOnCart($input: SetBillingAddressOnCartInput) {
setBillingAddressOnCart(input: $input) {
cart {
${metadata.fields}
}
}
}`
}),
},
}
}
};Using a custom GraphQL query to set billing address 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 = {
setBillingAddressOnCart: 'set-billing-address-on-cart-custom-query',
metadata: {
fields: 'id billing_address { firstname lastname }'
}
};
const result = await sdk.magento.setBillingAddressOnCart({
cart_id: 'some-cart-id',
billing_address: {
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.