Forum

Thread tagged as: Comments

Multi-step filtered using categories?

Hi Drew/Rachel,

I am trying to create a multi-step filter with categories.

I have a region 'Shipping Route' on the page 'shipping-search-results.php' with a template as follows:

<table class="table-responsive">
  <tr>
    <td>Origin</td>
    <td><perch:categories id="origin" label="Origin" set="origin" required="true" /></td>
  </tr>
  <tr>
    <td>Origin code</td>
    <td><perch:content id="origin-code" label="Origin code" required="true" /></td>
  </tr>
  <tr>
    <td>Destination</td>
    <td><perch:categories id="destination" label="Destination" set="destination" required="true" /></td>
  </tr>
  <tr>
    <td>Destination code</td>
    <td><perch:content id="destination-code" label="Destination code" required="true" /></td>
  </tr>
  <tr>
    <td>Vessel</td>
    <td><perch:content id="vessel" label="Vessel" required="true" /></td>
  </tr>
  <tr>
    <td>Closing</td>
    <td><perch:content id="closing" label="Closing" required="true" /></td>
  </tr>
  <tr>
    <td>Sailing</td>
    <td><perch:content id="sailing"label="Sailing" required="true" /></td>
  </tr>
  <tr>
    <td>Transit time</td>
    <td><perch:content id="transit-time" label="Transit time" required="true" /></td>
  </tr>               
</table>

<perch:categories id="service" label="Service" set="service" order="1" suppress="true" />

I need to create a multi-step filter to narrow town the results by clicking choices.

These are the filter steps that I need to have - Service > Origin > Destination > Result

This is my origin.html template called in 'shipping-search-origin.php':

<div class="col-lg-2 col-md-3 col-sm-4 col-xs-6">
<perch:categories id="origin" label="Origin" set="origin" required="true">
    <a href="/category/<perch:category id="catPath" />" class="service-panel"><h2><perch:category id="catTitle" /></h2></a>
</perch:categories>
</div>

There will be a similar template for destination on 'shipping-search-destination.php'

I have categories set up for Service, Origin and Destination and I have watched the video and read the documentation, but I'm just really struggling with tying everything up....

Is this something I can do with Perch? If so would you be able to point me in the right direction?

Many thanks in advance,

Andy

Andy Knight

Andy Knight 1 points

  • 7 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

The approach would be fundamentally the same as this: https://solutions.grabaperch.com/architecture/user-filtered-lists

Thanks for the lightning response Drew! I will take a look at this link now.

Hi Drew,

Is there a way of implementing this approach with out the form aspect?

i.e. domain.com/shipping-search-results.php?

I need to apply a multi choice filter so that there can never be 'no results'. i.e. a user can't choose a origin that isn't available under that service.

This is what now have on my results page:

<?php
// Create an empty array ready to add our filters to $filters = array();

if (perch_get('service')) {
    // if 'type' is on the URL, add a filter for bedrooms
    $filters[] = array(
        'filter' => 'service',
        'match'  => 'eq',
        'value'  => perch_get('service'),
    );
}

if (perch_get('origin')) {
    // if 'beds' is on the URL, add a filter for bedrooms
    $filters[] = array(
        'filter' => 'origin',
        'match'  => 'eq',
        'value'  => perch_get('origin'),
    );
}

if (perch_get('destination')) {
    // if 'location' is on the URL, add a filter for the location
    $filters[] = array(
        'filter' => 'destination',
        'match'  => 'eq',
        'value'  => perch_get('destination'),
    );
}

// Unset the filters if none are used:
if (!count($filters)) $filters=false;

// Then get the list
perch_content_custom('Shipping Route', array(
    'template'   => 'shipping_route.html',
    'sort'       => 'origin', 
        'sort-order' => 'DESC',
        'category' => perch_get('cat'),
    'filter'     => $filters,
));

?>

But adding filters to the url does nothing? i.e. domain.com/shipping-search-results.php?service=airfreight&etc

Drew McLellan

Drew McLellan 2638 points
Perch Support

How will the user filter their choices?

Hi Drew,

By using buttons displayed on the pages.

  • Service = Seafreight FCL, Seafreight FCL or Airfreight
  • Origin = Origin one, Origin two, Origin three etc...
  • Destination = Destination one, Destination two etc...
  • Result = Service + Origin + Destination

I nearly have it working (I think!)... just not sure how to include the service filter on the destination page:

<?php
perch_content_custom('Shipping Route', array(
  'template' => 'destination.html',
  'page'=>'/shipping-search-results.php',
  'filter'=>'origin',
  'match'=>'eq',
  'value'=>perch_get('origin')
));
?>
Drew McLellan

Drew McLellan 2638 points
Perch Support

What are the buttons? HTML links? In which case they'll behave in the same way as the form example. If they're form buttons, they still behave in the same way as the form example.