Forum

Thread tagged as: Question, Shop

Category Filtering

Hi,

I have looked in the docs but I am not clear with the example. With this code:

perch_content_custom(’T-shirts’, array(
       ‘category’ => array(‘size/xl’, ‘gender/male’)
    ));

Will it show items that match both categories (e.g. XL, Male T-shirts), or either?

Mike Harrison

Mike Harrison 37 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

The default is any but you can set it to all

'category-match' => 'all',

Hm that doesn't look like it is working - I am now seeing no items, and I am sure I have some that are in both categories. Code on my page looks like this:

  perch_shop_products([
  'template' => 'products/wall-paginated-list.html',
  'paginate'=>true,
  'count'=>18,
  'sort'=>'priority',
  'sort-order'=>'ASC',
'sort-type'=>'numeric',
'category' => array('products/wall-clocks', 'availability/uk-public'),
 'category-match' => 'all'
]);
Drew McLellan

Drew McLellan 2638 points
Perch Support

What does debug output?

No obvious errors, here is the output:

Time    Δ   Debug Message
0.4571  0   [59] SELECT p.pagePath, pr.routePattern, pr.routeRegExp, p.pageTemplate FROM clocks_pages p LEFT JOIN clocks_page_routes pr ON p.pageID=pr.pageID ORDER BY pr.routeOrder ASC, p.pagePath ASC
0.4588  0.0018  Matched page: /wall-clocks, so not using routes.
0.459   0.0001  Using master page: /templates/pages/wall-clocks.php
0.4817  0.0227  [1] SELECT * FROM clocks_pages WHERE pagePath='/wall-clocks' LIMIT 1
0.5297  0.0481  [1] SELECT * FROM clocks_shop_cart WHERE cartID=337615
0.5482  0.0184  [1] SELECT * FROM clocks_shop_cart WHERE cartID=337615
0.5836  0.0355  [15] SELECT * FROM clocks_pages WHERE pageNew=0 AND pageHidden=0 AND pageDepth >=0 AND pageDepth<=2 ORDER BY pageTreePosition ASC
0.5847  0.0011  [1] SELECT pageTreePosition FROM clocks_pages WHERE pagePath='/wall-clocks' LIMIT 1
0.5851  0.0004  [1] SELECT pageID FROM clocks_pages WHERE pageTreePosition IN ('000-002', '000') ORDER BY pageTreePosition DESC
0.5858  0.0007  Using template: /templates/navigation/dropdown-refill-level1.html
0.586   0.0002  [8] Using template: /templates/navigation/dropdown-refill-level2.html
0.6206  0.0346  [0] SELECT DISTINCT idx.itemID FROM clocks_shop_index idx JOIN clocks_shop_products main ON idx.itemID=main.productID AND idx.itemKey='productID' AND (idx.indexKey='_category' AND idx.indexValue LIKE 'products/wall-clocks%' OR idx.indexKey='_category' AND idx.indexValue='products/wall-clocks') OR (idx.indexKey='_category' AND idx.indexValue LIKE 'availability/uk-public%' OR idx.indexKey='_category' AND idx.indexValue='availability/uk-public') GROUP BY idx.itemID HAVING COUNT(idx.itemID)=2
1.9214  1.3008  [252] SELECT DISTINCT idx.itemID FROM clocks_shop_index idx JOIN clocks_shop_products main ON idx.itemID=main.productID AND idx.itemKey='productID' AND (idx.indexKey='status' AND idx.indexValue='1') GROUP BY idx.itemID HAVING COUNT(idx.itemID)=1
2.0749  0.1535  [294] SELECT DISTINCT idx.itemID FROM clocks_shop_index idx JOIN clocks_shop_products main ON idx.itemID=main.productID AND idx.itemKey='productID' AND (idx.indexKey='parentID' AND idx.indexValue='') GROUP BY idx.itemID HAVING COUNT(idx.itemID)=1
2.3541  0.2793  [nil] SELECT SQL_CALC_FOUND_ROWS DISTINCT tbl.* FROM ( SELECT idx.itemID, main.*, idx2.indexValue as sortval FROM clocks_shop_index idx JOIN clocks_shop_products main ON idx.itemID=main.productID AND idx.itemKey='productID' JOIN clocks_shop_index idx2 ON idx.itemID=idx2.itemID AND idx.itemKey='productID' AND idx2.indexKey='priority' AND idx.itemID IN (NULL) AND idx.itemID IN ('1', '100', '101', '102', '103', '104', '105', '106', '107', '108', '109', '11', '110', '114', '115', '116', '118', '119', '12', '120', '121', '122', '123', '125', '126', '127', '128', '13', '130', '131', '132', '133', '134', '136', '137', '138', '139', '14', '140', '141', '142', '143', '144', '145', '146', '147', '148', '149', '15', '150', '151', '152', '154', '155', '156', '157', '158', '159', '160', '161', '162', '163', '164', '165', '166', '167', '168', '169', '170', '171', '172', '173', '174', '175', '176', '179', '180', '181', '183', '184', '185', '186', '187', '188', '189', '190', '191', '192', '193', '195', '2', '20', '201', '202', '203', '204', '205', '207', '208', '21', '211', '212', '213', '214', '215', '216', '217', '218', '219', '22', '220', '221', '23', '230', '231', '232', '233', '234', '235', '236', '237', '238', '239', '24', '240', '241', '242', '243', '244', '245', '246', '247', '248', '249', '25', '250', '251', '252', '253', '254', '26', '27', '288', '289', '29', '290', '291', '292', '293', '294', '295', '296', '297', '298', '299', '3', '30', '300', '301', '302', '303', '304', '305', '306', '307', '308', '309', '31', '310', '311', '312', '313', '314', '315', '316', '317', '318', '319', '32', '320', '321', '322', '323', '324', '325', '326', '327', '328', '329', '33', '330', '331', '332', '333', '334', '335', '336', '34', '35', '36', '37', '38', '39', '40', '41', '42', '43', '44', '45', '46', '48', '49', '50', '52', '53', '54', '55', '56', '57', '58', '59', '60', '61', '62', '63', '66', '67', '68', '69', '70', '71', '73', '74', '75', '76', '77', '8', '82', '83', '84', '85', '86', '87', '9', '91', '92', '93', '94', '95', '97', '98', '99') AND idx.itemID IN ('1', '100', '101', '102', '103', '104', '105', '106', '107', '108', '109', '11', '110', '111', '112', '113', '114', '115', '116', '117', '118', '119', '12', '120', '121', '122', '123', '124', '125', '126', '127', '128', '129', '13', '130', '131', '132', '133', '134', '135', '136', '137', '138', '139', '14', '140', '141', '142', '143', '144', '145', '146', '147', '148', '149', '15', '150', '151', '152', '153', '154', '155', '156', '157', '158', '159', '160', '161', '162', '163', '164', '165', '166', '167', '168', '169', '170', '171', '172', '173', '174', '175', '176', '177', '178', '179', '180', '181', '182', '183', '184', '185', '186', '187', '188', '189', '190', '191', '192', '193', '194', '195', '196', '197', '198', '199', '2', '20', '200', '201', '202', '203', '204', '205', '206', '207', '208', '209', '21', '210', '211', '212', '213', '214', '215', '216', '217', '218', '219', '22', '220', '221', '222', '223', '224', '225', '226', '227', '228', '229', '23', '230', '231', '232', '233', '234', '235', '236', '237', '238', '239', '24', '240', '241', '242', '243', '244', '245', '246', '247', '248', '249', '25', '250', '251', '252', '253', '254', '26', '27', '28', '288', '289', '29', '290', '291', '292', '293', '294', '295', '296', '297', '298', '299', '3', '30', '300', '301', '302', '303', '304', '305', '306', '307', '308', '309', '31', '310', '311', '312', '313', '314', '315', '316', '317', '318', '319', '32', '320', '321', '322', '323', '324', '325', '326', '327', '328', '329', '33', '330', '331', '332', '333', '334', '335', '336', '34', '35', '36', '37', '38', '39', '40', '41', '42', '43', '44', '45', '46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60', '61', '62', '63', '64', '65', '66', '67', '68', '69', '70', '71', '72', '73', '74', '75', '76', '77', '78', '79', '8', '80', '81', '82', '83', '84', '85', '86', '87', '88', '89', '9', '90', '91', '92', '93', '94', '95', '96', '97', '98', '99') WHERE 1=1 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 * 1 ASC LIMIT 0, 18
2.3576  0.0035  [1] SELECT FOUND_ROWS() AS `count`
2.3642  0.0065  [38] SELECT DISTINCT settingID, settingValue FROM clocks_settings WHERE userID=0
2.3723  0.0081  Using template: /templates/shop/products/wall-paginated-list.html
2.3903  0.018   [1] SELECT regionKey, regionHTML FROM clocks_content_regions WHERE regionPage='/wall-clocks' OR regionPage='*' ORDER BY regionPage DESC
2.3915  0.0012  Request time: 2.3914
2.3915  0   Process time: 2.2817
2.3915  0   Memory: 5.6146

Strangely, this one works:

  perch_shop_products([
  'template' => 'products/paginated-list.html',
  'paginate'=>true,
  'count'=>18,
  'category' => array('!products/watches', 'availability/uk-public'),
  'sort'=>'priority',
  'sort-order'=>'ASC',
  'sort-type'=>'numeric',
  'category-match' => 'all'
]);
Drew McLellan

Drew McLellan 2638 points
Perch Support

idx.itemID IN (NULL) is intriguing.

Anything I can try or shall I leave it with you :) ?

If I switch this:

'category' => array('products/wall-clocks', 'availability/uk-public'),

to this:

'category' => array('!products/wall-clocks', 'availability/uk-public'),

It works, but obviously that is the opposite of the filter I want!

Drew McLellan

Drew McLellan 2638 points
Perch Support

You'll have to leave it with me.

Fixed in 2.8.29 :)