Forum

Thread tagged as: Question, Shop

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&quot;|2,3&quot;|3,4&quot;|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="&#xf217; 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'); ?>
Anthony Elleray

Anthony Elleray 2 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

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

Drew McLellan

Drew McLellan 2638 points
Perch Support

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

SELECT tbl.* FROM ( SELECT idx.itemID, main.*, idx2.indexValue as sortval FROM perch2_shop_index idx JOIN perch2_shop_products main ON idx.itemID=main.productID AND idx.itemKey='productID' JOIN perch2_shop_index idx2 ON idx.itemID=idx2.itemID AND idx.itemKey='productID' AND idx2.indexKey='title' AND idx.itemID IN ('1', '2', '3', '6') AND idx.itemID IN ('1', '2', '3', '4', '5', '6') WHERE 1=1 AND ((idx.indexKey='blade_type' AND idx.indexValue='bushcraft') OR (idx.indexKey='blade_length' AND idx.indexValue=3)) AND idx.itemID=idx2.itemID AND idx.itemKey=idx2.itemKey GROUP BY idx.itemID, idx2.indexValue, productID ) as tbl WHERE (productDeleted IS NULL) GROUP BY itemID, sortval HAVING count(*)=2 ORDER BY sortval DESC
Drew McLellan

Drew McLellan 2638 points
Perch Support

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

Drew McLellan

Drew McLellan 2638 points
Perch Support

What do those fields in your product.html template look like?

They are added to product.html and list.html

<perch:shop id="blade_type" type="select" label="Blade Type" options=",Bushcraft|bushcraft,Kitchen|kitchen" required="true" order="5" divider-before="Specfication"/>
<perch:shop id="blade_length" type="text" label="Blade Length" required="true" order="6"/>
Drew McLellan

Drew McLellan 2638 points
Perch Support

Are the values entered into blade_length all integers?

yes just numbers any " are just for front end display

Drew McLellan

Drew McLellan 2638 points
Perch Support

Can I see your diagnostics report?

sure

Diagnostics report
PERCH INFORMATION

Perch: 2.8.29
Production mode: Staging (50)
Installed apps: content (2.8.29), assets (2.8.29), categories (2.8.29), perch_forms (1.8.3), perch_gallery (2.8.6), perch_shop_orders (1.0), perch_shop_products (1.0), perch_shop (1.0.1), perch_members (1.5)
DB driver: PDO
DB tables: perch2_categories (2), perch2_category_counts (0), perch2_category_sets (1), perch2_content_index (137), perch2_content_items (15), perch2_content_regions (12), perch2_forms (1), perch2_forms_responses (7), perch2_gallery_albums (1), perch2_gallery_image_versions (154), perch2_gallery_images (22), perch2_members (164), perch2_members_forms (1), perch2_members_member_tags (0), perch2_members_sessions (3), perch2_members_tags (0), perch2_navigation (0), perch2_navigation_pages (0), perch2_page_templates (1), perch2_pages (8), perch2_resource_log (129), perch2_resource_tags (47), perch2_resources (88), perch2_resources_to_tags (94), perch2_settings (27), perch2_shop_addresses (383), perch2_shop_admin_index (23), perch2_shop_brands (1), perch2_shop_cart (50), perch2_shop_cart_data (123), perch2_shop_cart_items (23), perch2_shop_countries (248), perch2_shop_currencies (152), perch2_shop_customers (202), perch2_shop_emails (1), perch2_shop_index (349), perch2_shop_option_values (0), perch2_shop_options (0), perch2_shop_order_items (125), perch2_shop_order_promotions (0), perch2_shop_order_statuses (9), perch2_shop_orders (178), perch2_shop_orders_meta (1), perch2_shop_product_files (0), perch2_shop_product_option_values (0), perch2_shop_product_options (0), perch2_shop_product_tags (0), perch2_shop_products (7), perch2_shop_promotions (0), perch2_shop_search (7), perch2_shop_shipping_zone_countries (1), perch2_shop_shipping_zones (1), perch2_shop_shippings (1), perch2_shop_tax_exhibits (181), perch2_shop_tax_group_rates (1), perch2_shop_tax_groups (1), perch2_shop_tax_locations (1), perch2_shop_tax_rates (1), perch2_shop_variants (0), perch2_user_passwords (0), perch2_user_privileges (34), perch2_user_role_privileges (16), perch2_user_roles (2), perch2_users (1)
Users: 1
App runtimes:
<?php
    $apps_list = array(
        'content', 
        'categories',
        'perch_members',
        'perch_forms',
        'perch_shop',
        'perch_gallery',

    );
