We are transitioning over to a new forum platform. Please post new issues there. Existing threads will be dealt with here unless you choose to move them over. Visit the new forum

Forum

Thread tagged as: Problem, Runway, Shop

404 Routing Shop Categories

I have a navigation bar that routes categories from the set "Products" with the following path: /products/cat/subcat/etc The pages in the nav are showing up with proper links, and the /products page which displays the product list from a particular category currently has this function, but I end up with a 404 error on the page.

<?php 
     perch_shop_products ('Products', array[
          'count'      => 10,
          'category' => perch_get('cat'),
     ]);
?>
Kevin Wolff

Kevin Wolff 0 points

  • 1 year ago
Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

Hello Kevin,

Do you have any routes set up for /products? If not, go to the page and add the routes under the Location tab.

https://docs.grabaperch.com/runway/routing/

Yes, I originally routed the page to /products/[slug] but didn't know which tags to use so that it would recognize more than one slug for categories with children.

Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

If you only look for parent categories, you would use products/[slug:cat]. If you want to include sub categories too, check out this thread: http://forum.grabaperch.com/forum/02-13-2018-perch-shop-url-advice

Thanks - I have used the link you provided to adjust my routes so that it shows products/[slug/slug:catPath]. Now the pages don't return a 404 when the category links are pressed, they just show a completely blank page as if the template is not being pulled. Below is my master page for the product category listing and the list template.

Master Page:

perch_shop_products('Products', array[
        'template' => 'list.html',
        'count'    => 10,
        'category' => perch_get('cat'),
    ]);

Product List Template:

<perch:before>
    <div class="wrapper cols2-nav-right">

        <div class="primary-content">
<h1>Products</h1>
<ul class="listing">
</perch:before>
<li>
    <a href="/product/<perch:shop id="slug" type="slug" />/">
        <perch:shop id="title" type="text" />
    </a>

    <perch:if not-exists="has_variants">
        <perch:form id="add_to_cart" app="perch_shop" action="/bag">
            <perch:input id="product" type="hidden" value="<perch:shop id="productID" env-autofill="false" />" />
            <perch:input type="submit" value="Add To Bag" />
        </perch:form>
    </perch:if>
</li>
<perch:after>
</ul>
</div>
</div>
</perch:after>
Drew McLellan

Drew McLellan 2638 points
Perch Support

What routes do you have configured that start with products, and what order are they in?

products/[slug:catPath]

Then

products/[slug/slug:catPath]

Drew McLellan

Drew McLellan 2638 points
Perch Support

That looks ok. If you turn on debug, what does it output for the page that isn't working? The routing information is at the top of the debug.

Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

You are using array[] which I think would result in a syntax error.

You also have an extra argument. You are using perch_shop_products(string, array) - the first argument should be an array as far as I know.

One last thing, perch_get('cat') in your case doesn't return the full category path. It would return category/subcategory rather than set/category/subcategory/.

Try this:

$catPath = perch_get('cat');

perch_shop_products([
'template' => 'list.html',
'count' => 10,
'category' => "products/$catPath/",
]);

I have adjusted the code in the master with the template set to 'template' => 'products/list.html', - now the page is loading the header and footer properly, but the template has no information in it and shows up blank. The debug results seem to be using the template properly, but there's not even the H1 from the template that should output regardless of content beneath.

Debug Message - Perch Runway 3.1.1
[36] 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
Matched route: products/[slug:catPath]
Using master page: /templates/pages/shop/products.php
Page arguments:

Array
(
    [0] => /products/led
    [catPath] => led
    [1] => led
)

[64] SELECT DISTINCT settingID, settingValue FROM perch3_settings WHERE userID=0
[1] SELECT * FROM perch3_pages WHERE pagePath='/products' LIMIT 1
[1] SELECT * FROM perch3_shop_cart WHERE cartID=905
[1] SELECT * FROM perch3_shop_cart WHERE cartID=905
[nil] SELECT * FROM perch3_shop_sales WHERE saleFrom<='2018-04-13 22:35:00' AND saleTo>'2018-04-13 22:35:00' AND saleActive=1 AND saleDeleted IS NULL ORDER BY saleOrder ASC
Using template: /templates/search/search-nav.html
[1] SELECT setID FROM perch3_category_sets WHERE setSlug='products' LIMIT 1
[26] SELECT main.* FROM perch3_categories main WHERE 1=1 AND setID=1 ORDER BY catTreePosition ASC
[26] Using template: /templates/categories/mobile-shop-cats.html
[10] SELECT * FROM perch3_pages WHERE pageNew=0 AND pageHidden=0 AND pageDepth >=0 AND pageDepth<=2 ORDER BY pageTreePosition ASC
[1] SELECT pageTreePosition FROM perch3_pages WHERE pagePath='/products' LIMIT 1
[1] SELECT pageID FROM perch3_pages WHERE pageTreePosition IN ('000-002', '000') ORDER BY pageTreePosition DESC
Using template: /templates/navigation/mobile-item.html
[3] Using template: /templates/navigation/mobile-subitem.html
[3] Using template: /templates/navigation/mobile-subitem.html
[1] SELECT setID FROM perch3_category_sets WHERE setSlug='products' LIMIT 1
[26] SELECT main.* FROM perch3_categories main WHERE 1=1 AND setID=1 ORDER BY catTreePosition ASC
[26] Using template: /templates/categories/nav-shop-cats.html
[10] SELECT * FROM perch3_pages WHERE pageNew=0 AND pageHidden=0 AND pageDepth >=0 AND pageDepth<=2 ORDER BY pageTreePosition ASC
[1] SELECT pageTreePosition FROM perch3_pages WHERE pagePath='/products' LIMIT 1
[1] SELECT pageID FROM perch3_pages WHERE pageTreePosition IN ('000-002', '000') ORDER BY pageTreePosition DESC
Using template: /templates/navigation/item.html
[3] Using template: /templates/navigation/subitem.html
[3] Using template: /templates/navigation/subitem.html
[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//'))
[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 LIMIT 0, 10
Using template: /templates/shop/products/list.html
Using template: /templates/mailchimp/forms/subscribe.html
[1] SELECT setID FROM perch3_category_sets WHERE setSlug='products' LIMIT 1
[26] SELECT main.* FROM perch3_categories main WHERE 1=1 AND setID=1 ORDER BY catTreePosition ASC
[26] Using template: /templates/categories/footer-shop-cats.html
[1] SELECT groupID FROM perch3_navigation WHERE groupSlug='footer' LIMIT 1
[10] 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=1 AND p.pageNew=0 AND np.pageDepth >=0 AND np.pageDepth<=2 ORDER BY np.pageTreePosition ASC
[0] SELECT np.pageTreePosition FROM perch3_pages p, perch3_navigation_pages np WHERE np.pageID=p.pageID AND np.groupID=1 AND p.pagePath='/products' LIMIT 1
Using template: /templates/navigation/footer-item.html
[4] Using template: /templates/navigation/footer-subitem.html
[2] Using template: /templates/navigation/footer-subitem.html
[1] SELECT regionKey, regionHTML FROM perch3_content_regions WHERE regionPage='/products' OR regionPage='*' ORDER BY regionPage DESC
Request time: 0.0409
Process time: 0.0408
Memory: 1.0895
Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

If products/[slug:catPath] is your route, you need to use perch_get('catPath') not perch_get('cat').

Thank you guys, it's working now!