Transform To Shopify Structure Usage
Configuration
transformToShopifyStructure
Function
The transformToShopifyStructure
function converts the ServerProduct[] array into a structure compatible with Shopify’s requirements. This is useful for transforming Fast Simon product data into a format that can be used directly within Shopify’s ecosystem.
Parameter
- ServerProduct[]
The function expects an array of
ServerProduct
objects.
Return Object
The function returns a list of products in a format compatible with Shopify's product structure, enabling smooth integration into Shopify themes or apps.
Usage Example
const collection = await fastSimon.getSmartCollection({
props: {
categoryURL: '/collections/' + handle,
page,
narrow,
facetsRequired: true,
productsPerPage: 20,
categoryID: undefined,
sortBy,
},
});
if (!collection) {
throw new Response(`Collection ${handle} not found`, {
status: 404,
});
}
const transformed = transformToShopifyStructure(collection.items);
Explanation
1. Fetching the Smart Collection:
The getSmartCollection
function fetches a collection from Fast Simon based on the provided parameters like categoryURL
, page
, and sortBy
.
2. Collection Validation:
A check is performed to ensure that the collection exists. If not, an error is thrown with a 404 status.
3. Transforming Data:
The transformToShopifyStructure
function is called with the collection items. This transforms the raw data into the Shopify product structure, making it ready for integration into Shopify.