Customise the VirtueMart 1.1 Related Products display - Joomla & VirtueMart Tips & How To's

How to change the default layout of VirtueMart 1.1 Related Products display.

Home Joomla VirtueMart Tips Customise the VirtueMart 1.1 Related Products display

Sat

18

Apr

Customise the VirtueMart 1.1 Related Products display
  • Joomla 1.5 + 1.0
  • VirtueMart 1.1

The default layout for the VirtueMart 1.1 Related Products display is a maximum of 4 products displayed in a horizontal row.

It's quite easy to change this and also to display rounded corners i.e <div><div><div><div> layout but you need to change the core files.

The default layout of the Related Products is quite "clonky".
VirtueMart standard related products display
Open file joomla_root/components/com_virtuemart/themes/default/templates/common/relatedProducts.tpl.php in any text editor.
In this case we will make the display fold at 3 products, if you want more or less just change the ($relItem == 3) parameter. The original file is as so -
 
<?php if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' ); ?>
<hr/>
<h3><?php echo $VM_LANG->_('PHPSHOP_RELATED_PRODUCTS_HEADING') ?></h3> 
<table width="100%" align="center">
  <tr>
    <?php 
    while( $products->next_record() ) { ?>
        <td valign="top">
          <?php echo $ps_product->product_snapshot( $products->f('product_sku') ) ?>
        </td>
  <?php 
    }
  ?>
    </tr>
</table> 
 
The changes we need to make are to count the number of products and insert a new table row when we reach our required target number.
The relevant changes are within the table -
 
<table width="100%" align="center">
  <tr>
  <?php $relItemNo = 0; ?>
          <?php 
             while( $products->next_record() ) { 
        if ($relItem == 3) {
        echo "</tr>\n<tr>";
        $relItem = 0;
      }
         ?>  
     <td valign="top">
        <?php echo $ps_product->product_snapshot( $products->f('product_sku') ) ?>
     </td>
  <?php $relItem++;
      }
  ?>
       </tr>
</table>
 
If as well we want to surround the individual products in divs e.g. for a rounded corners border etc then we do this in this file as well. Simply add a class and the necessary divs to the table cell, you will have to adjust your css to suit -
 
     <td valign="top">
        <div class="related">
           <div class="module" style="width:210px;height:160px;">
              <div style="width:210px;height:160px;"><div><div></br>
           <?php echo $ps_product->product_snapshot( $products->f('product_sku') ) ?>
          </div></div></div>
            </div>
         </div>
</div>
     </td>
 
To increase the number of related products shown we need tp change another file.
Open file joomla_root/administrator/components/com_virtuemart/html/shop.product_details.php in any text editor and go to line 85.
Change the number of returned results in the query -
 
$q .= "AND FIND_IN_SET(#__{vm}_product.product_id, REPLACE(related_products, '|', ',' )) LIMIT 0, 4";
 
to for example 6
 
$q .= "AND FIND_IN_SET(#__{vm}_product.product_id, REPLACE(related_products, '|', ',' )) LIMIT 0, 6";
 
Looks better!
VirtueMart adjusted related products display
Last Updated on Monday, 18 October 2010 16:40
 
VirtueMart
Your Cart is currently empty.

Latest Joomla & VirtueMart Tips

See all tips & examples



Customise the VirtueMart 1.1 Related Products display|Joomla & VirtueMart Tips & How To's



How to change the default layout of VirtueMart 1.1 Related Products display.


products, product, related, file, change, number, virtuemart, relitem, snapshot, table, sku, default, joomla, display, layout, set, text, record, changes, editor, php, rounded, corners, replace, divs, open, limit, components, root, row, increase, shown, simply, cell, class, add, necessary, adjust, css, suit


guru

We use cookies to improve our website and your experience when using it. Cookies used for the essential operation of the site have already been set.
To find out more about the cookies we use and how to delete them, see our privacy policy.

I accept cookies from this site.