Forum

Thread tagged as: Shop

Listed product slug not linking to detail template

In Perch Shop I have listed product items all linking to their respective slug URLs. However when I click through on these it's failing to display them in the product detail template. What am I doing wrong? I am calling a variable in the function called 'product'. Does this relate to Runway setup? Unsure of this.

list template button linking to product page

<a href="/products/<perch:shop id="slug" type="slug">/"" class="button shop-button w-button">find out more</a>

product detail page

        <div class="right-col w-col w-col-8">

         <?php perch_shop_product(perch_get('product'),[
              'template' => 'products/product_detail.html',
              'filter' => 'slug',
              'match' => 'eq',
              'value' => perch_get('product')
]); ?>

        </div>

product_detail.html template

         <div class="blog-image-wrapper">
            <h2 class="shop-product-heading"><perch:shop id="title" type="text" /></h2><img src="<perch:shop type="image" id="prodImage1" class="blog-feature-image"></div>
          <div class="gallery-flex-wrap"></div>
          <div class="blog-post-wrapper">
            <<perch:shop id="description" type="text" /> 
          </div>
          <div class="shopify-wrapper">
            <div class="shopify-buy-price">
              <div class="text-block">€<span class="price"><perch:shop id="price" type="shop_currency_value"</span> inc VAT</div>
            </div>
            <div class="w-form">
              <form id="email-form" name="email-form" data-name="Email Form"><select id="Box-Size" name="Box-Size" data-name="Box Size" class="shopify-select w-select"><option value="">Choose Box Size</option><option value="First">First Choice</option><option value="Second">Second Choice</option></select></form>
              <div class="w-form-done">
                <div>Thank you! Your submission has been received!</div>
              </div>
              <div class="w-form-fail">
                <div>Oops! Something went wrong while submitting the form.</div>
              </div>
            </div><a href="#" class="button buy-now w-button">add to cart</a></div>

Diagnostics

Perch Runway: 3.1.2, PHP: 7.1.20, MySQL: 5.6.39, with PDO
Server OS: Linux, cgi-fcgi
Installed apps: content (3.1.2), assets (3.1.2), categories (3.1.2), perch_blog (5.6.1), perch_shop_orders (1.2.6), perch_shop_products (1.2.6), chirp_seo (1.2.1), perch_shop (1.2.6), perch_members (1.6.4)
App runtimes: <?php $apps_list = array( 'content', 'categories', 'perch_blog', 'perch_members', 'perch_shop', ); ?>
PERCH_LOGINPATH: /perch
PERCH_PATH: /var/www/vhosts/142/1004491/webspace/httpdocs/perch
PERCH_CORE: /var/www/vhosts/142/1004491/webspace/httpdocs/perch/core
PERCH_RESFILEPATH: /var/www/vhosts/142/1004491/webspace/httpdocs/perch/resources
Image manipulation: GD Imagick
PHP limits: Max upload 32M, Max POST 32M, Memory: 256M, Total max file upload: 32M
F1: 3b606135b33e6a102526838f4152a807
Resource folder writeable: Yes
HTTP_HOST: www.lirchocolates.com
DOCUMENT_ROOT: /var/www/vhosts/142/1004491/webspace/httpdocs
REQUEST_URI: /perch/core/settings/diagnostics/
SCRIPT_NAME: /perch/core/settings/diagnostics/index.php
Cormac Kerrigan

Cormac Kerrigan 0 points

  • 2 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Have you set up a route for /product/slug ?

Hi Drew, do you mean in Perch Runway settings? The product URL is set to; /product/{slug}

It loads the /product/slug into the address bar, but it displays a 404 page not found error.

Perhaps I'm misunderstanding the Perch Shop on Runway. By Routing, do you mean the shop's product detail page require some sort of master page like you would a pages app template? therefore allowing dynamic pages to be displayed? If so do you have examples of this or do I just work off the default?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes, there's a description of how it works here: https://docs.grabaperch.com/runway/routing/

Hi Drew, thanks for that. Something that's jumping out at me in the docs in "Find the page and click on Page Options" My /shop/product.php or /shop/index.php pages are not appearing in my Pages Listing on the Perch control panel, so therefore I can't action this. It seems odd as I've included the Perch string on the top of each page. Should they be appearing?

<?php include('../perch/runtime.php');?>

I've also tried with this string

<?php include($_SERVER['DOCUMENT_ROOT'].'/perch/runtime.php'); ?>

When I click on the pages section within my Perch Runway I see a Routes section, but I don't have the ability to add new routes? Why?

Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

Hello Cromac,

If you are using Runway, you should be creating master pages in templates/pages and adding pages via the control panel: https://docs.grabaperch.com/runway/core-tasks/master-pages/

Hi Hussein, Thanks for your response. I've added a new master page here called product.php, this is the code below:

<?php include($_SERVER['DOCUMENT_ROOT'].'/perch/runtime.php'); ?>

<?php perch_layout('shop.header'); ?>

  <div class="brand shop-hero">
    <div class="container">
      <div class="logo-wrapper"><img src="../images/lir-master-light-horiz2.png" srcset="../images/lir-master-light-horiz2-p-1080.png 1080w, ../images/lir-master-light-horiz2-p-1600.png 1600w, ../images/lir-master-light-horiz2.png 1687w" sizes="(max-width: 479px) 72vw, (max-width: 991px) 40vw, 32vw" class="logo"></div>
    </div>
  </div>
  <div class="container"></div>
  <div class="product">
    <div class="container">
      <div class="blog-posting w-row">
        <div class="left-col w-col w-col-4">

                 <?php perch_categories([
                'template' => 'category.html',
                'category' => 'shop/'.perch_get('category'),
          ]
            ); ?>
            <a href="../shop/index.php" class="button b2b w-button">back to shop</a>
          <div class="share">
            <h3>share this post</h3>
          </div>
          <div class="sharethis">
            <div class="sharethiscode w-embed">
              <div class="sharethis-inline-share-buttons"></div>
            </div>
          </div>
        </div>
        <div class="right-col w-col w-col-8">

            <?php perch_shop_product(perch_get('product'));?>


        </div>
      </div>
    </div>
  </div>
