Smart Collection
Creating Smart Collections allows you to generate dynamic collections that depend on conditions applied to fields (base and metafields) of each product.
- It is possible to define multiple conditions, linked together via
ANDorOR. - It is possible to set the condition relation type (default:
EQUAL) - For TAGs the EQUAL condition is handled by Shopify as a CONTAINS
- The primary key to identify a smart collection can be title or handle, based on the value configured in the specific header (see below)
- It is possible to associate an image with the collection (Note in update, if not provided and present on Shopify, the existing one will be maintained)
- It is possible to associate custom metafields with the collection, provided they have been defined as custom data on Shopify.
- It is possible to define multilingual translations for the title, description, handle fields and for metafields, to support multiple languages in collection display
- It is possible to publish on Shopify Online Store only, or on all sales channels provided for the shop.
Available keys for rules (key)
These keys represent the base Shopify fields usable in Smart Collection rules.
| Key | Description |
|---|---|
metafield | see example below (here) |
tag | Tags associated with the product |
title | Product title |
type | Product type |
compareAtPrice | Compare at price (used to indicate discounts) |
inventory | Quantity available in warehouse |
price | Product sale price |
variant_title | Variant title |
weight | Product weight |
vendor | Product supplier/brand |
Available operators (operator)
These operators determine the type of comparison applied between the key value and that indicated in the rule.
| Operator | Description |
|---|---|
EQUALS | Exactly equal value |
NOT_EQUALS | Different value |
GREATER_THAN | Greater than (only for numeric values) |
LESS_THAN | Less than (only for numeric values) |
CONTAINS | The value contains the indicated string |
NOT_CONTAINS | The value does not contain the indicated string |
STARTS_WITH | The value starts with the indicated string |
ENDS_WITH | The value ends with the indicated string |
IS_SET | The field is set |
IS_NOT_SET | The field is not set |
Conditions with Metafields
It is possible to use metafields as subjects of smart collections. These must already be configured on Shopify in the custom data section. To use them:
- Set the
keyfield with the metafield name - Specify
conditionTargetto indicate where the metafield is defined (on the product or on the variant)
ConditionTarget (only for metafield)
These targets are used to indicate where the metafield is located:
Target (conditionTarget) | Description |
|---|---|
PRODUCT | The metafield is associated with the product |
PRODUCTVARIANT | The metafield is associated with the variant |
Example
{
"rules": [
{
"conditionTarget": "PRODUCT",
"operator": "GREATER_THAN",
"key": "logistic_weight", // Metafield key
"value": "10"
},
{
"conditionTarget": "PRODUCTVARIANT",
"key": "subtitle", // Metafield key
"value": "subtitle value"
}
]
}
Translation Management
Smart Collections support the definition of multilingual translations for the main fields and for metafields. Translations are defined within a translations object, which contains the supported languages and the relative translated strings.
Translatable fields
title: collection titledescription: collection descriptionhandle: unique textual identifier used for the URLmetafields: specific translations for each metafield key
Example
{
"translations": {
"title": {
"it": "Smart Collection TAG Iphone 12",
"fr": "Collection intelligente TAG Iphone 12"
},
"description": {
"it": "Questa smart collection permette di raggruppare tutti i prodotti che hanno come tag Iphone12",
"fr": "Cette collection intelligente vous permet de regrouper tous les produits qui ont le tag Iphone12"
},
"handle": {
"it": "collezione-iphone-12",
"fr": "collection-iphone-12"
},
"metafields": {
"test": {
"it": "Metafield tradotto",
"fr": "Métachamp traduit"
},
"test_2": {
"it": "Metafield tradotto",
"fr": "Métachamp traduit"
}
}
}
}
Collection publication
In its standard behavior, a Smart Collection is published only on Shopify's Online Store.
If the shop provides multiple sales channels, it is possible to publish the collection on all sales channels.
This happens through the boolean field isPublishedOnAllChannels, which if set to the value true
allows publishing the collection on all channels, while if set to the value false, or if not set,
publishes only on Shopify's Online Store.
Example
{
"title": "Smart Collection TAG Iphone 12",
"description": "This smart collection allows you to group all the products that have the Iphone12 tag",
"handle": "smart-collection-iphone-12",
"rules": [
{
"conditionTarget": "PRODUCT",
"operator": "GREATER_THAN",
"key": "logistic_weight",
"value": "10"
},
{
"conditionTarget": "PRODUCTVARIANT",
"key": "subtitle",
"value": "subtitle value"
}
],
"isPublishedOnAllChannels": true // publish the collection on all sales channels
}
Examples
1. Base case: single condition with translations
In this example a smart collection is created that groups all products with the Iphone12 tag and includes translations.
{
"title": "Smart Collection TAG Iphone 12",
"description": "This smart collection allows you to group all the products that have the Iphone12 tag",
"handle": "smart-collection-iphone-12",
"rules": [
{
"key": "tag",
"value": "Iphone12"
}
],
"media": {
"alternativeText": "iphone12",
"url": "https://urldellimmagine.jpg"
},
"metafields": {
"test": "Translated metafield",
"test_2": ""
},
"translations": {
"title": {
"it": "Smart Collection TAG Iphone 12",
"fr": "Collection intelligente TAG Iphone 12"
},
"description": {
"it": "Questa smart collection permette di raggruppare tutti i prodotti che hanno come tag Iphone12",
"fr": "Cette collection intelligente vous permet de regrouper tous les produits qui ont le tag Iphone12"
},
"handle": {
"it": "collezione-iphone-12",
"fr": "collection-iphone-12"
},
"metafields": {
"test": {
"it": "Metafield tradotto",
"fr": "Métachamp traduit"
},
"test_2": {
"it": "Metafield tradotto",
"fr": "Métachamp traduit"
}
}
}
}
2. Multiple conditions in AND
In this case the conditions must all be verified (AND logic).
{
"isConditionOr": false, // Conditions in AND
"title": "Smart Collection TAG Iphone Pesanti",
"description": "Questa smart collection permette di raggruppare tutti i prodotti che hanno come tag Iphone12 e hanno un peso maggiore a 10 kg",
"handle": "collection-iphone-12-pesanti",
"rules": [
{
"key": "tag",
"value": "Iphone12"
},
{
"operator": "GREATER_THAN",
"key": "weight",
"value": "10"
}
]
}
3. Multiple conditions in OR
In this example the conditions are linked with OR logic: products are included that have at least one of the conditions true.
{
"isConditionOr": true, // Conditions in OR
"title": "Smart Collection TAG Iphone Pesanti",
"description": "Questa smart collection permette di raggruppare tutti i prodotti che hanno come tag Iphone12 e hanno un peso maggiore a 10 kg",
"handle": "collection-iphone-12-pesanti",
"rules": [
{
"key": "tag",
"value": "Iphone12"
},
{
"operator": "GREATER_THAN",
"key": "weight",
"value": "10"
}
]
}
Smart collections flow configurations
In addition to the base data flow configurations it is necessary to add the following settings in Settings Override:
| Field | Value | Note |
|---|---|---|
Base Url | https://adapt.flowlyze.com | adapter URL |
Resource Path | /api/adp/shopify/egress/sync-smart-collection-to-shopify | adapter path for smart collections |
Headers :: x-api-key | ********** | API key for endpoint interaction verification |
Headers :: x-shopify-graphql-url | https://SHOPIFYURL.myshopify.com/ | Shopify shop URL to connect to |
Headers :: x-shopify-access-token | shpat_CODICEALFANUMERICO | secret of the custom app created for integration |
Headers :: x-collection-identifier | title/handle | Indicates which field to use as a unique key to identify the smart collection during creation or update operations (default: title) |