Alokai

addMultipleToMyShoppingList

Add multiple products to the Shopping List.

By default, it uses the addMultipleToMyShoppingListDefaultQuery GraphQL query

Signature

declare function addMultipleToMyShoppingList(
	context: CommercetoolsIntegrationContext,
	params: AddMultipleToMyShoppingListParams,
	customQuery?: CustomQuery
): Promise<AddMultipleToMyShoppingListResponse>;

Parameters

NameRequiredTypeDescription
contextRequiredCommercetoolsIntegrationContext
paramsRequiredAddMultipleToMyShoppingListParams
customQueryOptionalCustomQuery

Referenced Types

Examples

Adding a product to the Shopping List:

const MY_SHOPPING_LIST_PARAMS = {
  products: [
   { sku: 'test-sku' }
  ],
  id: 'test-id',
  version: 'test-version'
};

const { wishlist } = await sdk.commerce.addMultipleToMyShoppingList(MY_SHOPPING_LIST_PARAMS);

Or you can add multiple products to the Shopping List:

const MY_SHOPPING_LIST_PARAMS = {
  products: [
   { sku: 'test-sku-1' },
   { sku: 'test-sku-2' },
   ...and so on
  ],
  id: 'test-id',
  version: 'test-version'
};

const { wishlist } = await sdk.commerce.addMultipleToMyShoppingList(MY_SHOPPING_LIST_PARAMS);

Creating a custom GraphQL query for the method in middleware.config.ts:

export const integrations = {
    ct: {
      // ...
      customQueries: {
        'add-to-my-shopping-list-custom-query': ({ variables, metadata }) => {
           return {
             variables,
             query: `
               mutation updateShoppingList($id: String!, $version: Long!, $actions: [MyShoppingListUpdateAction!]!, $acceptLanguage: [Locale!]) {
                 wishlist: updateMyShoppingList(id: $id, version: $version, actions: $actions) {
                 ${metadata}
                 lineItems {
                   id
                   quantity
                   name(acceptLanguage: $acceptLanguage)
                   productSlug(acceptLanguage: $acceptLanguage)
                 }
               }
             }`
           };
         }
       }
     }
   }
};

Adding a product to the Shopping List and selecting response fields using the custom GraphQL query from the previous example.

const customQuery = {
  updateShoppingList: 'add-to-my-shopping-list-custom-query',
  metadata: 'id version lineItems { id quantity }'
};

const { wishlist } = await sdk.commerce.addMultipleToMyShoppingList({
  products: [
    { sku: TEST_PRODUCT_SKU }
  ],
  id: 'test-id',
  version: 'test-version'
}, customQuery);

On this page