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: Question, Docs, Shop

Creating a list detail page

Hi,

I'm attempting to follow this guide:

https://docs.grabaperch.com/perch/content/functions/how-do-i-create-list-detail-pages/

The page is picking up the slug, according to the page debug, but the region isn't being populated with the product info. I'm using the templates shown on that page.

Many thanks in advance, Chris

The code on the page in question

    <?php

    perch_content_create('Event', array(
          'template'  => 'product_detail.html',
          'multiple'  => true,
          'edit-mode' => 'listdetail',
     ));

    if (perch_get('s')) {
     // Detail mode
     perch_content_custom('Event', array(
          'page' => '/event.php',
          'template' => 'product_detail.html',
          'filter' => 'slug',
          'match' => 'eq',
          'value' => perch_get('s'),
          'count' => 1,
     ));
    } else {
     // List mode
     perch_content_custom('Event', array(
          'page' => '/event.php',
          'template' => 'product_listing.html',
     ));
    }

    ?>

The page debug which appears to know to use product_detail.html from the slug

Debug Message - Perch 3.0.13
[53] SELECT DISTINCT settingID, settingValue FROM perch3_settings WHERE userID=0
[1] SELECT * FROM perch3_pages WHERE pagePath='/event.php' LIMIT 1
[1] SELECT * FROM perch3_shop_cart WHERE cartID=27
[1] SELECT * FROM perch3_shop_cart WHERE cartID=27
[1] SELECT regionKey, regionHTML FROM perch3_content_regions WHERE regionPage='/event.php' OR regionPage='*' ORDER BY regionPage DESC
[1] SELECT regionID, regionTemplate, regionPage, regionRev AS rev FROM perch3_content_regions WHERE regionKey='Event' AND (regionPage='/event.php' OR regionPage='*')
[nil] SELECT * FROM ( SELECT idx.itemID, c.regionID, idx.pageID, c.itemJSON, idx2.indexValue as sortval FROM perch3_content_index idx JOIN perch3_content_items c ON idx.itemID=c.itemID AND idx.itemRev=c.itemRev AND idx.regionID=c.regionID JOIN perch3_content_index idx2 ON idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev AND idx2.indexKey='_order' WHERE ((idx.regionID=13 AND idx.itemRev=0)) AND ((idx.indexKey='slug' AND idx.indexValue='who-lives-in-our-woods-easter-trail-nature-club-march-2018')) AND idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev ) as tbl GROUP BY itemID, pageID, itemJSON, sortval, regionID ORDER BY sortval ASC LIMIT 0, 1
Using template: /templates/content/product_detail.html

Diagnostic report

Perch: 3.0.13, PHP: 7.1.13, MySQL: mysqlnd 5.0.12-dev - 20150407 - $Id: b396954eeb2d1d9ed7902b8bae237b287f21ad9e $, with PDO
Server OS: Linux, cgi-fcgi
Installed apps: content (3.0.13), assets (3.0.13), categories (3.0.13), perch_blog (5.6.1), perch_forms (1.10), perch_shop_orders (1.2.5), perch_shop_products (1.2.5), perch_shop (1.2.5), perch_members (1.6.2), pipit_catalog (1.1.0)
App runtimes: <?php $apps_list = [ 'content', 'categories', 'perch_blog', 'perch_forms', 'perch_members', 'perch_shop', ];
PERCH_LOGINPATH: /perch
PERCH_PATH: /homepages/21/d688763965/htdocs/utt/perch
PERCH_CORE: /homepages/21/d688763965/htdocs/utt/perch/core
PERCH_RESFILEPATH: /homepages/21/d688763965/htdocs/utt/perch/resources
Image manipulation: GD
PHP limits: Max upload 64M, Max POST 64M, Memory: 256M, Total max file upload: 64M
F1: 3b606135b33e6a102526838f4152a807
Resource folder writeable: Yes
HTTP_HOST: www.***.org.uk
DOCUMENT_ROOT: /kunden/homepages/21/d688763965/htdocs/utt
REQUEST_URI: /perch/core/settings/diagnostics/
SCRIPT_NAME: /perch/core/settings/diagnostics/index.php
Chris McMahon

Chris McMahon 0 points

  • 1 year ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Are you intending to use two different regions here? You have Event and Products.

Just noticed that, have changed both to Event.

The problems persists, though.

Drew McLellan

Drew McLellan 2638 points
Perch Support

It seems odd that it's looking for revision zero. Does the itemRev=0 value in the debug change if you re-save the content region?

Yes, has incremented to 1.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Hmm, that's something at least. And list mode works just fine?

Unfortunately neither mode works. My assumption is that I've overlooked something, but I can't see what it could be.

Should I be adding anything to the Region via the Perch Admin pages?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Is this page /event.php ?

Yep, that's the page that gives the debug output in the second block above.

I'm open to starting again if there's a better way to set up my product (event) pages. I noted that the default setup was:

/product/slug/

Rather than:

/product.php?s=slug

I'm new to Perch, so if there are other examples I can follow rather than the one linked above I'd be happy to.

Drew McLellan

Drew McLellan 2638 points
Perch Support

No, that should be fine, and this is exceptionally simple functionality. I've no idea what the problem could be.

What does this output?

perch_content('Event');

This code:

    perch_content_create('Event', array(
      'template'  => 'product_detail.html',
      'multiple'  => true,
      'edit-mode' => 'listdetail',
     ));

     perch_content('Event');

Gives me this output on the page debug:

SELECT DISTINCT settingID, settingValue FROM perch3_settings WHERE userID=0
[1] SELECT * FROM perch3_pages WHERE pagePath='/event.php' LIMIT 1
[1] SELECT * FROM perch3_shop_cart WHERE cartID=27
[1] SELECT * FROM perch3_shop_cart WHERE cartID=27
[1] SELECT regionKey, regionHTML FROM perch3_content_regions WHERE regionPage='/event.php' OR regionPage='*' ORDER BY regionPage DESC
Drew McLellan

Drew McLellan 2638 points
Perch Support

But no content?

None. Should I be adding something to that region in the Perch Admin?

Drew McLellan

Drew McLellan 2638 points
Perch Support

How much content is in the region?

I'm unsure what you mean. As far as I understood it I create the region in event.php using:

<?php  perch_content_create('Event', array( 
'template' => 'product_detail.html', 
'multiple' => true, 
'edit-mode' => 'listdetail', 
));

Then I populate the region with this:

    if (perch_get('s')) {
      // Detail mode
      perch_content_custom('Event', array(
        'page' => '/event.php',
        'template' => 'product_detail.html',
        'filter' => 'slug',
        'match' => 'eq',
        'value' => perch_get('s'),
        'count' => 1,
     ));
    } else {
      // List mode
      perch_content_custom('Event', array(
        'page' => '/event.php',
        'template' => 'product_listing.html',
     ));
    }

Have I got this mixed up?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Then I populate the region with this:

That's not populating anything. That's displaying the region as either a list, or a single item in detail.

You need to actually add some content, or there's nothing to show. What are you expecting to see on the page?

I'm expecting to see the products I have created. I was under the impression that this would grab a product using it's slug.

As per: https://docs.grabaperch.com/perch/content/functions/how-do-i-create-list-detail-pages/

Drew McLellan

Drew McLellan 2638 points
Perch Support

Are you using the Shop app? Are you trying to list products from your shop?

Yes & yes.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, so forget the perch_content functions, they don't do what you want. Those are for content regions.

You need to use perch_shop_products() instead for the listing.

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

And perch_shop_product() for the detail.

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