getViewed - Сниппет вывода просмотренных товаров для minishop2
<?php | |
$id = $modx->resource->id; | |
$tpls = explode(',', $modx->getOption('ms2_template_product_default')); | |
if (!isset($limit)) {$limit = 10;} | |
if (!isset($tpl)) {$tpl = 'tpl.msProducts.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 | |
,'element' => 'msProducts' | |
,'includeContent' => 1 | |
); | |
$config = array_merge($config, $scriptProperties); | |
return $modx->runSnippet('pdoPage', $config); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment