Vanilo 6.0 Released.See what's new
WARNING! You're browsing the documentation of the upcoming version of Vanilo. It may contain unreleased features and changes, or even features that will not be present in the next release as described here. The latest stable version is 6.x
Components Search and Query Products
1 min read

Searching and Querying Products

Retrieving a list of products can be as simple as querying the Product model. But real E-commerce systems attribute lots of features to products that involve other models and DB tables like:

Imagine combining these like: "Get products from category "Men's shoes" that have color 'red' and 'yellow' and style 'casual' properties, containing 'Retro' in their names but only those within the 'retail' channel. Get both plain and master products and paginate them in chunks of 50 items".

This is a pretty common scenario in E-commerce, but can be a hell of a complexity when working with data structures. Vanilo has the ProductSearch class to simplify your life with complex, multi-model queries.

use Vanilo\Foundation\Search\ProductSearch;

$products = (new ProductSearch())
    ->withinTaxon(Taxon::findBySlug('mens-shoes'))
    ->withinChannel(Channel::findBySlug('retail'))
    ->havingPropertyValuesByName('color', ['red', 'yellow'])
    ->havingPropertyValuesByName('style', ['casual'])
    ->nameContains('Retro')
    ->paginate(50);
Next in Components Categorization