From 3a52619d9bca4b065f2f9f8951ac09a92d42caa5 Mon Sep 17 00:00:00 2001 From: Serhii Korneliuk Date: Tue, 16 Jan 2024 18:30:33 +0200 Subject: [PATCH] [ADD] Product views count. --- plugins/sCommercePlugin.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/plugins/sCommercePlugin.php b/plugins/sCommercePlugin.php index 2083f20..b9e9715 100644 --- a/plugins/sCommercePlugin.php +++ b/plugins/sCommercePlugin.php @@ -40,6 +40,7 @@ if (isset($aliasArr[0]) && $aliasArr[0] == evo()->getConfig('lang', 'base')) { unset($aliasArr[0]); } + $alias = implode('/', $aliasArr); $document = sCommerce::documentListing()[$alias] ?? false; if (!$document && evo()->getLoginUserID('mgr')) { @@ -49,6 +50,7 @@ $document = (int)$product->id; } } + if ($document) { $product = sCommerce::getProduct($document, evo()->getConfig('lang', 'base')); $product->constructor = data_is_json($product->constructor, true); @@ -69,6 +71,13 @@ $product->deleted = 0; $product->cacheable = 1; + if (sCommerce::config('product.views_on', 1) == 1) { + if (!in_array($product->id, $_SESSION['s_commerce_product_views'] ?? [])) { + $product->increment('views'); + $_SESSION['s_commerce_product_views'][] = $product->id; + } + } + unset($product->tmplvars); return $params['documentObject'] = Arr::dot($product->toArray()); }