Skip to content

Commit

Permalink
[ADD] Product views count.
Browse files Browse the repository at this point in the history
  • Loading branch information
Seiger committed Jan 16, 2024
1 parent bb3b372 commit 3a52619
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions plugins/sCommercePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand All @@ -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);
Expand All @@ -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());
}
Expand Down

0 comments on commit 3a52619

Please sign in to comment.