Forum

Thread tagged as: Question, Runway, Shop

Shop Products Filter by Second Category

I have products that have 2 categories associated with them, the first if they are a washer or a dryer and the second for capacity 8kg, 10kg, 23kg and so on. I have pages that display products by category working fine for example /shop/category/washers and I can have a pages for capacities working fine for example /shop/capacities/10kg but I would like to filter the products on this capacity page by their other category as to whether they are a washer or a dryer.

<?php 

perch_category('products/' . perch_get('cat'), [ 'template' => 'cat_title.html' ]);     

perch_shop_products([  'category' => 'products/'.perch_get('cat'),  ]); 

?>   


<hr>  
 <h4>Washers</h4>

 <?php

 perch_shop_products([  'category' => 'products/'.perch_get('cat'),
 'category' => 'products/washers'
   ]);

 ?>
 <hr>

 <h4>Dryers</h4>

 <?php

 perch_shop_products([  'category' => 'products/'.perch_get('cat'),
 'category' => array('products/dryer')
   ]);

 ?>

I have tried the above the first section shows all the products with the correct capacity such as 10kg but the second and third filter washers or dryers but seem to ignore the capacity as they are including washers and dryers or all capacities in the results. How could I split my capacity results pages into two separate sections based on the second category of the products?

Perch Runway: 2.8.31, PHP: 7.0.10, MySQL: mysqlnd 5.0.12-dev - 20150407 - $Id: 241ae00989d1995ffcbbf63d579943635faf9972 $, with PDO
Server OS: Darwin, apache2handler
Installed apps: content (2.8.31), assets (2.8.31), categories (2.8.31), perch_blog (5.0), perch_forms (1.8.3), perch_shop_orders (1.0.8), perch_shop_products (1.0.8), perch_shop (1.0.8), perch_members (1.5)
App runtimes: <?php $apps_list = array( 'content', 'categories', 'perch_forms', 'perch_blog', 'perch_members', 'perch_shop', );
PERCH_LOGINPATH: /perch
PERCH_PATH: /Users/greg/Sites/millers/trunk/perch
PERCH_CORE: /Users/greg/Sites/millers/trunk/perch/core
PERCH_RESFILEPATH: /Users/greg/Sites/millers/trunk/perch/resources
Image manipulation: GD
PHP limits: Max upload 32M, Max POST 32M, Memory: 128M, Total max file upload: 32M
F1: 2edba60ed1f613d6dd804feb202456a2
Resource folder writeable: Yes
HTTP_HOST: millers
DOCUMENT_ROOT: /Users/greg/Sites/millers/trunk
REQUEST_URI: /perch/core/settings/diagnostics/
SCRIPT_NAME: /perch/core/settings/diagnostics/index.php

Thanks again for any help or alternative solutions.

Greg Riley

Greg Riley 1 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

I think you probably want to use the category-match option:

    'category' => ['products/dryer', 'capacities/10kg'],
    'category-match' => 'all',

Thanks yet again Drew. I had to change it around a bit as the capacities are in the same products category set, maybe I should re think that. I also wanted to dynamically get the capacity weights. The end code for anyone else scouring the forum for answers like I do is:

 <h4>Washers</h4>

 <?php

 perch_shop_products([  'category' => 'products/'.perch_get('cat'),
 'category' => ['products/washers', 'products/'.perch_get('cat')],
 'category-match' => 'all',
   ]);


 ?>
 <hr>

 <h4>Dryers</h4>

 <?php

 perch_shop_products([  'category' => 'products/'.perch_get('cat'),
  'category' => ['products/dryers', 'products/'.perch_get('cat')],
 'category-match' => 'all',
   ]);

 ?>