Skip to content

Instantly share code, notes, and snippets.

@denysbutenko
Last active December 12, 2015 02:58
Show Gist options
  • Save denysbutenko/4703399 to your computer and use it in GitHub Desktop.
Save denysbutenko/4703399 to your computer and use it in GitHub Desktop.
getViewed
<?php
$id = $modx->resource->id;
$tpls = explode(',', $modx->getOption('minishop.goods_tpl'));
if (!isset($limit)) {$limit = 10;}
if (!isset($tpl)) {$tpl = 'tpl.msGoods.row';}
// Вносим ID просмотренных товаров
if (in_array($modx->resource->template, $tpls)) {
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;
}
}
// Если указано действие returnViewed - выводим просмотренные товары
if ($action == 'returnViewed') {
$ids = array_reverse($_SESSION['viewed']);
if (empty($ids)) {return;}
$config = array(
'resources' => '-'.$modx->resource->id.','.implode(',', $ids)
,'parents' => -1
,'tpl' => $tpl
,'limit' => $limit
,'includeTVs' => 1
,'includeTVList' => 'all_needed_tvs'
);
$config = array_merge($config, $scriptProperties);
return $modx->runSnippet('msGetResources', $config);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment