$c = array(
'contentid' => $docid,
'tmplvarid' => $tvImageId,
);
$imgTVres = $modx->getCollection('modTemplateVarResource',$c);
$imgTotal_rows = $modx->getCount('modTemplateVarResource',$c);
<?php
$phpThumbOptions = 'w=210&h=220&f=jpg';
// end of settings
$output = '';
if ($modx->user->hasSessionContext($modx->context->get('key')) )
{
$user_id = $modx->user->get('id');
$tableVars = $modx->getFullTableName('site_tmplvar_contentvalues');
$tvImageId = 21;
$tvProdDescrId = 20;
$wishListDocId = $modx->documentIdentifier;
if (!empty($_GET['deleteId']) and intval($_GET['deleteId']))
{
$deleteId = intval($_GET['deleteId']);
$sql= "DELETE FROM `modx_wishlist` WHERE user_id = {$user_id} AND content_id = {$deleteId} LIMIT 1";
if ($modx->exec($sql))
$message = 'Item removed from your wishlist';
else
$message = 'Can\'t remove this item from your wishlist. Please try later';
$output .= '<div class="message">'.$message.'</div>';
}
$sql= "SELECT content_id FROM `modx_wishlist` WHERE user_id = {$user_id}";
if ($stmt = $modx->prepare($sql)
and $stmt->execute()
and $result = $stmt->fetchAll(PDO::FETCH_ASSOC))
{
$output .= '<div>';
foreach ($result as $n => $val){
$output .= '<div class="column grid_3 listing">';
$docId = $val['content_id'];
$title = ''; $parameters=array(); $imgSrc = ''; $descrSrc = '';
$parameters = array(
'id' => $docId,
'field' => 'pagetitle',
);
$title = $modx->runSnippet('getResourceField',$parameters);
$title = ($title != '') ? $title : $docId;
$imgTVres = $modx->db->select('value', $tableVars, "contentid = $docId AND tmplvarid = $tvImageId");
$imgTotal_rows = $modx->db->getRecordCount($imgTVres);
if($imgTotal_rows >= 1 ) {
$row = $modx->db->getRow($imgTVres);
$imgSrc = $row['value'];
if ($imgSrc != '') $imgSrc = '<img src='.$modx->runSnippet("phpthumbof",array('input' => $imgSrc, 'options' => $phpThumbOptions)).' title="'.$title.'" class="imgborder"/>';
}
$descrTVres = $modx->db->select('value', $tableVars, "contentid = $docId AND tmplvarid = $tvProdDescrId");
$descrTotal_rows = $modx->db->getRecordCount($descrTVres);
if($descrTotal_rows >= 1 ) {
$row = $modx->db->getRow($descrTVres);
$descrSrc = $row['value'];
}
$output .= '<h5 class="h5wish"><a href="'.$modx->makeUrl($docId).'">'.$title.'</a></h5>
<a href="'.$modx->makeUrl($docId).'"><div class="p-image">'.$imgSrc.'</div></a><br />
<div class="p-description"><p>'.$descrSrc.'</p></div>
<a href="'.$modx->makeUrl($docId).'" class="button3"><span id="buttonText">View item</span></a></h5>
<a href="'.$modx->makeUrl($wishListDocId,'','&deleteId='.$docId).'" class="button3"><span id="buttonText">Delete from wishlist</span></a>
';
$output .= '</div>';
}
$output .= '</div>';
}
else
$output .= 'Your wishlist is empty';
}
else
$output .= 'Login to view your wishlist';
return $output;