How can I display more than 3 recently viewed products?
I use this code:
<?php
// d0ublezer0 recently viewed products -- start --
// first, cleanup the variables, just in case
$actualIds=false;
$recentProducts=false;
$rSession = JFactory::getSession();
$rIds = $rSession->get('vmlastvisitedproductids', array(), 'vm'); // get recent viewed from browser session
if (is_array($rIds)){
foreach($rIds as $rId){
if ($rId!=$currentId) $actualIds[]=$rId; // cut out from array currently viewed product
}
}
if (is_array($actualIds)){
$recent_products_rows = VmConfig::get('recent_products_rows'); // set in VM admin panel
$products_per_row = 10; // set in VM admin panel
// override next line to define number of recent to display, for example: $recent_products_count = 7;
$recent_products_count = $products_per_row * $recent_products_rows; // get max recent products count
$productModel = VmModel::getModel('product');
$mediaModel = VmModel::getModel('Media');
$recentProducts = $productModel->getProducts($actualIds, false, false); // no front, no calc, only published
$mediaModel->addImages($recentProducts,1); // Digit 1 - is the limit of returned product images. For recent list usually you wil be need only one picture
}
if (is_array($recentProducts)) // if we have recent products
$recentProducts=array_slice($recentProducts,0,$recent_products_count); // return only allowed num of products
if ($recentProducts){ // if we get recent products, display them
?>
<div class="product-recent-products">
<h2>Recently viewed products:</h2>
<ul class="recent-list">
<?php
foreach ($recentProducts as $rProduct) {
?>
<li>
<a href="<?php echo JRoute::_('index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id='.$rProduct->virtuemart_product_id.'&virtuemart_category_id='.$rProduct->virtuemart_category_id); ?>">
<?php
// images[0] - this is first image in images list of the current processed recent product
// also, you can use ->file_url for the full image
echo '<img src="'.$rProduct->images[0]->file_url_thumb.'" />';
echo $rProduct->product_name;
?>
</a>
</li>
<?php } ?>
</ul>
</div>
<?php
}
// d0ublezer0 recently viewed products -- end --
?>
It displays only 3, but 1 is the current, so its just 2, actually. Why VM2 doesn't support to display more than 2 viewed products?
Thanks,
Erik
seems to be in components/helpers/shopfunctionsf.php line 113
function addProductToRecent ()
$recent_products_rows = VmConfig::get('recent_products_rows', 1);
$products_per_row = VmConfig::get('homepage_products_per_row',3);
$maxSize = $products_per_row * $recent_products_rows;
if(count( $products_ids )>$maxSize) {
array_splice( $products_ids, $maxSize );
}
depends on your template config recent product rows X products per row - default 3
Thanks man! My problem is solved now!