<?php perch_layout('blog.footer'); ?>

In Perch Admin I've updated the route pattern URL for this master page to be :

/shop/products/{slug}

I've updated the list template to point to:

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

This still doesn't work. How do I make the unique detail page pick up this master page template? It's still giving me a page 404

Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

Since you are using Runway, you don't to include the Perch runtime file. So you can remove this:

<?php include($_SERVER['DOCUMENT_ROOT'].'/perch/runtime.php'); ?>

Since you are using perch_get('product'), your route should be:

shop/products/[slug:product]

Hi Hussein, No problem. Removed that string from the products.php master template and updated the route URL pattern to

/shop/products/[slug:product]

Issue still remains; clicking on an item in the listing page, loads the URL expected but not the page; leaves a 404 error.

Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

You also need to remove the slash at the start.

Hussein Al Hammad said:

You also need to remove the slash at the start.

It was removed in the URL to begin with. I tested with both slash removed and present and it made no difference.

Just to note in Perch Admin settings for Product URL I also have this:

shop/products/{slug}

Again it makes no difference. It's like the product is not able to take to the master page?

Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

So you have:

  1. Created a master page in templates/pages
  2. Added the page via the control panel (assuming with the URL /shop/products) - can you confirm you can visit this page /shop/products?
  3. Added a route with shop/products/[slug:product]
  4. Tried visiting /shop/products/my-product-slug but you're still getting a 404?

Hussein Al Hammad said:

So you have:

  1. Created a master page in templates/pages
  2. Added the page via the control panel (assuming with the URL /shop/products) - can you confirm you can visit this page /shop/products?
  3. Added a route with shop/products/[slug:product]
  4. Tried visiting /shop/products/my-product-slug but you're still getting a 404?
  1. Yes.
  2. I hadn't actually added the page in Perch as it had already existed. I just added it now and called it Product, using the master page template (that I just created). And yes I can successfully view this page I created at /shop/product.php *Should I delete this page from the server and re-add again?
  3. Yes
  4. Tried again linking to /shop/products/my-product-slug and still getting a 404.

Okay, so obviously the successful product page I was seeing was the one that was there on the server already. I deleted this and attempted to add a page called product with the path /shop/product.php and it is failing. I also re-updated it's URL pattern to shop/products/{slug} and it's still failing with a 404. So it is not recognising this master template?

Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

When you go to the page in the control panel and click on the "Location" tab, what do you see in the "Path" field? And what do you see in the "URL pattern" field?

When I created the page using the product.php master template, the debug tells me I'm using a different template... why?

Debug Message - Perch Runway 3.1.2
[1] SELECT u.*, r.* FROM perch3_users u, perch3_user_roles r WHERE u.roleID=r.roleID AND u.userEnabled=1 AND u.userID=1 AND u.userHash='59070fb28ce21e28c4c453cf86c5d87a' LIMIT 1
UPDATE perch3_users SET userHash='8984584ab6af2b9423325d9da9b378f6' WHERE userID='1'
[46] SELECT settingID, settingValue, userID FROM perch3_settings WHERE userID=1 OR userID=0 ORDER BY userID ASC
[12] SELECT itemValue FROM perch3_menu_items WHERE itemType='app'
[1] SELECT * FROM perch3_pages WHERE pageID=11 LIMIT 1
Using template: /templates/pages/attributes/default.html
Using sub-template: /templates/pages/attributes/seo.html
Setting alert: Your page has been successfully created. Return to page listing (success)
[1] SELECT mi.*, p.privKey FROM perch3_menu_items mi LEFT JOIN perch3_user_privileges p ON mi.privID=p.privID WHERE mi.itemActive=1 AND mi.parentID=0 ORDER BY itemOrder ASC LIMIT 0, 1
[7] SELECT mi.*, p.privKey FROM perch3_menu_items mi LEFT JOIN perch3_user_privileges p ON mi.privID=p.privID WHERE mi.itemActive=1 AND mi.parentID=1 ORDER BY mi.itemOrder ASC
[1] SELECT itemTitle FROM perch3_menu_items WHERE itemType='app' AND itemValue='content' LIMIT 1
[1] SELECT mi.*, p.privKey FROM perch3_menu_items mi LEFT JOIN perch3_user_privileges p ON mi.privID=p.privID WHERE mi.itemActive=1 AND mi.parentID=0 ORDER BY itemOrder ASC LIMIT 1, 10
[2] SELECT mi.*, p.privKey FROM perch3_menu_items mi LEFT JOIN perch3_user_privileges p ON mi.privID=p.privID WHERE mi.itemActive=1 AND mi.parentID=2 ORDER BY mi.itemOrder ASC
File: /core/apps/content/modes/page.details.post.php
Queries: 11
Memory: 2.5321

Hussein Al Hammad said:

When you go to the page in the control panel and click on the "Location" tab, what do you see in the "Path" field? And what do you see in the "URL pattern" field?

/shop/product.php

The URL pattern field is blank, so I add in:

shop/products/{slug}

Cormac Kerrigan said:

Hussein Al Hammad said:

When you go to the page in the control panel and click on the "Location" tab, what do you see in the "Path" field? And what do you see in the "URL pattern" field?

/shop/product.php

The URL pattern field is blank, so I add in:

shop/products/{slug}

If I'm adding a page called Product, what should the URL segment read?