Skip to content

Instantly share code, notes, and snippets.

@andronex
Created March 18, 2016 11:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save andronex/133ca9e3a2844f667e6f to your computer and use it in GitHub Desktop.
Save andronex/133ca9e3a2844f667e6f to your computer and use it in GitHub Desktop.
Вывод последних просмотренных товаров
<?php
$id = $modx->resource->id;
if (!isset($limit)) {$limit = 4;}
// Добавляем просмотренный товар MS2 в сессию
if ($modx->resource->get('class_key') == 'msProduct') {
if (!isset($_SESSION['viewedrecent'])) {
$_SESSION['viewedrecent'] = array($id);
}
else {
if (in_array($id, $_SESSION['viewedrecent'])) {
$key = array_search($id, $_SESSION['viewedrecent']);
unset($_SESSION['viewedrecent'][$key]);
}
if (count($_SESSION['viewedrecent']) > $limit) {
array_shift($_SESSION['viewedrecent']);
}
$_SESSION['viewedrecent'][] = $id;
}
}
// Выводим просмотренные товары
if ($scriptProperties['returnViewed']) {
$ids = @array_reverse($_SESSION['viewedrecent']);
if (empty($ids)) {return;}
$tplWrap = '@INLINE <div class="box new-products hidden-xs">
<div class="box-heading">Вы уже смотрели<span class="sale_gadget"> (<span>кликните здесь</span>)</span></div>
<div class="box-content">
<div class="box-product">
<ul class="row">
[[+output]]
</ul>
</div>
</div>
</div>';
$config = array(
'resources' => '-'.$modx->resource->id.','.implode(',', $ids)
,'parents' => 0
,'depth' => 0
,'context' => 'web'
,'limit' => $limit
,'tpl' => 'last.tpl'
,'nestedChunkPrefix' => 'parse_'
,'fastMode' => 1
,'prepareSnippet' => 'prepareMain'
,'tplWrapper' => $tplWrap
,'wrapIfEmpty' => 0
);
//$config = array_merge($config, $scriptProperties);
$rows = $modx->runSnippet('msProducts', $config);
if (!empty($rows)) {
return $rows;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment