-
-
Save Ibochkarev/e080fa2ecd10aabe9d85039454eab127 to your computer and use it in GitHub Desktop.
Вывод последних просмотренных товаров
This file contains 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; | |
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