Forum

Thread tagged as: Shop

Product Detail page

how do i redirect to a product detail page? when using the tag: perch_shop_products();

using this:

perch_shop_product('test', [
   'template' => 'shop/products/product.html'
]);

and getting this: Sorry, that page could not be found.

And how to make it dynamically? Using the product slug?

Ali Vonsensey

Ali Vonsensey 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Sorry, do you mean how do you link to the product detail page from the listing?

What's the URL of the product detail page?

Drew McLellan said:

Sorry, do you mean how do you link to the product detail page from the listing?

What's the URL of the product detail page?

Yes And i created a page called: Products

Want to navigate to product detail page when clicking on the product (Test)

Rachel Andrew

Rachel Andrew 394 points
Perch Support

You need to create a page, then use perch_shop_product() on that page passing in the slug from the QueryString:

https://docs.grabaperch.com/addons/shop/products/functions/perch-shop-product/

Your listing needs to link to that page from the template. Editing Shop templates is the same as editing any other Perch templates - copy them into perch/templates and edit them or add your own.

I am still having issues with this, I must be missing something obvious. I am not a php dev, so may explain it.

So I have created a page for the 'product listing’ & 'product detail page’ which sit in a folder called shop within the root both use their respective default functions & default templates just while I learn the shop ropes.

  • perch_shop_products( ); function on the listing page
  • perch_shop_product(‘a product slug'); function on the detail page

If I test each page in the browser all is OK, in that they both fire their respective templates, the product lists shows all products, the product detail shows a product if I add a slug, or all products in a bit more detail if none parsed.

So to rephrase this thread, how do I pass the ‘slug’ as a query to the product_shop_product() function from the listing page once I click on the product link.

As Rachel mentioned I need to tell the list.html <a> element to look for the product details page, the default template is

<a href="/shop/products/<perch:shop id="slug" type="slug" />/“>

I updated to this

<a href="/shop/products/product.php?s=<perch:shop id="slug" type="slug" />/">

I have blog installed and no issues setting that up, I looked at how that handles passing the query from the blog/index.php to blog/post.php so tried something similar like this perch_shop_product(perch_get('s')); and tweaking the template, but I’m just missing something obvious I know it!

Any help appreciated

@Mike

You running Perch or Perch Runway?, I use Runway

I solved it with token (https://docs.grabaperch.com/runway/routing/custom-tokens/)

I'm on standard perch

Ok thanks Ali, I will take a look. I need to buy a dev runway licence anyway, so think I will do that and start afresh rather than mess up my other installs.

yeah, i think its better, runway is way better then old perch :) you can do a lot more stuff :)

i have this setting:

//file: perch->config->runway.php

        'routing_tokens' => [
            'productSlug' => '.*' //match all (regex)
        ],  

then go to the product page via dashboard and click Page Options And in the URL pattern, you then add:

product/[productSlug:s]

that should work, it worked for me :)