setShippingMethodsOnCart
Set shipping methods on cart.
Signature
declare function setShippingMethodsOnCart(
context: Context,
input: SetShippingMethodsOnCartInput,
customQuery?: CustomQuery,
customHeaders?: CustomHeaders
): Promise<FetchResult<SetShippingMethodsOnCartMutation>>;Parameters
| Name | Required | Type | Description |
|---|---|---|---|
context | Required | Context | |
input | Required | SetShippingMethodsOnCartInput | |
customQuery | Optional | CustomQuery | |
customHeaders | Optional | CustomHeaders |
Referenced Types
- Context
- SetShippingMethodsOnCartInput
- CustomQuery
- CustomHeaders
FetchResultSetShippingMethodsOnCartMutation
Examples
Simple usage:
import { sdk } from '~/sdk.config.ts';
// assign the shipping method to given cart
const setShippingMethodResult = await sdk.magento.setShippingMethodsOnCart({
cart_id: 'some-cart-id',
shipping_methods: [{
carrier_code: 'flatrate',
method_code: 'flatrate'
}]
});Creating a custom GraphQL query for setting shipping methods on cart
module.exports = {
integrations: {
magento: {
customQueries: {
'set-shipping-methods-on-cart-custom-query': ({ variables, metadata }) => ({
variables,
query: `
mutation setShippingMethodsOnCart($input: SetShippingMethodsOnCartInput) {
setShippingMethodsOnCart(input: $input) {
cart {
${metadata.fields}
}
}
}`
}),
},
}
}
};Using a custom GraphQL query to set shipping methods 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 = {
setShippingMethodsOnCart: 'set-shipping-methods-on-cart-custom-query',
metadata: {
fields: 'id email'
}
};
const setShippingMethodResult = await sdk.magento.setShippingMethodsOnCart({
cart_id: 'some-cart-id',
shipping_methods: [{
carrier_code: 'flatrate',
method_code: 'flatrate'
}]
}, customQuery);
// result will contain only the fields specified in the custom query.