Разделы

  
 

[Evo] Снипет отображения последних просмотренных товаров

Уважаемые,

взял тут

Стандартно можно вывести лишь url и имя.
Как вывести фотографию которая хранится в TV параметре?

Заранее, спасибо!

<?php
$mode = isset($mode) ? $mode : 'show';
$outerTpl = isset($outerTpl) ? $outerTpl : '@CODE: <h1>Вы уже смотрели:</h1><ul class="[+outer-class+]">[+rows+]</ul>';
$outerClass = isset($outerClass) ? $outerClass : 'last-view';
$rowTpl = isset($rowTpl) ? $rowTpl : '@CODE: <li><a href="[+url+]">[+name+]</a></li>';
$maxRows = isset($maxRows) ? $maxRows : 10;

if(!function_exists('fetchTpl')) {
    function fetchTpl($tpl){
        global $modx;
        $template = "";    
        if(substr($tpl, 0, 6) == "@FILE:") {
            $tpl_file = MODX_BASE_PATH . substr($tpl, 6);
            $template = file_get_contents($tpl_file);
        } else if (substr($tpl, 0, 6) == "@CODE:") {
            $template = substr($tpl, 6);
        } else if($modx->getChunk($tpl) != "") {
            $template = $modx->getChunk($tpl);
        } else {
            $template = false;
        }
        return $template;
    }
}

if(!function_exists('parseTplChunk')) {
    function parseTplChunk($tpl,$placeholder=array()){
        $chunk = fetchTpl($tpl);
        foreach ($placeholder as $key => $value){
           $chunk = str_replace("[+".$key."+]", $value, $chunk);
        }
        return $chunk;
    }
}

$item = array();

if (isset($_COOKIE['last_view']) and $_COOKIE['last_view'] != '') {
    $item = explode(',', $_COOKIE['last_view']);   
}


switch ($mode) {
    case 'register':
        if (!in_array($modx->documentIdentifier, $item)) {
            if (count($item) >= $maxRows) {
                array_shift($item);
                array_unshift($item, $modx->documentIdentifier);
            } else {
                array_unshift($item, $modx->documentIdentifier);
            }
            setcookie('last_view', implode(',', $item), time()+60*60*24*30, '/');
        }
    break;
    
    case 'show':
        
        if (!empty($item)) {
            $docs = $modx->getDocuments($item);
            $output = '';
            foreach ($docs as $doc) {
                $rows .= parseTplChunk($rowTpl, array('url'=>$modx->makeUrl($doc['id']), 'name'=>$doc['pagetitle']));
            }
            
           return parseTplChunk($outerTpl, array('rows'=>$rows, 'outer-class'=>$outerClass));
        }
    break;
}
?>

ps пытался так:
$rows .= parseTplChunk($rowTpl, array('url'=>$modx->makeUrl($doc['id']), 'name'=>$doc['pagetitle'], 'image'=>$modx->getTemplateVar('img_product_home')));

но не работает, выводит вместо значения TV параметра текст:
Array
  • +1
  • 30 января 2012, 19:13
  • senty
  • 5