Editor plug-ins: markitup
H1: dc3017eee2d3e15e50ff2a05c2c8999a
L1: 54a7cae75ea89b60e22e47c899c06f65
F1: 2edba60ed1f613d6dd804feb202456a2
headerColour: #ffffff
content_singlePageEdit: 1
helpURL:
hideBranding: 0
content_collapseList: 1
lang: en-gb
update_2.8.29: done
latest_version: 2.8.15
on_sale_version: 2.8.29
headerScheme: light
dashboard: 1
perch_members_login_page: /members/login.php?r={returnURL}
perch_shop_price_tax_mode: exc
perch_shop_site_url: https://
perch_shop_product_url: /knives/products/{slug}
perch_shop_invoice_number_format: Invoice%d
hide_pwd_reset: 0
content_hideNonEditableRegions: 0
content_frontend_edit: 0
perch_shop_default_currency: 47
perch_shop_reporting_currency: 47
perch_gallery_update: 2.8.5
perch_gallery_bucket_mode: single
perch_gallery_bucket: default
perch_gallery_basicUpload: 0
perch_members_update: 1.4
siteURL: /
PERCH_DEVELOPMENT: 10
PERCH_STAGING: 50
PERCH_PRODUCTION: 100
PERCH_PRODUCTION_MODE: 50
PERCH_DB_USERNAME: myboxpro_bear
PERCH_DB_SERVER: 10.169.0.90
PERCH_DB_DATABASE: myboxpro_bear
PERCH_DB_PREFIX: perch2_
PERCH_EMAIL_FROM: test@myboxproject.co.uk
PERCH_EMAIL_FROM_NAME: Bear Blades STAGING
PERCH_EMAIL_METHOD: smtp
PERCH_EMAIL_HOST: mail3.gridhost.co.uk
PERCH_EMAIL_AUTH: 1
PERCH_EMAIL_SECURE: ssl
PERCH_EMAIL_PORT: 465
PERCH_EMAIL_USERNAME: test@myboxproject.co.uk
PERCH_DEBUG: 1
PERCH_TZ: UTC
PERCH_LOGINPATH: /perch
PERCH_PATH: /var/sites/b/bearblades.myboxproject.co.uk/public_html/perch
PERCH_CORE: /var/sites/b/bearblades.myboxproject.co.uk/public_html/perch/core
PERCH_RESFILEPATH: /var/sites/b/bearblades.myboxproject.co.uk/public_html/perch/resources
PERCH_RESPATH: /perch/resources
PERCH_HTML5: 1
PERCH_MAP_JS: /js/public_maps.js
PERCH_RUNWAY:
PERCH_ERROR_MODE: DIE
PERCH_DATE_LONG: %d %B %Y
PERCH_DATE_SHORT: %d %b %Y
PERCH_TIME_SHORT: %H:%M
PERCH_TIME_LONG: %H:%M:%S
PERCH_RUNWAY_ROUTED:
PERCH_STRONG_PASSWORDS:
PERCH_PREVIEW_ARG: preview
PERCH_TEMPLATE_PATH: /var/sites/b/bearblades.myboxproject.co.uk/public_html/perch/templates
PERCH_DEFAULT_DOC: index.php
PERCH_DEFAULT_EXT: .php
PERCH_RWD:
PERCH_HTML_ENTITIES:
PERCH_SSL:
PERCH_STRIPSLASHES:
PERCH_PROGRESSIVE_FLUSH: 1
PERCH_PARANOID:
PERCH_FORCE_SECURE_COOKIES:
PERCH_PASSWORD_MIN_LENGTH: 6
PERCH_MAX_FAILED_LOGINS: 10
PERCH_AUTH_LOCKOUT_DURATION: 1 HOUR
PERCH_VERIFY_UPLOADS:
PERCH_AUTH_PLUGIN:
PERCH_DB_CHARSET: utf8
PERCH_DB_PORT:
PERCH_DB_SOCKET:
PERCH_SESSION_TIMEOUT_MINS: 20
PERCH_APPS_EDITOR_PLUGIN: markitup
PERCH_APPS_EDITOR_MARKUP_LANGUAGE: textile
HOSTING SETTINGS

PHP: 5.5.26
Zend: 2.5.0
OS: Linux
SAPI: cgi-fcgi
Safe mode: not detected
MySQL client: mysqlnd 5.0.11-dev - 20120503 - $Id: 15d5c781cfcad91193dceae1d2cdd127674ddb3e $
MySQL server: 5.6.30
Free disk space: 17.73 TB
Extensions: Core, date, ereg, libxml, openssl, pcre, sqlite3, zlib, bcmath, calendar, ctype, curl, dom, hash, fileinfo, filter, ftp, gd, gettext, SPL, iconv, session, json, ldap, mbstring, mcrypt, mssql, standard, mysql, mysqlnd, mysqli, PDO, pdo_mysql, pdo_pgsql, pdo_sqlite, pgsql, Phar, posix, Reflection, imap, SimpleXML, soap, sockets, exif, tidy, tokenizer, xml, xmlreader, xmlrpc, xmlwriter, xsl, zip, cgi-fcgi, memcache, geoip, mhash, ionCube Loader
GD: Yes
ImageMagick: No
PHP max upload size: 100M
PHP max form post size: 100M
PHP memory limit: 128M
Total max uploadable file size: 100M
Resource folder writeable: Yes
Session timeout: 240 minutes
Native JSON: Yes
Filter functions: Yes
Transliteration functions: No
DOCUMENT_ROOT: /var/sites/b/bearblades.myboxproject.co.uk/public_html
GATEWAY_INTERFACE: CGI/1.1
HTTP_ACCEPT: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
HTTP_ACCEPT_ENCODING: gzip, deflate, sdch
HTTP_ACCEPT_LANGUAGE: en-GB,en-US;q=0.8,en;q=0.6
HTTP_CONNECTION: close
HTTP_COOKIE: km_lv=1460548469; km_ai=827223; km_ni=827223; km_uq=; _ga=GA1.3.286757128.1458634075; p_m=0c13d5e28300460dbd178515b494f61fd208968d; cmsa=1; PHPSESSID=51e4c6e56f16725b7499fcab49c31314
HTTP_HOST: bearblades.myboxproject.co.uk
HTTP_REFERER: https://bearblades.myboxproject.co.uk/perch/core/settings/diagnostics/
HTTP_UPGRADE_INSECURE_REQUESTS: 1
HTTP_USER_AGENT: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.94 Safari/537.36
HTTP_X_FORWARDED_FOR: 94.193.72.159
PATH: /bin
QUERY_STRING: extended
REDIRECT_STATUS: 200
REMOTE_ADDR: 94.193.72.159
REMOTE_PORT: 32829
REQUEST_METHOD: GET
REQUEST_URI: /perch/core/settings/diagnostics/?extended
SCRIPT_FILENAME: /var/sites/b/bearblades.myboxproject.co.uk/public_html/perch/core/settings/diagnostics/index.php
SCRIPT_NAME: /perch/core/settings/diagnostics/index.php
SERVER_ADDR: 10.168.1.177
SERVER_ADMIN: you@example.com
SERVER_NAME: bearblades.myboxproject.co.uk
SERVER_PORT: 80
SERVER_PROTOCOL: HTTP/1.1
SERVER_SOFTWARE: Apache
PHP_SELF: /perch/core/settings/diagnostics/index.php
REQUEST_TIME_FLOAT: 1462806642.59
REQUEST_TIME: 1462806642
argc: 1

Could this be a potential bug ?

Drew McLellan

Drew McLellan 2638 points
Perch Support

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

Drew McLellan

Drew McLellan 2638 points
Perch Support

I was thinking

'category-match' => 'any',

vs

'category-match' => 'all',

just tried both and still not working

if i just filer by blade_length i get

SELECT tbl.* FROM ( SELECT idx.itemID, main.*, idx2.indexValue as sortval FROM perch2_shop_index idx JOIN perch2_shop_products main ON idx.itemID=main.productID AND idx.itemKey='productID' JOIN perch2_shop_index idx2 ON idx.itemID=idx2.itemID AND idx.itemKey='productID' AND idx2.indexKey='title' AND idx.itemID IN ('1', '10', '2', '3', '6', '7') AND idx.itemID IN ('1', '10', '2', '3', '4', '5', '6', '7') WHERE 1=1 AND ((idx.indexKey='blade_length' AND idx.indexValue=3)) AND idx.itemID=idx2.itemID AND idx.itemKey=idx2.itemKey GROUP BY idx.itemID, idx2.indexValue, productID ) as tbl WHERE (productDeleted IS NULL) GROUP BY itemID, sortval ORDER BY sortval DESC

if i filter buy blade_length and blade type

SELECT tbl.* FROM ( SELECT idx.itemID, main.*, idx2.indexValue as sortval FROM perch2_shop_index idx JOIN perch2_shop_products main ON idx.itemID=main.productID AND idx.itemKey='productID' JOIN perch2_shop_index idx2 ON idx.itemID=idx2.itemID AND idx.itemKey='productID' AND idx2.indexKey='title' AND idx.itemID IN ('1', '10', '2', '3', '6', '7') AND idx.itemID IN ('1', '10', '2', '3', '4', '5', '6', '7') WHERE 1=1 AND ((idx.indexKey='blade_type' AND idx.indexValue='bushcraft') OR (idx.indexKey='blade_length' AND idx.indexValue=3)) AND idx.itemID=idx2.itemID AND idx.itemKey=idx2.itemKey GROUP BY idx.itemID, idx2.indexValue, productID ) as tbl WHERE (productDeleted IS NULL) GROUP BY itemID, sortval HAVING count(*)=2 ORDER BY sortval DESC

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