-
-
Save Sentinel-7/74f932ac00af820e72248e908742f772 to your computer and use it in GitHub Desktop.
getViewed - Сниппет вывода просмотренных товаров для minishop2
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('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
{'!getViewed' | snippet: [ 'action' => 'returnViewed', 'includeThumbs' => 'bigwebp', 'limit' => 3 ]}