1

I have a search form where a user can enter width, height and depth and the search results will return any item that will "fit" into those dimensions. It works, but for some reason only if the depth is not set.

Form:

<input type="search" name="q" value="{{ craft.request.getParam('q') }}">
<label>Width</label>
  <input type="number" name="w" value="{{ searchWidth }}">
<label>Height</label>
  <input type="number" name="h" value="{{ searchHeight }}">
<label>Depth</label>
  <input type="number" name="d" value="{{ searchDepth }}">

The resulting query looks like this search3?q=&w=43&h=44&d=1000

For Results

{% set queryParams = {
  section: 'products',
  order: 'postDate desc',
  limit: 15
  } %}

{% set searchWidth = craft.request.getParam('w') %}
{% set searchHeight = craft.request.getParam('h') %}
{% set searchDepth = craft.request.getParam('d') %}

{% if searchWidth > 0 %}
  {% set finalWidth = searchWidth + 1 %}
  {% set queryParams = queryParams | merge({
    width: '<= ' ~ finalWidth
    }) %}
{% endif %}

{% if searchHeight > 0 %}
  {% set finalHeight = searchHeight + 1 %}
  {% set queryParams = queryParams | merge({
    height: '<= ' ~ finalHeight
    }) %}
{% endif %}

{% if searchDepth > 0 %}
  {% set finalDepth = searchDepth + 1 %}
  {% set queryParams = queryParams | merge({
    depth: '<= ' ~ finalDepth
    }) %}
{% endif %}

Which I merge with my original search:

{% set searchQ = craft.request.getParam('q') %}
{% if searchQ is not empty %}
{% set queryParams = queryParams | merge({
  search: {
  query: searchQ,
  subLeft: true,
  subRight: true
   }
 }) %}
{% endif %}

Everything works fine. If I enter 44 for h and 43 for w it does what it should, if finds all items smaller than the width and height. If I add something in the d, even 1,000 I get 0 results. If I output {{ finalDepth }} somewhere in the template it outputs without issue, but it finds 0 results when something is entered in the d search.

All three fields are number fields named width, height and depth. I have checked and rechecked and I am at a loss.

2

Rename the field handle to something else, depth is a deprecated attribute for ElementCriteriaModel.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.