Alokai

getAvailableShippingMethods

Fetch guest's available shipping methods

Signature

declare function getAvailableShippingMethods(
	context: Context,
	params: QueryCartArgs,
	customQuery?: CustomQuery,
	customHeaders?: CustomHeaders
): Promise<ApolloQueryResult<CartQuery>>;

Parameters

NameRequiredTypeDescription
contextRequiredContext
paramsRequiredQueryCartArgs
customQueryOptionalCustomQuery
customHeadersOptionalCustomHeaders

Referenced Types

Examples

Simple usage:

import { sdk } from '~/sdk.config.ts';

// fetch guest's available shipping methods
const result = await sdk.magento.getAvailableShippingMethods({
  cart_id: TEST_CART_ID
});
// array of available shipping methods for selected shipping address:
result.data.cart.shipping_addresses[0].available_shipping_methods[0];

Creating a custom GraphQL query for fetching only what's requested from shipping methods

module.exports = {
  integrations: {
    magento: {
      customQueries: {
        'get-available-shipping-methods-custom-query': ({ variables, metadata }) => ({
           variables,
           query: `
             query GuestAvailableShippingMethods($cart_id: String!) {
               cart(cart_id:$cart_id) {
                 shipping_addresses {
                   available_shipping_methods {
                     ${metadata.fields}
                   }
                 }
               }
             }
           `
        }),
      },
    }
  }
};

Using a custom GraphQL query to fetch only method_title field

import { sdk } from '~/sdk.config.ts';
// reduce the amount of fields returned by the query, when compared to the default query
const customQuery = {
  shippingMethods: 'get-available-shipping-methods-custom-query',
  metadata: {
    fields: 'method_title'
  }
};

const result = await sdk.magento.getAvailableShippingMethods({ cart_id: '123'}, customQuery);

// result contains the customer addresses with only the city method_title. Of course, it has same shape as in the "simple usage" example.

On this page