Alokai
You are reading the documentation for SDK v2, which is no longer the latest version. Switch to current

addToMyShoppingList

Method for adding a product to the Shopping List.

This method communicates with the addToMyShoppingList addToMyShoppingList endpoint. and adds a product to the Shopping List.

Signature

export declare function addToMyShoppingList<Res extends PartialAddToMyShoppingListResponse = AddToMyShoppingListResponse>(
	params: AddToMyShoppingListParams,
	options?: MethodOptions<CustomQuery<"updateShoppingList">>
): Promise<Res>;

Parameters

NameRequiredTypeDescription
paramsRequiredAddToMyShoppingListParamsParameter object which can be used with this method. Refer to its type definition to learn about possible properties.
optionsOptionalMethodOptions<CustomQuery<"updateShoppingList">>Options that can be passed to additionally configure the request or customize the logic in a plugin.

Returns

Returns a representation of the AddToMyShoppingListResponse.

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.addToMyShoppingList(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.addToMyShoppingList(MY_SHOPPING_LIST_PARAMS);

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

module.exports = {
  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.

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

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

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

On this page