Product filter - only filters by 1
Hi All
I have created a user filterable list to filter my products but i can only filter by 1 term not two
i have used the filter for another project with perch content custom and it works perfectly
product-filter.html
<div id="product-filter" class="row">
<div class="large-12 columns">
<perch:form id="product_filter" method="get">
<div class="large-4 medium-4 small-12 columns text-center">
<h3><i class="fa fa-search" aria-hidden="true"></i> Find the perfect Bear Blade</h3>
</div>
<div class="large-3 medium-3 small-12 columns">
<perch:input type="select" id="blade_type" options="Kife Type|,Bushcraft|bushcraft,Kitchen|kitchen" />
</div>
<div class="large-3 medium-3 small-12 columns">
<perch:input type="select" id="blade_length" options="Blade Length|,2"|2,3"|3,4"|4" />
</div>
<div class="large-2 medium-2 small-12 columns">
<perch:input type="submit" value="Filter" class="filter-button button" />
</div>
</perch:form>
</div>
</div>
list.html
<perch:before>
<div class="row">
<div class="large-12 columns product-listing">
</perch:before>
<div class="large-4 medium-4 small-12 columns product <perch:if exists="perch_item_last">end</perch:if>">
<div class="image">
<img src="<perch:shop id="image" type="image" width="360" height="240" density="1.6" crop="true" />">
<div class="buttons">
<div class="view-item">
<a href="/knives/products/<perch:shop id="slug" type="slug" />/">
<div class="button">
<i class="fa fa-search" aria-hidden="true"></i> View Details
</div>
</a>
</div>
<div class="buy-item">
<perch:if not-exists="has_variants">
<perch:form id="add_to_cart" app="perch_shop" action="/knives/cart">
<perch:input id="product" type="hidden" env-autofill="false" value="<perch:shop id="productID" type="hidden" />" />
<perch:input id="submit" type="submit" value=" Add to Basket" class="add-to-cart button" />
</perch:form>
</perch:if>
</div>
</div>
</div>
<div class="title">
<a href="/knives/products/<perch:shop id="slug" type="slug" />/">
<h3><perch:shop id="title" type="text" /></h3>
</a>
</div>
<div class="details">
<perch:shop id="description" type="textarea" label="Description" editor="markitup" order="3" markdown="true" words="20" append=" ..." />
<perch:shop id="blade_type" type="select" label="Blade Type" />
<perch:shop id="blade_length" type="text" label="Blade Length" />
</div>
<div class="price">
<perch:if exists="on_sale">
<span class="sale-price"><perch:shop id="sale_price" type="shop_currency_value" label="Price" size="m" min="0" step="any" /></span>
<span class="price-was"><perch:shop id="price" type="shop_currency_value" label="Price" size="m" min="0" step="any" /></span>
<perch:else />
<perch:shop id="price" type="shop_currency_value" label="Price" size="m" min="0" step="any" />
</perch:if>
</div>
</div>
<perch:every count="3">
<div class="hide-for-small-only">
<hr />
</div>
</perch:every>
<perch:after>
</div>
</div>
</perch:after>
<perch:noresults>
<div id="no_results">
<div class="row">
<div class="title text-center">
<h3>Sorry we could not find a Bear Blade to your specfication</h3>
<p>Please fill in the form below with detais of your requires specification and we will get back to you ASAP</p>
</div>
<div class="large-8 medium-12 small-12 collumns large-offset-2">
<perch:form id="blade_request" method="post" app="perch_forms">
<div>
<perch:input type="text" id="name" required="true" label="Name" placeholder="Your Name"/>
<perch:error for="name" type="required">Please add your name</perch:error>
</div>
<div>
<perch:input type="email" id="email" required="true" label="Email" placeholder="Your Email Address" />
<perch:error for="email" type="required">Please add your email address</perch:error>
<perch:error for="email" type="format">Please check your email address</perch:error>
</div>
<div>
<perch:input type="textarea" id="message" required="true" label="Message" placeholder="Please Include Details Of The Blade Specification You Require" />
<perch:error for="message" type="required">Please add a message</perch:error>
</div>
<div>
<perch:input type="submit" id="submit" value="Send" class="button" />
</div>
</perch:form>
</div>
</div>
</div>
</perch:noresults>
The page
<?php include('../perch/runtime.php'); ?>
<?php perch_layout('header'); ?>
<?php
perch_gallery_album_images('global-images', array(
'template'=>'global_images.html',
'sort'=>'image',
'sort-order'=>'RAND',
'count'=>'6',
));
?>
<?php perch_form('product_filter.html'); ?>
<?php
// Create an empty array ready to add our filters to
$filters = array();
if (perch_get('blade_type')) {
// if 'type' is on the URL, add a filter for bedrooms
$filters[] = array(
'filter' => 'blade_type',
'match' => 'eq',
'value' => perch_get('blade_type'),
);
}
if (perch_get('blade_length')) {
// if 'beds' is on the URL, add a filter for bedrooms
$filters[] = array(
'filter' => 'blade_length',
'match' => 'eq',
'value' => perch_get('blade_length'),
);
}
// Unset the filters if none are used:
if (!count($filters)) $filters=false;
// Then get the list
perch_shop_products([
'sort' => 'title',
'sort-order' => 'DESC',
'filter' => $filters,
]);
?>
<?php
perch_gallery_album_images('global-images', array(
'template'=>'global_images.html',
'sort'=>'image',
'sort-order'=>'RAND',
'count'=>'6',
));
?>
<?php perch_layout('footer'); ?>
What happens?
if i filter by blade_length it works if i filter by blade_type it works
if i filter by both it does not work
Do you get an error? What does debug output?
it just displays the no results
even tho their is results that match
https://bearblades.myboxproject.co.uk/knives/
just enabled debug and it outputs
How many products do you have with a bushcraft blade at length 3?
1 product at 4
1 product at 3
1 product at 2
What do those fields in your
product.html
template look like?They are added to product.html and list.html
Are the values entered into
blade_length
all integers?yes just numbers any " are just for front end display
Can I see your diagnostics report?
sure
Could this be a potential bug ?
It's very had to say. Have you tried the match any/all filter options?
So try contains instead of eq ?
changed to contains that does not wok
I was thinking
vs
just tried both and still not working
if i just filer by blade_length i get
if i filter buy blade_length and blade type
there are 3 knives at the moment
all blade_type Bushcraft
1 is blade_length 2 1 is blade_length 3 1 is blade_length 4