Last active
May 15, 2016 01:02
-
-
Save fomigo/5559983 to your computer and use it in GitHub Desktop.
просмотренные страницы
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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