Alokai

getAvailableCustomerShippingMethods

Fetch available shipping methods for current customer. Customer must be logged in.

Signature

declare function getAvailableCustomerShippingMethods(
	context: Context,
	customQuery?: CustomQuery,
	customHeaders?: CustomHeaders
): Promise<ApolloQueryResult<CustomerCartQuery>>;

Parameters

NameRequiredTypeDescription
contextRequiredContext
customQueryOptionalCustomQuery
customHeadersOptionalCustomHeaders

Referenced Types

Examples

Simple usage:

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

// fetch available shipping methods for current customer
const result = await sdk.magento.getAvailableCustomerShippingMethods();
// e.g. output:
// {
//   "data": {
//     "customerCart": {
//       "shipping_addresses": [
//         address1: {
//          "available_shipping_methods": [...]
//         },
//       ]
//     }

Creating a custom GraphQL query

module.exports = {
  integrations: {
    magento: {
      customQueries: {
        'get-available-customer-shipping-methods-custom-query': ({ variables, metadata }) => ({
           variables,
           query: `
             query CustomerAvailableShippingMethods {
               customerCart {
                 ${metadata?.fields}
               }
             }
           `
        }),
      },
    }
  }
};

Using a custom GraphQL query to reduce the amount of data returned by the API

import { sdk } from '~/sdk.config.ts';
// reduce the amount of fields returned by the query, when compared to the default query

const customQuery = {
 getAvailableCustomerShippingMethods: 'get-available-customer-shipping-methods-custom-query',
 metadata: {
   fields: 'shipping_addresses { available_shipping_methods { available method_title } }'
 }
};

const result = await sdk.magento.getAvailableCustomerShippingMethods(customQuery);

// the result will contain only the data defined in the custom query

On this page