LemonStand Documentation

shop:search

The shop:search page is designed for creating the Product Search page. The action finds products in the database, according to a search query and other search parameters passed to the search page in the URL. Please read the Creating the Search page article for action usage examples.

Supported form fields

The action automatically loads GET parameters from the URL and performs the search. Example of a correct search URL: /search/query=laptop&records=6. The accepted parameters are:

  • query - the search query string
  • records - number of products to output on a single page
  • min_price - minimum product price. You can use this and the max_price parameters to limit products with a price range.
  • max_price - maximum product price.
  • categories - a list of category identifiers the products should belong to. This parameter should be an array, so you need to use the categories[] name for your form controls. You can use either checkboxes or a SELECT element for specifying category identifiers.
  • sorting - manages the search result sorting. Supported values are: relevance (default), name, name desc, price, price desc, created_at, created_at desc, product_rating, product_rating desc, product_rating_all, product_rating_all desc.
  • manufacturers - a list of manufacturer identifiers the products should belong to. This parameter should be an array, so you need to use the manufacturers[] name for your form controls. You can use either checkboxes or a SELECT element for specifying manufacturer identifiers.
  • option_names - a list of product option names. Use this and the option_values parameters to search in product options. This parameter should be an array, so you need to use the option_names[] name for your form controls.
  • option_values - a list of product option values. Use this parameter in combination with the option_names parameter to specify values you want to search in product options. This parameter should be an array, so you need to use the option_values[] name for your form controls. 
  • attribute_names - a list of product attribute names. Use this and the attribute_values parameters to search in product attributes. This parameter should be an array, so you need to use the attribute_names[] name for your form controls.
  • attribute_values - list of product attribute values. Use this parameter in combination with the attribute_names parameter to specify values you want to search in product attributes. This parameter should be an array, so you need to use the attribute_values[] name for your form controls. 

Please note that the form should use the GET method. Example of a simple search form:

<form method="get" action="/search">
    <input name="query" type="text" value="<?= isset($query) ? $query : null ?>"/>
    <input type="submit" value="Find Products"/>
    <input type="hidden" name="records" value="6"/>
</form>

The option_names and option_values parameters work in the following way. You can define any number of the option_names and option_values fields. On your form you should have an equal number of the option_names[] and option_values[] fields. LemonStand matches names and values specified in fields with equal index. The first value from the option_values[] field will correspond the first option_names[] field. For example, if you want to organize a search in the Color option (and only), you can define two fields (one of them is hidden):

<form method="get" action="/search">
    <input name="query" type="text" value="<?= isset($query) ? $query : null ?>"/>
    <input type="submit" value="Find Products"/>
    <input type="hidden" name="records" value="6"/>
  
    <input type="hidden" name="option_names[]" value="Color"/>
    Product color:
    <input type="text" name="option_values[]" value=""/>
</form>

The attribute_names and attribute_values fields work in the same way. You can find more examples in the  Creating the Search page article.

Generated PHP variables

The action creates the following variables which you can access in the page code:

  • $no_query - a boolean-type variable. Its value is TRUE is the search query string is empty and no other parameters were specified.
  • $query - a search query string passed to the search page through the page URL.
  • $min_price - the min_price value specified in the search form.
  • $max_price - the max_price value specified in the search form.
  • $sorting - the sorting value specified in the search form.
  • $categories - a list of category identifiers specified in the search form.
  • $manufacturers - of manufacturer identifiers specified in the search form.
  • $option_names - a list of product option names specified in the search form.
  • $option_values - a list of product option values specified in the search form.
  • $attribute_names - a list of product attribute names specified in the search form.
  • $attribute_values - a list of product attribute values specified in the search form.
  • $search_params_str - a string, containing all search parameters in a URL format. You can pass this string between pagination pages. In the default store implementation this value can be passed to the suffix parameter of the pagination partial.
  • $records - a number of records per page to output on the search page. The default parameter value is 20.
  • $products - a list of found products. An object of the Db_DataCollection class. Each element in the collection is an object of the Shop_Product class.
  • $pagination  - an object of the Phpr_Pagination class which contains the pagination information.

Next: shop:signup
Previous: shop:on_clearCompareList
Return to Reference