Product filtering by category

  • I've created a page which uses this page path /category/before-the-day/wedding-invitations, it uses a master page which has the URL pattern category/[slug:cat]/[slug:subcat]. I also have a category set up at products/before-the-day/wedding-invitations/


    I'm trying to filter a list of products by category using

    Code
    1. perch_shop_products([
    2. 'template' => 'products/list.html',
    3. 'category' => 'products/'.perch_get('cat').'/'.perch_get('subcat')
    4. ]);

    but I can't get 'cat' or 'subcat'


    When I use this it works

    Code
    1. perch_shop_products([
    2. 'template' => 'products/list.html',
    3. 'category' => 'products/before-the-day/wedding-invitations/'
    4. ]);

    I can't figure our where I'm going wrong. Any help would be appreciated.

  • drewm

    Approved the thread.
  • get_route(): "> [25] SELECT p.pagePath, pr.routePattern, pr.routeRegExp, p.pageTemplate, pr.routeOrder, s.settingValue AS siteOffline FROM perch3_pages p LEFT JOIN perch3_page_routes pr ON p.pageID=pr.pageID LEFT JOIN perch3_settings s ON s.settingID='siteOffline' UNION SELECT NULL AS pagePath, pr2.routePattern, pr2.routeRegExp, pr2.templatePath AS pageTemplate, pr2.routeOrder, NULL AS siteOffline FROM perch3_page_routes pr2 WHERE templateID!=0 ORDER BY routeOrder ASC, pagePath ASC
    get_route(): ">Matched page: /category/before-the-day/wedding-invitations, so not using routes.
    Using master page: /templates/pages/category.php
    find_by_path(): "> [1] SELECT * FROM perch3_pages WHERE pagePath='/category/before-the-day/wedding-invitations' LIMIT 1
    get_cart_field(): "> [1] SELECT * FROM perch3_shop_cart WHERE cartID=42
    get_cart_field(): "> [1] SELECT * FROM perch3_shop_cart WHERE cartID=42
    get_currently_active(): "> [nil] SELECT * FROM perch3_shop_sales WHERE saleFrom<='2019-04-10 09:35:00' AND saleTo>'2019-04-10 09:35:00' AND saleActive=1 AND saleDeleted IS NULL ORDER BY saleOrder ASC
    get_navigation(): "> [1] SELECT pageID, pageParentID, pageDepth, pageTreePosition FROM perch3_pages WHERE pagePath='/before-the-day' OR pageSortPath='/before-the-day' LIMIT 1
    get_navigation(): "> [1] SELECT * FROM perch3_pages WHERE pageNew=0 AND pageHidden=0 AND pageDepth >=0 AND pageDepth<=1 ORDER BY pageTreePosition ASC
    get_value(): "> [1] SELECT pageTreePosition FROM perch3_pages WHERE pagePath='/category/before-the-day/wedding-invitations' LIMIT 1
    find_parent_page_ids_by_path(): "> [3] SELECT pageID FROM perch3_pages WHERE pageTreePosition IN ('000-001-001-001', '000-001-001', '000-001', '000') ORDER BY pageTreePosition DESC
    _template_nav(): "> [1] Using template: /templates/navigation/main_navs.html
    get_navigation(): "> [1] SELECT pageID, pageParentID, pageDepth, pageTreePosition FROM perch3_pages WHERE pagePath='/ceremony-and-reception' OR pageSortPath='/ceremony-and-reception' LIMIT 1
    get_navigation(): "> [1] SELECT * FROM perch3_pages WHERE pageNew=0 AND pageHidden=0 AND pageDepth >=0 AND pageDepth<=1 ORDER BY pageTreePosition ASC
    get_value(): "> [1] SELECT pageTreePosition FROM perch3_pages WHERE pagePath='/category/before-the-day/wedding-invitations' LIMIT 1
    find_parent_page_ids_by_path(): "> [3] SELECT pageID FROM perch3_pages WHERE pageTreePosition IN ('000-001-001-001', '000-001-001', '000-001', '000') ORDER BY pageTreePosition DESC
    _template_nav(): "> [1] Using template: /templates/navigation/main_navs.html
    get_navigation(): "> [1] SELECT pageID, pageParentID, pageDepth, pageTreePosition FROM perch3_pages WHERE pagePath='/after-the-day' OR pageSortPath='/after-the-day' LIMIT 1
    get_navigation(): "> [1] SELECT * FROM perch3_pages WHERE pageNew=0 AND pageHidden=0 AND pageDepth >=0 AND pageDepth<=1 ORDER BY pageTreePosition ASC
    get_value(): "> [1] SELECT pageTreePosition FROM perch3_pages WHERE pagePath='/category/before-the-day/wedding-invitations' LIMIT 1
    find_parent_page_ids_by_path(): "> [3] SELECT pageID FROM perch3_pages WHERE pageTreePosition IN ('000-001-001-001', '000-001-001', '000-001', '000') ORDER BY pageTreePosition DESC
    _template_nav(): "> [1] Using template: /templates/navigation/main_navs.html
    get_value(): "> [1] SELECT groupID FROM perch3_navigation WHERE groupSlug='site-navigation' LIMIT 1
    get_navigation(): "> [2] SELECT np.pageID, np.pageParentID, p.pagePath, p.pageTitle, p.pageNavText, p.pageNew, p.pageOrder, np.pageDepth, p.pageSortPath, np.pageTreePosition, p.pageAccessTags, p.pageAttributes FROM perch3_navigation_pages np, perch3_pages p WHERE p.pageID=np.pageID AND np.groupID=5 AND p.pageNew=0 AND np.pageDepth >=0 AND np.pageDepth<=1 ORDER BY np.pageTreePosition ASC
    get_value(): "> [0] SELECT np.pageTreePosition FROM perch3_pages p, perch3_navigation_pages np WHERE np.pageID=p.pageID AND np.groupID=5 AND p.pagePath='/category/before-the-day/wedding-invitations' LIMIT 1
    _template_nav(): "> [2] Using template: /templates/navigation/site_navigation.html
    __construct(): ">Using template: /templates/search/search-form.html
    get(): "> [32] SELECT DISTINCT settingID, settingValue FROM perch3_settings WHERE userID=0
    set(): ">Using template: /templates/shop/checkout/customer_login.html
    _get_content(): "> [1] SELECT regionKey, regionHTML FROM perch3_content_regions WHERE regionPage='/category/before-the-day/wedding-invitations' OR regionPage='*' ORDER BY regionPage DESC
    _get_filter_sub_sql(): "> [0] SELECT DISTINCT idx.itemID FROM perch3_shop_index idx JOIN perch3_shop_products main ON idx.itemID=main.productID AND idx.itemKey='productID' AND ((idx.indexKey='_category' AND idx.indexValue LIKE 'products//%' OR idx.indexKey='_category' AND idx.indexValue='products//'))
    get_filtered_listing_from_index(): "> [nil] SELECT tbl.* FROM ( SELECT idx.itemID, main.*, idx2.indexValue as sortval FROM perch3_shop_index idx JOIN perch3_shop_products main ON idx.itemID=main.productID AND idx.itemKey='productID' JOIN perch3_shop_index idx2 ON idx.itemID=idx2.itemID AND idx.itemKey='productID' AND idx2.indexKey='title' AND idx.itemID IN (NULL) 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 AND productStatus=1 AND parentID IS NULL) GROUP BY itemID, sortval ORDER BY sortval ASC
    set(): ">Using template: /templates/shop/products/list.html
  • Yes this page exists, I need to to get 'before-the-day' and 'wedding-invitations' from the URL to filter my products by category


    This page uses a master page with the URL pattern category/[slug:cat]/[slug:subcat]


    Maybe I don't understand the routing enough, and am doing this wrong?