Filter Rules Example

In the previous article, we provided a simple example of what was possible using filter rules. This article will walk you through creating the rules for that example.

This will give you the foundation from which to build further, more complex rules.

Adding Rules

Following on from the Filters article in this series, we will now use the example discussed in the previous article, Filter Rules, to walk you through the creation of rules. You can quickly view the example rules we discussed below:

📘

Example Rules

1. Search for products whose Price (Field) is Greater Than (Operator£50.00 (Value).
2. Search for products whose Price (Field) is Less Than (Operator) £60.00 (Value).
3. Search for products whose Stock (Field) is Greater Than (Operator) 1 (Value).

OR

4. Search for products whose Colour (Field) is Equal to (Operator) Current Products Colour (Value).

2288

The first rule for a new filter is always started for you. To add a further rule to your filter, you would click the Add Rule button.

1. First select the Add Group button to add a new group. This will contain our first three nested rules. For now, you can Delete the top rule - we will come back to that later.

2. Select the Field you would like to search by for the first example rule. For this example, we will use the Products: Price field.

3. Select the Operator you would like to use. For this example, we will use the Greater operator.

4. Enter the Value you would like the rule to search against. For this example, we will use the value of 50.00.

Your rule should look like the below:

2298

👍

Now is a good time to use the Preview button to preview the list of products that will be returned by the rule. See the Preview section in the Filter Rules article for more information on the feature.

5. To add another nested rule to the group, click the Add Rule button that's inside the group.

6. Following steps 2, 3 and 4 above, add the second example rule discussed above using the different operator and values.

 
7. To add the last nested rule to the group, click the Add Rule button again, that's inside the group.

8. Following steps 2, 3 and 4 above, add the third example rule discussed above. This time, don't forget to use the Stock field.

Your filter rules should now look like the below:

2296

Feel free to use the Preview button to view the results of your query. The result will always be dependent on the products in your store.

Now would be a good time to Save your filter using the Add/Edit Filter button at the bottom of the page.

🚧

Take care when building complex filters with many rules. Each rule applied will likely reduce the number of products being returned by the filter. Use the Preview button to preview the results of the your filter each time a new rule is added.

Using Rule Operators 

As well as using operators for individual rules, operators can be used between rules and groups of rules.

Note how the operator in the group you created earlier is set to AND. This means that all of the rules in the group have to be met for a product to be returned by the filter. Lets add an OR operator.

 
Following on from the above filter, to add a parent rule:

1. Click the parent Add Rule button, located to the very top left of the Rules section.

2. Select the parent OR operator. This will now make the filter search for products that meet ALL of the rules in the group you created, OR, meet the new single rule we are going to create.

Your filter rules should now look like the below:

2274

You can create groups inside groups, which could be stored inside a further group. Each group can contain 1 or more rules. This functionality allows you to create some extremely complex queriers from which to return a list of products.

Adding Current Product Aware Rules

As mentioned previously, you can use values in rules that are aware of the product being currently viewed. In this example we will use the additional field Colours to find products that match the colour of the product the customer is viewing, though the principle applies to almost all selectable fields.

Following on with with above filter, to add a current product aware rule:

1. Select the Field you would like to search by. For this example, we will use the Product Additional: Colour field.

2. Select the Operator you would like to use. For this example, we will use the Equal operator.

4. For the Value, type the { character. You will be presented with a list of dynamic variables that you can use.

📘

Dynamic Variables were discussed in more detail in the previous article which covered Filter Rules.

5. We are looking for the Colour additional field, so we need to type {current.p_add.colour}. You will notice that as you type the variable in, the list of other variables available automatically updates.

📘

Need a list of all dynamic variables available?

Once you've typed the { character in the Value field, you can scroll down and select dynamic variables from the list - instead of typing it out fully.

Your rule should look like the below:

2284

6. Finally, click the Preview button. You'll notice that you're asked to provide a product reference this time. This is because you've added a rule that varies its results based on the product the customer is viewing. Enter the product name or product reference of the product you would like to simulate a customer viewing.

7. Click the Preview button again. The results displayed will be based on the supplied product name or reference.

Summary

The rules that we just created combined the first three example rules into a group, which resulted in products being returned that were greater than £50, less than £60, and in stock.

Then, using an OR operator for the fourth rule, you altered the query to also include all products that matched the currently viewed products colour (irrespective of the price or stock).

The principles covered above can be applied to all fields, operators, and values available.