Using E-commerce Custom Types with Custom Component Inputs
The following video shows using a custom component—being dragged in from the left—along with a plugin to feature an image of a shirt in the collection grid.
When you use e-commerce plugin custom types with component inputs, your teammates can use these custom fields to select products, collections, and other e-commerce platform resources from a searchable list. Your component receives the selected resource's handle as a prop, which you can use to fetch and consume data from your e-commerce platform.
Use cases for this technique could include:
- Displaying a selected product's details
- Displaying a selected product collection
- Combining data from a selected product with data fetched from external platforms to display shipping times, pricing histories, and other information.
Providing a searchable list for selecting e-commerce platform resources reduces the risk of data entry errors when compared to requiring users to manually enter handles or resource IDs and offers better UX when using your components.
To get the most out of this document, you should be familiar with the following:
Step 1: Setting up the code
ProductCollection React component in the example below displays the titles of a product collection's products from a Shopify store.
The component has a string prop called
collection that corresponds to the collection's handle. The component fetches the collection's data from Shopify using a function called
getCollection() and stores the collection's products in its local state. Finally, it renders each product's title.
Next, register the component using
Builder.registerComponent(), which makes the component available for use in the Visual Editor. This example has one input,
collection, with the type
ShopifyCollectionHandle is a custom type available in the Shopify e-commerce plugin that represents the handle of a Shopify collection. The exact types that you use when registering your components depend on your application and the e-commerce platform with which you're integrating.
Tip: We suggest that you use request object, handle, or list types depending on your use case.
Request object types are versatile: they provide you with an
id, which you can use to fetch resource data from your e-commerce platform.
includeRefs: true to
builder.get(), when the query API sends content, it fetches any data you specify, as in this example on GitHub. The Visual Editor also fetches remote requests while editing when you pass
options=undefined to BuilderComponent, as in this example on GitHub.
Handle and list types are convenient when you need to consume a resource's handle—for example, while constructing a product page URL—or multiple resources at once.
For more information, see E-commerce Custom Types.
Step 2: In the Visual Editor
This section builds upon the example snippets above. Your e-commerce plugin options and custom component inputs might differ, but the process follows the same pattern.
- Add a
ProductCollectionblock to your Page or Section in Builder.
- Set the collection by selecting Choose collection in the Options tab. This loads a searchable list with all the collections from your Shopify store available.
- Choosing a collection sets your
ProductCollectionblock's collection field.
Need Expert help?
Reach out to us, and we will match you with a Builder expert.