web design, England, Britain, UK, belgium
 
Ulti Clocks content

Customise the VirtueMart 1.1 Related Products display

GJC Web Design Joomla & VirtueMart how to, tips, tricks, coding examples, html, php, tutorial, 101, useful hints, help

A collection of help articles and coding examples for Joomla & Virtuemart

Belgium, VirtueMart & Joomla Web Design England UK Britain & Germany

Joomla, VirtueMart, how to, tips, tricks, coding examples, html, php, tutorial, 101, useful hints, help sand How to change the default layout of VirtueMart 1.1 Related Products display.
products, div, product, related, php, pre, virtuemart, table, display, width, file, joomla, change, html, echo, xml, com, number, height, relitem, class, style, standard, layout, adjusted, sku, snapshot, valign, default, border, need, text, set, changes, editor, defined, record, divs, want, center

Home Joomla - VirtueMart Joomla & VM How To's 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


Add this page to your favorite Social Bookmarking websites
Digg! Reddit! Del.icio.us! Mixx! Free and Open Source Software News Google! Live! Facebook! Slashdot! Technorati! StumbleUpon! Spurl! Newsvine! Furl! Fark! Yahoo! Netvouz! Mister-Wong! RawSugar! Ma.gnolia! Squidoo! DZone! Swik!
Last Updated on Saturday, 18 April 2009 10:06 Read : 14063 times
 
Comments (16)
@Chris
16 Tuesday, 25 May 2010 10:32
GJC admin
Yes, the template file is just that, a template so you can have it tableless if you want.
Just copy the existing, rename the old one so you have something to go back to if it all falls in a heap, and experiment with the layout...
Can I replace that table?
15 Tuesday, 25 May 2010 09:52
Chris
Hi
This article is great and works well as it lead me to the right files to edit... However I would like my related products to float left and butt up to each other if there are less than the '4' I want displayed... As they are contained within a table I can't find a way to apply a float.. Any Ideas?
Can I just replace the 'table' in root/components/com_virtuemart/themes/default/templates/common/relatedProducts.tpl.php with CSS controlled Divs?
help ?
14 Monday, 12 April 2010 21:12
Hey guys, could someone very kind help me with the css ? And if I would like to modify the home page of virtuemart which file I should modify ? Thank You in advace. P.
thanks so much
13 Tuesday, 23 March 2010 21:31
miki
It works , thank you ...really

I just made a few styling modifications but it was perfect !!! Smile
Please help
12 Monday, 22 March 2010 21:07
John
Can you show me your CSS for this?
need help
11 Tuesday, 23 February 2010 08:47
Guest
Can't get it working, maybe someone can share modified relatedProducts.tpl file? Thanx
@Steff
10 Wednesday, 09 September 2009 14:05
GJC (admin)
Email me thru the contact page with more details..
Related products disappear
9 Wednesday, 09 September 2009 13:48
Steff
It is not working for me, the related products disappear while using this code.
Working!!
8 Sunday, 09 August 2009 22:51
Dirk
I get it working. Just make a little mistake somewhere...

See:
http://www.dima-sports.nl/Honkbal-/-Softbal/Ballen/Champro-Official-League-Ball.html

Thanks!
Dirk
Weird...
7 Sunday, 09 August 2009 21:55
Dirk
Hi,
Did exactly the things you described.
Works nicely... but.
Image (or productname)is not clickable anymore. The link to the flypage is gone.
Did i do something wrong?
css styling
6 Thursday, 06 August 2009 13:39
@Maykel
If you need help you can contact me through the contact page...
cSS to suit
5 Thursday, 06 August 2009 11:44
Maykel Leijsten
Thanks for trying to help me.

My Englisch is not so good to understand than sentence. I know css but where and wich css files do i have to change?

see my sit http://www3.quickproducts.nl
@Maykel
4 Thursday, 06 August 2009 10:08
GJC (admin)
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
Tried but nothing changed
3 Thursday, 06 August 2009 09:34
Maykel Leijsten
Hi I also tried the modification in virtuemart 1.1.3 but nothing happens. Is there something we do wrong?
@Radoslaw
2 Saturday, 25 July 2009 06:36
GJC (admin)
With all your feedback and information I've finally worked out that it's not working because the wind is coming from the east.
Try turning the PC around 180 degrees, should work then...

Wearing a hat while coding should make it simpler next time as well...
About
1 Friday, 24 July 2009 21:20
Radoslaw
It`s not working. I changed the code ,but nothing happend.

Add your comment

BoldItalicUnderlineStrikethroughSubscriptSuperscriptEmailImageHyperlinkOrdered listUnordered listQuoteCodeHyperlink to the Article by its id
Very HappySmileWinkSadSurprisedShockedConfusedCoolLaughingMadRazzEmbarrassedCrying or Very SadEvil or Very MadTwisted EvilRolling EyesExclamationQuestionIdeaArrowNeutralMr. GreenGeekUber Geek
Your name:
Subject:
Comment:

Latest Articles

Paypal Donation

If you use this module on your site please donate a small amount.
Any donation amount appreciated.

VM Live Product Search

Recommended Reading

For those interested in extending there knowledge of Joomla! & VirtueMart Packt Publishing has an excellent range of help & how to books.
Listed below are some I can recommend.
Simply click on the images to be taken directly to their web shop.

Learning Joomla! 1.5 Extension Development Learning Joomla! 1.5 Extension Development
by Joseph L. LeBlanc.
Read the review
Joomla! E-Commerce with VirtueMart Joomla! E-Commerce with VirtueMart
by Suhreed Sarkar.
Read the review
Joomla! Web Security Joomla! Web Security
by Tom Canavan.

Mastering Joomla! 1.5 Extension and Framework Development Mastering Joomla! 1.5 Extension and Framework Development
by James Kennard.

Joomla! Template Design: Create your own professional-quality templates with this fast, friendly guide Joomla! Template Design: Create your own professional-quality templates with this fast, friendly guide
by Tessa Blakeley Silver.

GJC Web Design Joomla & VirtueMart how to, tips, tricks, coding examples, html, php, tutorial, 101, useful hints, help

A collection of help articles and coding examples for Joomla & Virtuemart

Belgium, VirtueMart & Joomla Web Design England UK Britain & Germany

Joomla, VirtueMart, how to, tips, tricks, coding examples, html, php, tutorial, 101, useful hints, help



Customise the VirtueMart 1.1 Related Products display



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


products, div, product, related, php, pre, virtuemart, table, display, width, file, joomla, change, html, echo, xml, com, number, height, relitem, class, style, standard, layout, adjusted, sku, snapshot, valign, default, border, need, text, set, changes, editor, defined, record, divs, want, center