Backend filters reference for Shopware 6

Overview

In this guide, Filter allows you to filter a field to an approximate value

Below Filter are available in Shopware 6 backend:-

  • Equals:- Exact match for the given value
  • equalsAny:- At least one exact match for a value of the given list
  • Contains:- Before and after wildcard search for the given value
  • Range:- For range compatible fields like numbers or dates
  • Not:- Allows to negate a filter
  • Multi:- Allows to combine different filters
  • Prefix:- Before wildcard search for the given value
  • Suffix:- After wildcard search for the given value

Equals:- 

The Equals filter allows you to check fields for an exact value. The following SQL statement is executed in the background: WHERE stock = 10.

{% tabs %} {% tab title=”PHP Criteria” %}

$criteria = new Criteria();

$criteria->addFilter(new EqualsFilter(‘stock’, 10));

{% endtabs %}

{% tab title=”API Criteria” %}

{

    “filter”: [

        { 

            “type”: “equals”, 

            “field”: “stock”, 

            “value”: 10

        }    

    ]

}

{% endtab %} {% endtabs %}

EqualsAny:- 

The EqualsAny filter allows you to filter a field where at least one of the defined values matches exactly. The following SQL statement is executed in the background: WHERE productNumber IN (‘3fed029475fa4d4585f3a119886e0eb1′, ’77d26d011d914c3aa2c197c81241a45b’).

{% tabs %} {% tab title=”PHP Criteria” %}

$criteria = new Criteria();

$criteria->addFilter(

    new EqualsAnyFilter(‘productNumber’, [‘3fed029475fa4d4585f3a119886e0eb1′, ’77d26d011d914c3aa2c197c81241a45b’])

);

{% endtabs %}

{% tab title=”API Criteria” %}

{

    “filter”: [

        { 

            “type”: “equalsAny”, 

            “field”: “productNumber”, 

            “value”: [

                “3fed029475fa4d4585f3a119886e0eb1”, 

                “77d26d011d914c3aa2c197c81241a45b”

            ] 

        }    

    ]

}

{% endtab %} {% endtabs %}

Contains:- 

The Contains Filter allows you to filter a field to an approximate value, where the passed value must be contained as a full value. The following SQL statement is executed in the background: WHERE name LIKE ‘%Lightweight%’.

{% tabs %} {% tab title=”PHP Criteria” %}

$criteria = new Criteria();

$criteria->addFilter(new ContainsFilter(‘name’, ‘Lightweight’));

);

{% endtabs %}

{% tab title=”API Criteria” %}

{

    “filter”: [

        { 

            “type”: “contains”, 

            “field”: “name”, 

            “value”: “Lightweight”

        }    

    ]

}

{% endtab %} {% endtabs %}

Range:- 

The Range filter allows you to filter a field to a value space. This can work with a date or numerical values. Within the parameter property the following values are possible:

  • gte => Greater than equals
  • lte => Less than equals
  • gt => Greater than
  • lt => Less than

The following SQL statement is executed in the background: WHERE stock >= 20 AND stock <= 30.

{% tabs %} {% tab title=”PHP Criteria” %}

$criteria = new Criteria();

$criteria->addFilter(

    new RangeFilter(‘stock’, [

        RangeFilter::GTE => 20,

        RangeFilter::LTE => 30

    ])

);

);

{% endtabs %}

{% tab title=”API Criteria” %}

{

    “filter”: [

        { 

            “type”: “range”, 

            “field”: “stock”, 

            “parameters”: {

                “gte”: 20,      

                “lte”: 30

            }

        }    

    ]

}

{% endtab %} {% endtabs %}

Not:- 

The Not Filter is a container which allows to negate any kind of filter. The operator allows you to define the combination of queries within the NOT filter (OR and AND). The following SQL statement is executed in the background: WHERE !(stock = 1 OR availableStock = 1) AND active = 1.

{% tabs %} {% tab title=”PHP Criteria” %}

$criteria = new Criteria();

$criteria->addFilter(new EqualsFilter(‘active’, true));

$criteria->addFilter(

    new NotFilter(

        NotFilter::CONNECTION_OR,

        [

            new EqualsFilter(‘stock’, 1),

            new EqualsFilter(‘availableStock’, 10)

        ]

    )

);

);

{% endtabs %}

{% tab title=”API Criteria” %}

{

    “filter”: [

        { 

            “type”: “not”, 

            “operator”: “or”,

            “queries”: [

                {

                    “type”: “equals”,

                    “field”: “stock”,

                    “value”: 1

                },

                {

                    “type”: “equals”,

                    “field”: “availableStock”,

                    “value”: 1

                }    

            ]

        },

        {

            “type”: “equals”,

            “field”: “active”,

            “value”: true

        }

    ]

}

{% endtab %} {% endtabs %}

Multi:- 

The Multi Filter is a container, which allows to set logical links between filters. The operator allows you to define the links between the queries within the Multi filter (OR and AND). The following SQL statement is executed in the background: WHERE (stock = 1 OR availableStock = 1) AND active = 1.

{% tabs %} {% tab title=”PHP Criteria” %}

$criteria = new Criteria();

$criteria->addFilter(

    new MultiFilter(

        MultiFilter::CONNECTION_OR,

        [

            new EqualsFilter(‘stock’, 1),

            new EqualsFilter(‘availableStock’, 10)

        ]

    )

);

$criteria->addFilter(

    new EqualsFilter(‘active’, true)

);

);

{% endtabs %}

{% tab title=”API Criteria” %}

 {

    “filter”: [

        { 

            “type”: “multi”,   

            “operator”: “or”,

            “queries”: [

                {

                    “type”: “equals”,

                    “field”: “stock”,

                    “value”: 1

                },

                {

                    “type”: “equals”,

                    “field”: “availableStock”,

                    “value”: 1

                } 

            ]

        },

        {

            “type”: “equals”,

            “field”: “active”,

            “value”: true

        }

    ]

}

{% endtab %} {% endtabs %}

Prefix:- 

The Prefix Filter allows you to filter a field to an approximate value, where the passed value must be the start of a full value. The following SQL statement is executed in the background: WHERE name LIKE ‘Lightweight%’.

{% tabs %} {% tab title=”PHP Criteria” %}

$criteria = new Criteria();

$criteria->addFilter(new PrefixFilter(‘name’, ‘Lightweight’));

{% endtabs %}

{% tab title=”API Criteria” %}

{

    “filter”: [

        {

            “type”: “prefix”,

            “field”: “name”,

            “value”: “Lightweight”

        }

    ]

}

{% endtab %} {% endtabs %}

Suffix:- 

The Suffix Filter allows you to filter a field to an approximate value, where the passed value must be an end of a full value. The following SQL statement is executed in the background: WHERE name LIKE ‘%Lightweight’.

{% tabs %} {% tab title=”PHP Criteria” %}

$criteria = new Criteria();

$criteria->addFilter(new SuffixFilter(‘name’, ‘Lightweight’));

{% endtabs %}

{% tab title=”API Criteria” %}

{

    “filter”: [

        {

            “type”: “suffix”,

            “field”: “name”,

            “value”: “Lightweight”

        }

    ]

}

{% endtab %} {% endtabs %}

Rajanik is a technical Lead at our organization. He has an overall experience of 7+ years and have experience with various ecommerce software's such as Shopware, WooCommerce, Prestashop and Shopify. He is a Certified Shopware 6 Developer. He manages the team and also handles multiple projects simultaneously. He always believes to deliver the project with the highest quality.