Hi there!
I have a snippet for display Last viewed products (miniShop2)
<?php
$id = $modx->resource->id;
if (!isset($limit)) {$limit = 12;}
if (!isset($show)) {$show = 0;}
if (!isset($snippet)) {$snippet = 0;}
if (!isset($parents)) {$parents = 0;}
if (!isset($thumbs)) {$thumbs = '300x300';}
if (!isset($tpl)) {$tpl = 'store.Product.Viewed.Inner';}
if (!isset($except)) {$except = 0;} else {$except = split(",",$except);}
if($except != false) {
$add = 1;
foreach ($except as $value) {
if($value == $id) {$add = 0;}
}
}
if ($add != false) {
if (!isset($_SESSION['viewed'])) {
$_SESSION['viewed'] = array($id);
}
else {
if (in_array($id, $_SESSION['viewed'])) {
$key = array_search($id, $_SESSION['viewed']);
unset($_SESSION['viewed'][$key]);
}
if (count($_SESSION['viewed']) > $limit) {
array_shift($_SESSION['viewed']);
}
$_SESSION['viewed'][] = $id;
}
}
if ($show == '1') {
if (!isset($_SESSION['viewed'])) {
return;
}
$ids = array_reverse($_SESSION['viewed']);
if (empty($ids)) {
return;
}
}
if ($show == '1' && $snippet == false) {
$output = '';
foreach ($ids as $tsID) {
if($tsID != $id) {
$row = $modx->getObject('modResource', $tsID)->toArray();
$output .= $modx->getChunk($tpl, $row);
}
}
return $output;
}
if ($show == '1' && $snippet != false) {
$config = array(
'resources' => '-'.$id.','.implode(',', $ids),
'parents' => $parents,
'limit' => $limit,
'tpl' => $tpl,
'tplOuter' => $tplOuter,
'includeThumbs' => $thumbs
);
$config = array_merge($config, $scriptProperties);
$rows = $modx->runSnippet('msProducts', $config);
if (!empty($rows)) {
return $modx->getChunk('store.Product.Viewed.Outer', array('title' => $title, 'rows' => $rows));
}
}
How to add a button «Clear list»?
[ed. note: ezersky last edited this post 8 years ago.]