Skip to main content

How To Configure Collections Based Rules

Configure collection-based rules in Rebuy Data Sources using IF and RETURN logic. Learn the IF Collection operators, Sort By options including Smart Sort, multi-collection Complete the Look setups, and how the widget product limit affects output.

Written by Tom

Collection-based rules in Rebuy Data Sources let you recommend products from a collection, match on whether a product belongs to a collection, or both. They are built using IF and RETURN logic and are often paired with a Complete the Look widget to show products from several collections together.

What Collection-Based Rules Do in Rebuy Data Sources

Collection-based rules use a collection as part of the IF condition, the RETURN statement, or both. The IF condition and the RETURN statement are independent: you can match on a collection without returning one, return a collection without matching on one, or use both together. They do not have to reference the same collection.

A collection-based rule can use either or both of these:

  • IF Collection sets the condition for when a rule matches, based on whether an input product belongs to a collection.

  • RETURN Collection sets which collection's products are displayed when the rule matches.

How you combine them depends on what you want the widget to do. The sections below cover each piece on its own, then show how they work together in a Complete the Look widget.


How to Set Up an IF Collection Rule

An IF Collection rule matches based on whether the input products belong to a collection you select. The input products are the products in context for the request, such as the product on the page the shopper is viewing or the items in their cart. The rule checks whether each input product belongs to the collection, not which page the shopper is on.

This is different from adding a widget to a collection page. An IF Collection rule fires when an input product belongs to the collection, in any widget placement. Building a widget that lives on your collection pages is a separate setup, covered in How to Create a Collection Page Widget.

In the example below, the rule matches when an input product belongs to the Snowboards collection. This lets you trigger a recommendation whenever a shopper has a snowboard in their cart or is viewing one.

(Screenshot above: Rebuy Admin datasource rule builder showing a IF Collection rule with the available operators)

IF Collection Rule Operators

IF Collection operators control when an IF Collection condition matches and a shopper sees the products you have chosen to recommend. The rule compares the input products (the current product, cart items, or other contextual products) against the collection you select.

IF Collection rules support the following operators:

  • Equals Anything always matches, with no check performed. Use it when you want the rule to fire for any input product.

  • Contains Any matches when at least one input product is in the selected collection. (Most commonly used)

  • Does Not Contain Any matches when none of the input products are in the selected collection.

  • Contains All matches when every input product is in the selected collection.

  • Does Not Contain All matches when at least one input product is not in the selected collection.

  • Equals matches only when the set of input products contains exactly the products you have selected, with nothing extra and none missing. For collections with more than a few products, this operator will rarely fire and is not recommended for most use cases.

  • Does Not Equal matches when the input products do not exactly match the selected set. Like Equals, this operator is rarely practical for large collections.


How to Set Up a RETURN Collection Rule

A RETURN Collection rule defines which collection's products are displayed when the rule matches. Set the RETURN statement to the collection you want to recommend from, and the widget will display products from that collection.

(Screenshot above: Rebuy Admin datasource rule builder showing a rule RETURN set to "Collection")

Collection Rule Sort By Options in Rebuy Data Sources

When you pair a collection rule with the Sort By option in the data source, you choose how the returned products are ordered. There are three options: Smart Sort, Similar Sort, and Don't Sort This Output.

(Screenshot above: Rebuy Admin datasource rule builder showing a rule RETURN set to "Collection" and the "SORT BY" dropdown open displaying three options: "Don't sort this output", "Smart Sort", and "Similar Sort")

How Smart Sort Ranks Collection Products

Smart Sort reorders the collection so the products most frequently bought or viewed together with the current products appear first. The ranking is based on the products in context, such as the product being viewed or the items in the cart.

Note: Smart Sort is not personalized to the individual shopper. It ranks products by what shoppers buy and view together across the whole store, based on the products in context rather than any one person's history, so every shopper viewing the same products sees the same ranking. Adding a customer rule does not switch Smart Sort into per-customer personalization. Customer rules control which shoppers a rule applies to and keep results uncached, but they do not feed an individual's order history into the Smart Sort ranking.

How Similar Sort Ranks Collection Products

Similar Sort orders products by how closely they match the current product. The algorithm analyzes product characteristics such as features, category, and attributes to suggest products with comparable qualities. Both Smart Sort and Similar Sort are designed to surface relevant product suggestions and can improve customer satisfaction, sales, and retention.

What Don't Sort This Output Does in a Collection Rule

Selecting Don't Sort This Output returns the collection's products in whatever order the collection is set to in Shopify, with no additional Rebuy sorting applied. Rebuy follows the collection's Sort option in Shopify, whether that is Best selling, Manually, Alphabetical, Price, Date, or any other Shopify sort. To change the order, update the collection's Sort option in Shopify. If you set it to Manually, you can drag the products into the exact sequence you want and Rebuy returns them in that order.

(Screenshot above: Shopify's collection editor with the Sort dropdown set)

What to Do When Don't Sort This Output Doesn't Match Shopify

If a collection rule using Don't Sort This Output is not returning products in the order shown in Shopify, the cause is usually a stale Rebuy cache or out-of-date product data. Rebuy caches collection data for performance, so a recent change to a Shopify collection's sort order or products may not be reflected yet. Work through these steps in order:

  1. Open the data source and click the Clear Cache button near the top right of the data source editor, then re-test.

  2. Resync your collections from the Status page. Find the Collections section and click Resync.

  3. If the order is still stale, open the Cache Manager and clear the Collections, Metafields, Presentment Prices Cache, which holds the collection ordering data.

(Screenshot above: the Rebuy Status page under Settings, showing the Products section and the Collections section with a Resync button)

(Screenshot above: the Rebuy Cache Manager warning panel listing the cache records, with Product Cache, Product Engine Cache, and Collections, Metafields, Presentment Prices Cache highlighted)


How to Show Products from Multiple Collections with a Complete the Look Widget

A Complete the Look widget uses collection-based rules to recommend products from several collections at once, building a full look around the product in the shopper's cart or on the page. By combining IF Collection and RETURN Collection rules, you can return products from multiple collections in a single widget.

This example uses two rules. Both match when an input product belongs to the Snowboards collection, and each returns products from a different collection:

  • Rule 1: IF Collection Snowboards, Contains Any, RETURN Collection Helmets, sorted by Smart Sort, with a Product Limit of 2.

  • Rule 2: IF Collection Snowboards, Contains Any, RETURN Collection Snow Gloves, sorted by Smart Sort, with a Product Limit of 2.

Leave Exit If Matched disabled on both rules. Exit If Matched stops every rule below it from running once its rule matches, so enabling it on Rule 1 would prevent Rule 2 from firing and only the helmets would return. Keeping it off lets both rules run and fill the widget with products from both collections.

(Screenshot above: the Rebuy data source rule builder showing two collection rules with Product Limits)

Note: The connected widget's Max Number of Products displayed setting overrides the Product Limit set in your data source rules. This setting lives in the Widget Editor under the Data Source section, and it caps the total number of products the widget shows no matter how many the rules return. Set it to at least the combined total your rules return, so in this two-rule example, set it to 4 or higher to show both helmets and both gloves.

(Screenshot above: the Rebuy Widget Editor Data Source section, showing the selected data source, and the Max Number of Products displayed slider)

With a Snowboard in the cart, the widget returns two products from each collection: two helmets from the Helmets collection and two gloves from the Snow Gloves collection.

The products return in rule order, not a mixed or random order. Rules evaluate top to bottom, so Rule 1's products fill the widget first, followed by Rule 2's. In this example the widget shows the two helmets first, then the two gloves. It does not interleave or shuffle products across the two rules.

Using just a few rules, you can return products from multiple collections to complete the look!

(Screenshot above: a Smart Cart with a Snowboard in the cart and a "You may also like" recommendation section. The first highlighted group shows two products from the Helmets collection. The second highlighted group shows two products from the Snow Gloves collection.)


How to Preview and Test a Collection Rule Before Going Live

You can preview what a collection rule will return before publishing it. Select Preview Ruleset, then Simulate, to see the products the rule will display.


Data Source Collection Rules Frequently Asked Questions

Does Smart Sort personalize recommendations for each individual customer?

Smart Sort does not personalize recommendations to the individual shopper. It ranks the products in a collection by what shoppers buy and view together across the whole store, based on the products in context, surfacing the items most frequently paired with the current products. Because the ranking is based on the products in context rather than one person's history, every shopper viewing the same products sees the same Smart Sort order. Adding a customer rule does not change this. Customer rules gate which shoppers a rule applies to and keep results uncached, but they do not turn Smart Sort into a per-customer personalization mode.

What is the difference between Smart Sort and Similar Sort in collection rules?

Smart Sort and Similar Sort are two ordering options for collection-based rules, and they rank products differently. Smart Sort orders products by what shoppers buy and view together with the products in context, based on storewide behavior. Similar Sort orders products by how closely they match the products in context, based on characteristics such as features, category, and attributes. Use Smart Sort when you want recommendations driven by buying and viewing patterns, and Similar Sort when you want recommendations driven by product similarity.

What does Contains Any mean in a collection-based rule?

Contains Any (Most commonly used) is an IF Collection operator that matches when at least one of the input products is in the selected collection. The input products are the current product, cart items, or other contextual products evaluated by the rule. For example, an IF Collection rule using Contains Any on the Snowboards collection matches whenever at least one input product belongs to that collection.

What is the difference between Contains Any and Contains All in a collection rule?

Contains Any and Contains All are both IF Collection operators, and they differ in how many input products must be in the collection for the rule to match. Contains Any matches when at least one input product is in the selected collection. Contains All matches only when every input product is in the selected collection. Use Contains Any for the broader match and Contains All when the rule should fire only if the entire input set belongs to the collection.

How do I recommend products from one collection when an input product is from another collection?

To recommend products from one collection based on an input product belonging to another, use an IF Collection rule together with a RETURN Collection rule. Set the IF Collection condition to the collection you want to match on, and set the RETURN Collection statement to the collection you want to recommend products from. This is the same logic a widget uses to return products from multiple collections at once. This is independent of widget placement and is not the same as building a widget for your collection pages.

Why is my widget showing fewer products than my data source rules return?

If your widget shows fewer products than your data source rules return, there are two common causes.

The first is the widget's Max Number of Products displayed setting. This setting, found in the Widget Editor under the Data Source section, overrides the Product Limit in your data source rules and caps the total number of products the widget shows. For example, if your rules return four products but Max Number of Products displayed is set to 2, the widget shows only 2. Raise this setting to at least the combined total your rules return.

The second is exclusion and out-of-stock filtering. Exclusion filters and the Filter out of stock products setting run after the rule's product set is assembled, not while it is being built. This means a rule can assemble a full set of products and then have some removed by a filter, leaving fewer products than expected in the widget. If a widget is set to show 10 products but consistently shows fewer, check whether an exclusion filter or the out-of-stock filter is removing items after assembly.

Can a collection rule mix products from different rules together in the output?

Products from different collection rules do not mix together in the output. Rebuy data source rules evaluate top to bottom, so each rule's products are added in order: the first rule's products fill the widget first, then the next rule's products follow. For example, in a two-rule setup that returns two helmets from Rule 1 and two gloves from Rule 2, the widget shows the two helmets first, then the two gloves. Rebuy does not interleave or randomly shuffle products across rules.

How do I preview a collection rule before publishing it?

You can preview a collection rule before it goes live by selecting Preview Ruleset, then Simulate, in the data source editor. The simulation shows which products the rule will return based on its current configuration, so you can confirm the rule behaves as expected before publishing.

Why doesn't Don't Sort This Output match the order in my Shopify collection?

When a collection rule using Don't Sort This Output does not match the order in your Shopify collection, the cause is usually a stale Rebuy cache or out-of-date product data after a recent change in Shopify. To fix it, clear the cache and resync. First, click the Clear Cache button in the data source editor and re-test. If the order is still stale, resync your collections from the Status page at Settings > Status > Collections > Resync. If it persists, open the Cache Manager under Data Sources and clear the Collections, Metafields, Presentment Prices Cache, which holds collection ordering data.

Why does my Smart Sort or Similar Sort widget show products in default order when there's nothing in the cart?

Smart Sort and Similar Sort both rank products relative to the input products in context, such as the item being viewed or the products in the cart. The widget falls back to the collection's default Shopify sort order, even with Smart Sort or Similar Sort selected, in two situations. The first is when there are no input products to rank against, for example a cart widget loading before anything has been added to the cart. The second is when there is an input product but Rebuy does not yet have enough data on it to generate a ranking, which can happen with newly added products, low-traffic products, or products without enough purchase and view history built up. In both cases the selected sort applies as expected once an input product is present and Rebuy has enough data on it.

Related Articles

Did this answer your question?