Forum
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.
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 ...
For a product code that doesn't exist, these are the diagnostics ...
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
You should be able to catch the output and test it.
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:
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:
Thanks, Alex