Hello everybody,
I've read tons of posts on this forum without finding a solution. I would like to show an image from an external link on my recently viewed frame. The link to the image is saved in a custom field named ext_img with a layout position set to image. The problem is that $v->customfieldsSorted['image'] results always empty.
I use the same code for the product view layout and it works perfectly.
Does anybody know the solution? Thanks for your help!
<?php
defined ( '_JEXEC' ) or die ( 'Restricted access' );
if(!isset($_SESSION['recent']))
$_SESSION['recent'] = array();
if(!in_array($this->product->virtuemart_product_id,$_SESSION['recent'])){
$_SESSION['recent'][] = $this->product->virtuemart_product_id;
if(count($_SESSION['recent']) > 5){
array_shift($_SESSION['recent']);
}
}
$product_model = VmModel::getModel('product');
$products = $product_model->getProducts($_SESSION['recent']);
$product_model->addImages($products,1);
if(count($products) > 1){
echo '<ul class="recentproducts">';
$i=1;
foreach($products as $v){
foreach ($v->categoryItem as $key=>$prod_cat) {
$virtuemart_category_name=$prod_cat['category_name'];
}
//var_dump($v);
if($v->virtuemart_product_id == $this->product->virtuemart_product_id )
continue;
if ($v->virtuemart_product_id >0){
//echo '<h3 class="module-title item'.$i.'">'.JText::_('RECENTLY_VIEWED_PRODUCTS').'</h3>';
echo '<li>';
echo '<div class="box-style">';
//removed
//$thumb = !empty($v->images[0]) ? $v->images[0]->displayMediaThumb('class="image"', false, 'class="modal"', true, false) : '';
//end removed
//added
$custom_title = null;
foreach ($v->customfieldsSorted['image'] as $field) {
if ($field->display) {
if ($field->custom_title != $custom_title) {
$thumb = '<img src="'.$field->display.'" alt="'.$v->product_name.'">';
}
}
}
//end-added
echo '<div class="browse">'.$thumb.'</div>';
echo '<div class="button-box-mia-recent2">';
echo JHTML::link ( JRoute::_('index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id='.$v->virtuemart_product_id.'&virtuemart_category_id='.$v->virtuemart_category_id), $v->product_name , array ('title' => $v->product_name ) );
echo '<br>in '.JText::_('RECENTLY_CATEGORY_PRODUCTS').' ' .JHTML::link ( JRoute::_('index.php?option=com_virtuemart&view=category&virtuemart_category_id='.$v->virtuemart_category_id), $virtuemart_category_name) ;
// echo ( JRoute::_('<br>'.$v->prices['basePrice'])) ;
$prezzo = $this->currency->createPriceDiv('salesPrice','',$v->prices);
echo '<font color="#e74c3c">'.$prezzo.'</font>';
echo '</div>';
echo '<div class="button-box-mia-recent">';
echo '<div class="button-box-mia">';
echo "<a target=\"_blank\" class=\"button\" href=\"".$v->product_url."\">SHOP NOW</a>";
echo '<div class="image-manu">';
echo '<img src="images/stories/virtuemart/manufacturer/'.$v->mf_name.'.png"></div>' ;
echo '</div></div></div>';
echo '</li>';
$i++;
}
}
echo '</ul>';
}
?>
I've found a workaround, it's a bit dirty but it works. Be careful if you use it because the array customfields[0] can be different from case to case.
<?php //added
$field = null;
$customFieldsModel = VmModel::getModel('customfields');
$product->customfields = $customFieldsModel->getCustomEmbeddedProductCustomFields($v->virtuemart_product_id,$virtuemart_custom_id=49);
$field = $v->customfields[0]->customfield_value;
//$field = $v->customfields[0]->customfield_value;
$thumb = '<img src="'.$field.'" alt="'.$v->product_name.'">';
//end-added ?>
I'm open for better solutions!