News:

Looking for documentation? Take a look on our wiki

Main Menu

Display more than 3 Recently viewed products

Started by eriksimonx, November 19, 2013, 14:20:33 PM

Previous topic - Next topic

eriksimonx

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($actualIdsfalsefalse);  // 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

GJC Web Design

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

GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

eriksimonx