field-shopify

Pre-built external fields for selecting Shopify products and collections via the Storefront API.

npm i @reacteditor/field-shopify --save

createFieldShopifyProduct

Returns an external field that lists products from a Shopify store.

import { createFieldShopifyProduct } from "@reacteditor/field-shopify";
 
const config = {
  components: {
    ProductCard: {
      fields: {
        product: createFieldShopifyProduct({
          storeDomain: "my-store.myshopify.com",
          storefrontAccessToken: process.env.SHOPIFY_STOREFRONT_TOKEN!,
        }),
      },
      render: ({ product }) => <h2>{product?.title}</h2>,
    },
  },
};

Options

ParamExampleDescription
storeDomain"my-store.myshopify.com"Shopify store domain. Required unless client is supplied.
storefrontAccessTokenprocess.env.SHOPIFY_TOKENStorefront API access token. Required unless client is supplied.
apiVersion"2024-10"Storefront API version.
clientclient: createStorefrontApiClient(...)Pre-built @shopify/storefront-api-client.
firstfirst: 50Number of products to fetch per page. Defaults to 20.
titleField"title"Field key used for the row title and item summary. Defaults to "title".
filterFieldsfilterFields: { vendor: { type: "text" } }Filter UI for the picker.
initialFilters{ vendor: "Acme" }Initial filter values.

createFieldShopifyCollection

Same shape as createFieldShopifyProduct, but lists Shopify collections.

import { createFieldShopifyCollection } from "@reacteditor/field-shopify";
 
const collection = createFieldShopifyCollection({
  storeDomain: "my-store.myshopify.com",
  storefrontAccessToken: process.env.SHOPIFY_STOREFRONT_TOKEN!,
});