Forum

Thread tagged as: PayPal

Display a message when a shop item doesn't exist

The URL for the product page is .../item.php?s=br001. (br001 is the product code and the slug). When the product exists, then perch_shop_product(perch_get('s')); works fine and displays everything using the template product.html. If the product doesn't exist, I want to display a message on the page instead.

At the moment perch_shop_product(perch_get('s')); returns nothing at all (as expected).

I've tried <perch:noresults><p>No product</p></perch:noresults> at the top of the product.html template and it doesn't work. What's the best method of displaying the message if the product is offline or is deleted from the shop.

Graham Street

Graham Street 17 points

  • 7 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

noresults should work, but I'll test it.

I wonder if I'm coding this wrong or doing something wrong?

I've tried <perch:noresults>Sorry, there are no items currently available.</perch:noresults> at the start or the end of the template product.html.

For a product code that exists, the product appears with these diagnostics ...

DIAGNOSTICS:
SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0
SELECT * FROM perch2_shop_products WHERE productStatus='Live' AND productSlug= 'br001'
SELECT categoryID FROM perch2_shop_products_to_categories WHERE productID = '2'
SELECT c.*
FROM perch2_shop_categories c, perch2_shop_products_to_categories p2c
WHERE c.categoryID=p2c.categoryID
AND p2c.productID='2'
Using template: /templates/shop/item_category.html
Using template: /templates/shop/item_category_return.html
SELECT * FROM perch2_pages WHERE pagePath='/item.php' LIMIT 1
SELECT p.* FROM perch2_shop_products p WHERE productStatus='Live' AND productSlug='br001'

For a product code that doesn't exist, these are the diagnostics ...

DIAGNOSTICS:
SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0
SELECT * FROM perch2_shop_products WHERE productStatus='Live' AND productSlug= 'br009'
SELECT * FROM perch2_pages WHERE pagePath='/item.php' LIMIT 1
SELECT p.* FROM perch2_shop_products p WHERE productStatus='Live' AND productSlug='br009'

Using template: /templates/shop/product.html
SELECT * FROM perch2_pages WHERE pagePath='/item.php' LIMIT 1
Drew McLellan

Drew McLellan 2638 points
Perch Support

I think it may actually predate noresults, looking at the code. If I had time to update it, I would.

Ah! Thanks for the offer and I understand.

What alternative solution/tests/etc could I do in product.html or in item.php (that uses that template) to check if the product/code exists. I'd rather not display a page that just contains a page header and footer, with space in the middle.

Thanks, Graham

Drew McLellan

Drew McLellan 2638 points
Perch Support

You should be able to catch the output and test it.

$result = perch_shop_product(perch_get('s'), true);
if (trim($result)) {
    echo $result;
}else{
    echo  'No result';
}

Superstar!! Works great, thanks :-)

Hi Drew - I have a similar problem to this thread, hence why I've replied here. I'm using the Paypal shop app, but cannot get noresults to work in my templates.

I've also tried the code above which doesn't work either. I'm using the following code at present:


$result = perch_shop_products_by_category(perch_get('cat'), 12); if (trim($result)) { echo $result; }else{ echo '<div class="no-products">Sorry, we have no products in this range at the moment but please check back soon!</div><hr>'; }

Do you have any idea what I might be able to do to display a no results message?

I'm using the latest version of the Paypal app, but my diagnostic is here:


SUMMARY INFORMATION Perch: 2.8.25, PHP: 5.6.10, MySQL: mysqlnd 5.0.11-dev - 20120503 - $Id: 3c688b6bbc30d36af3ac34fdd4b7b5b787fe5555 $, with PDO Server OS: Darwin, apache2handler Installed apps: content (2.8.25), assets (2.8.25), categories (2.8.25), perch_events (1.7), perch_shop_paypal (1.2.3), perch_blog (3.6.1), perch_plantcats (3.6.1) App runtimes: <?php include(PERCH_PATH.'/core/apps/content/runtime.php'); include(PERCH_PATH.'/addons/apps/perch_plantcats/runtime.php'); include(PERCH_PATH.'/addons/apps/perch_shop_paypal/runtime.php'); include(PERCH_PATH.'/addons/apps/perch_events/runtime.php'); include(PERCH_PATH.'/addons/apps/perch_blog/runtime.php'); ?> PERCH_LOGINPATH: /admin PERCH_PATH: /Users/alexbennett/Desktop/Job Folder/Cooks Lane Herbs/Test-website/admin PERCH_CORE: /Users/alexbennett/Desktop/Job Folder/Cooks Lane Herbs/Test-website/admin/core PERCH_RESFILEPATH: /Users/alexbennett/Desktop/Job Folder/Cooks Lane Herbs/Test-website/admin/resources Image manipulation: GD PHP limits: Max upload 32M, Max POST 32M, Memory: 128M, Total max file upload: 32M F1: dc1fef2ad0fcd9f943c02ebb43d85dbc Resource folder writeable: Yes HTTP_HOST: cookslaneherbs:8888 DOCUMENT_ROOT: /Users/alexbennett/Desktop/Job Folder/Cooks Lane Herbs/Test-website REQUEST_URI: /admin/core/settings/diagnostics/ SCRIPT_NAME: /admin/core/settings/diagnostics/index.php

Thanks, Alex