Alokai

setShippingMethodsOnCart

Set shipping methods on cart.

Signature

declare function setShippingMethodsOnCart(
	context: Context,
	input: SetShippingMethodsOnCartInput,
	customQuery?: CustomQuery,
	customHeaders?: CustomHeaders
): Promise<FetchResult<SetShippingMethodsOnCartMutation>>;

Parameters

NameRequiredTypeDescription
contextRequiredContext
inputRequiredSetShippingMethodsOnCartInput
customQueryOptionalCustomQuery
customHeadersOptionalCustomHeaders

Referenced Types

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.

On this page