Take promotions to the next level with our new Rules Engine.

Behind the Docs

Use SKU Lists as Wishlists

January 14, 2025 Alex Canessa

At Commerce Layer we’re really proud of our documentation. It’s simple to understand, extensive, and saves loads of time. That's why I decided to start off a series of small blog posts: "Behind the Docs". In this series I intend to take pieces of our documentation and explain possible usage in real world scenarios.

Today I want to start from our Data Model, in particular the SKU Lists.

SKU List data model

SKU List Anatomy

Here’s what a SKU List can be connected to:

  • SKUs - the SKUs part of the list
  • Promotion Rules - conditions that apply to the list
  • Customer - "Why does a SKU List have a customer relationship?"

SKU List can be used in different ways and one of them is if you tie it to a Customer, what you’ve got is… a Wishlist.

No need for a separate resource. No need for a special name or plugin. You’re using what’s already there.

Let’s Build One with the CLI

Let’s say you want to create a wishlist for a user (me, actually - I’ve got my eyes on a Commerce Layer hat).

Rather than building the wishlist mechanism in a front-end application, today I want to show you the concept using our Commerce Layer CLI, and we’ll need the resources plugin, which you can install this way:

cl plugins:install resources

1. Create the SKU List

First, we want to create the actual list that will hold our SKUs.Think of it as a container for your wishlist items.

cl create sku_list -a name="Alex's Wishlist"
{
  id: 'JqjZIgXaZn',
  type: 'sku_lists',
  name: "Alex's wishlist",
  slug: 'alex-s-wishlist',
  description: null,
  image_url: null,
  manual: true,
  sku_code_regex: null,
  created_at: '2025-04-05T06:42:20.637Z',
  updated_at: '2025-04-05T06:42:20.637Z',
  reference: null,
  reference_origin: null,
  metadata: {}
}

2. Assign it to a Customer

Now we tie the list to a specific customer. This operation could be done when the user first adds the SKU to the favourites/wishlist.

We're using last to get the ID of the latest operation and customer_id with the ID of the user (from Commerce Layer) using the flag -r to update the relationship.

cl update sku_list/last -r customer={customer_id}
{
  id: 'JqjZIgXaZn',
  type: 'sku_lists',
  name: "Alex's Wishlist",
  slug: 'alex-s-wishlist',
  description: null,
  image_url: null,
  manual: true,
  sku_code_regex: null,
  created_at: '2025-04-05T15:29:39.130Z',
  updated_at: '2025-04-05T15:34:57.760Z',
  reference: null,
  reference_origin: null,
  metadata: {},
  customer: {
    id: 'nxqWhMveDY',
    type: 'customers',
    email: 'alex@commercelayer.io',
    status: 'prospect',
    has_password: false,
    total_orders_count: 0,
    shopper_reference: '1B545D53510259365D4BA9D3F66E2970B9102266',
    profile_id: '1B4DA567BC561EED03DC6BF7C695E9B81959A6A7',
    tax_exemption_code: null,
    created_at: '2025-04-05T15:29:57.692Z',
    updated_at: '2025-04-05T15:29:57.692Z',
    reference: null,
    reference_origin: null,
    metadata: {}
  }
}

3. Add items to the Wishlist

Finally we can add the SKU to the list, using the sku_list_items resource’s relationships and using last alias to get the id of the SKU List we just created ('JqjZIgXaZn') and the ID of the SKU we want to add.

cl create sku_list_items -r sku_list=last sku={sku_id}
{
  id: 'zqLZIPLrpW',
  type: 'sku_list_items',
  position: 1,
  sku_code: 'HATBLACKM',
  quantity: 1,
  created_at: '2025-04-05T15:41:44.429Z',
  updated_at: '2025-04-05T15:41:44.429Z',
  reference: null,
  reference_origin: null,
  metadata: {},
  sku_list: {
    id: 'JqjZIgXaZn',
    type: 'sku_lists',
    name: "Alex's Wishlist",
    slug: 'alex-s-wishlist',
    description: null,
    image_url: null,
    manual: true,
    sku_code_regex: null,
    created_at: '2025-04-05T15:29:39.130Z',
    updated_at: '2025-04-05T15:41:44.434Z',
    reference: null,
    reference_origin: null,
    metadata: {}
  },
  sku: {
    id: 'ZXxPSELwVo',
    type: 'skus',
    code: 'HATBLACKM',
    name: 'Hat Black Medium',
    description: 'Lorem ipsum dolor sit amet.',
    image_url: 'https://data.commercelayer.app/assets/images/old_skus/HATBSBMU000000FFFFFF.jpg',
    pieces_per_pack: null,
    weight: null,
    unit_of_weight: null,
    hs_tariff_number: '',
    do_not_ship: true,
    do_not_track: false,
    created_at: '2025-04-02T08:43:34.424Z',
    updated_at: '2025-04-02T08:43:34.424Z',
    reference: null,
    reference_origin: null,
    jwt_custom_claim: null,
    metadata: {}
  }
}
The SKU List we created using the CLI

That’s it. You’ve easily created a fully functional wishlist. It contains a specific product and it can be retrieved and updated

From Wishlist to Microstore

One interesting aspect of using the SKU List as a wishlist, is that you can turn it into a checkout experience using Commerce Layer’s Links and send to your customers their wishlist in a microstore.

cl create links -a name="Alex's Wishlist" scope="market:id:{market_id}" client_id="xxx-yyy-zzz" -r item="sku_lists/{sku_list_id}"

And now we can hit the generated link from the output and see our result on the browser

Generated Microstore for the wishlist.

Why this is cool

Using SKU List for wishlists means you get:

  • No extra modelling or workarounds
  • A clean, unified data model
  • Easy way to sell via CL Links

Want to know more?