From 62a0cd6e22e45efb45c9e9b0a2197eef57eadd8d Mon Sep 17 00:00:00 2001 From: Stanislav Date: Wed, 21 Nov 2018 18:52:17 +0300 Subject: [PATCH] Handling a nonexistent product item --- pages/product.htm | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pages/product.htm b/pages/product.htm index f5376e3..b701291 100755 --- a/pages/product.htm +++ b/pages/product.htm @@ -6,4 +6,14 @@ [product] slug = "{{ :slug }}" == -{% component 'product' %} \ No newline at end of file +function onEnd() { + $slug = $this->param('slug'); + $product = Xeor\OctoCart\Models\Product::where('slug', $slug)->first(); + if (!$product) { + $this->setStatusCode(404); + return $this->controller->run('404'); + } + $this->page->title = $product->title; +} +== +{% component 'product' %}