Author Topic: Solution to display product weights and total weights in details and cart  (Read 12462 times)

cinos

  • Jr. Member
  • **
  • Posts: 85
Decided to put this information here, since my other post regarding this has been put in the implemented feature list (the deadzone) and I want to make sure people see this so that they don't have as much trouble as I did. As always big it up for the community. They saved the day, with perhaps a little tinkering on my part.  ;D

Anyway here is how you can set up the product weight for yourselves.

First off, displaying the product weight in the product details page.

Go to: components/com_virtuemart/themes/default/templates/product_details and edit the file flypage.tpl.php or whichever file you have chosen for your categories.

The following code will place the product weight underneath the manufacturer link, or if that is disabled just under the title of the product:

On about line 37, change the code from this:

Code: [Select]
<td width="33%" valign="top" align="left">
      <?php echo $product_price_lbl ?>
      <?php echo $product_price ?><br /></td>
      <td valign="top"><?php echo $product_packaging ?><br /></td>

To this:

Code: [Select]
<td width="33%" valign="top" align="left">
      <?php echo $product_weight?>
      <?php echo $product_weight_uom?><br /><br />
      <?php echo $product_price_lbl ?>
      <?php echo $product_price ?><br /></td>
      <td valign="top"><?php echo $product_packaging ?><br /></td>

You don't have to put the code here, this is just where I wanted it. Play around a bit and find a location you're happy with. Just BACKUP the code before you change anything!!

Right, next is the total weight for the cart. Fortunately the code to work out the total weight is already present so all we have to do is ask for it to be shown.


First off go here: administrator/components/com_virtuemart/languages/common/english.php

and place this code anywhere you like in the list. I placed it at line 122:

Code: [Select]
'PHPSHOP_ORDER_PRINT_WEIGHTTOTAL' => 'Total Weight',
DON'T forget the comma.

Next we want to go here: components/com_virtuemart/themes/default/templates/basket/basket_b2c.html.php

It will probably be best to edit and add similar code to the other 3 basket files (to be on the safe side) but this file is the one that customers will be predominantly using.

Go to line 40, where the code should look like this:

Code: [Select]
<tr class="sectiontableentry1">
    <td colspan="4" align="right"><?php echo $VM_LANG->_('PHPSHOP_CART_SUBTOTAL'?>:</td>
    <td colspan="3" align="right"><?php echo $subtotal_display ?></td>
  </tr>
<?php if( $discount_before ) { ?>
  <tr class="sectiontableentry1">
    <td colspan="4" align="right"><?php echo $VM_LANG->_('PHPSHOP_COUPON_DISCOUNT'?>:
    </td>

and change it to this:

Code: [Select]
<tr class="sectiontableentry1">
    <td colspan="4" align="right"><?php echo $VM_LANG->_('PHPSHOP_CART_SUBTOTAL'?>:</td>
    <td colspan="3" align="right"><?php echo $subtotal_display ?></td>
  </tr>
  <tr class="sectiontableentry1">
    <td colspan="4" align="right"><?php echo $VM_LANG->_('PHPSHOP_ORDER_PRINT_WEIGHTTOTAL'?>:</td>
    <td colspan="3" align="right"><?php echo $weight_total ?> kg</td>
  </tr>
<?php if( $discount_before ) { ?>
  <tr class="sectiontableentry1">
    <td colspan="4" align="right"><?php echo $VM_LANG->_('PHPSHOP_COUPON_DISCOUNT'?>:
    </td>

Once done, test the checkout and product pages, to see if everything is how you want it. The weight is currently set to display kilogramms, if your weights are shown as a different unit of measure then just change the 'kg' to whatever is appropriate.

The code should work for you. Only problem I have found so far is that the product weight is displayed with 4 decimal places on the product details page.

If I find a solution I'll let you know...assuming of course that some other delightful person doesn't beat me to it.  ;) (hint hint)

cinos

  • Jr. Member
  • **
  • Posts: 85
Ha! That didn't take long.  ;D

Right if you want to change the number of decimal places shown on the product weights then what you have to do is access your sql database.

If you use Siteground as a host, then you can do this by logging in and going to the cpanel of your site.

Then go to PHPMyAdmin (near the bottom, by the sql stuff), click that.

Once loaded, on the right there should be a list of database headers. Select the one that says _jo151 (this might be different, I'm not sure, but it should look similar to this)

A new list of databases should appear, and you need to select jos_vm_product

This should open a new list of individual fields, the one you want is called: product_weight

Under type it should say: Decimal(10,4)

If you don't want any decimal places, you should change that to (click change/pencil icon): Decimal(10,0)

That should do it. Hope it helps someone. ;)

klutzon

  • Jr. Member
  • **
  • Posts: 319
  • Knuckles the Echidna
    • Rage3D
It did indeed. :)

Thank you very much for the info, especially the tip about the Decimal points, which my client was actually asking about. While I know how to go about changing this manually in phpmyadmin, surely there must be an automatic option somewhere in the VirtueMart admin panel...? If there isn't, there should be! :D We can remove the decimals for the prices, we should be able to remove the decimals for weight.

Thanks again cinos. ;)

cinos

  • Jr. Member
  • **
  • Posts: 85
Right well that was short lived.

After upgrading to version 1.1.3 the total weight no longer displays.
I set up a personal theme so that the basket files would not be changed and I have put the language edit (PHPSHOP_ORDER_PRINT_WEIGHTTOTAL) back in.

All that's left is for the actuall weight to display, however all I get is the kg with nothing before it.

Any ideas on what has been changed that could affect this?

cinos

  • Jr. Member
  • **
  • Posts: 85
Right ok, think I have found it.

At line 269 of administrator/components/com_virtuemart/html/basket.php, you should see this code:

Code: [Select]
if( $show_basket ) {

if( $auth["show_price_including_tax"] == 1) {
$basket_html = $tpl->fetch( 'basket/basket_b2c.html.php');
}
else {
$basket_html = $tpl->fetch( 'basket/basket_b2b.html.php');
}
}

This is what is breaking the total_weight. For now the best way to fix this is to change it back to the old code, as in:

Code: [Select]
if( $show_basket ) {
ob_start();
if( $auth["show_price_including_tax"] == 1) {
include (VM_THEMEPATH."templates/basket/basket_b2c.html.php");
}
else {
include (VM_THEMEPATH."templates/basket/basket_b2b.html.php");
}
$basket_html = ob_get_contents();
ob_end_clean();
}

This should restore the total weight to its former glory. I'll have a look round the site over the next few days and see if this change breaks anything else.

If a dev could take a look at what I've done and tell me if there is a better way I would greatly appreciate it. ;)

devilman

  • Beginner
  • *
  • Posts: 19
I'm glad I saw this thread.  I did a similar modification on my old cart and wondered why it wasn't working when I copied the code across to the new one and the $weight_total stuff would explain a lot. Did you find out if your last modification caused any issues?

cinos

  • Jr. Member
  • **
  • Posts: 85
No issues for me whatsoever. ;)

If you find any problems however, please don't hesitate to bring it up.

Stasevich

  • Beginner
  • *
  • Posts: 2
Thank you very much, "cinos", for this topic.
I've got results for ten minutes.

cinos

  • Jr. Member
  • **
  • Posts: 85
Re: Solution to display product weights and total weights in details and cart
« Reply #8 on: February 02, 2009, 17:17:45 pm »
Thankyou so much for the kind words it means alot. :)

On another note I have just noticed that despite my 'fix' the total weight still won't display on the "Complete Order" (step 4 of checkout) page.

This has me quite stumped since, the weight displays perfectly for steps 1 through 3 and the extra code I added still shows in step 4 (the "Total weight:  kg" bit), yet the actual weight does not.

Does anyone know why this would be? Does step 4 use anything that might block the total weight from displaying on that page and not the previous steps of checkout?

Stasevich

  • Beginner
  • *
  • Posts: 2
Re: Solution to display product weights and total weights in details and cart
« Reply #9 on: February 04, 2009, 18:14:56 pm »
please, help me to change the pounds. to kg. in VM (1.1.3) product details page?
I've imported CSV file with a list of products, but the total weight calculating like 453.59237 (1pound = 453.59237 gr) * weight in CSV file = weight in kg., but it's wrong... (

devilman

  • Beginner
  • *
  • Posts: 19
Re: Solution to display product weights and total weights in details and cart
« Reply #10 on: February 05, 2009, 00:34:10 am »
No issues for me whatsoever. ;)
If you find any problems however, please don't hesitate to bring it up.
I've just realised I've got the wrong idea from this thread!  You're displaying the weight total during the cart process whereas I was hoping to show the weight in the mini-cart in the VM module!  That would explain why, when I implemented your fix, nothing changed!  At least I've managed to get it working again how I wanted it (http://www.consolemad.co.uk - if you want to see how I've chosen to do it)

CigarPax

  • Beginner
  • *
  • Posts: 2
Does anyone know why this would be? Does step 4 use anything that might block the total weight from displaying on that page and not the previous steps of checkout?

Thanks a lot for that, it was really tricky to find, I look for it hours before coming here ! >:(
So for your problem, step 4 is ro_basket, at line 289 of administrator/components/com_virtuemart/html/ro_basket.php, you should see this code:
Code: [Select]
$basket_html = $tpl->fetch( 'basket/ro_basket_b2c.html.php');
}
else {
$basket_html = $tpl->fetch( 'basket/ro_basket_b2b.html.php');
replace with :
Code: [Select]
include (VM_THEMEPATH."templates/basket/ro_basket_b2c.html.php");
}
else {
include (VM_THEMEPATH."templates/basket/ro_basket_b2b.html.php");
(in your hint, it's the same just replace the 2 lines with include, don't add old ob things)

And again don't touch your sql for decimal !!! You don't need it. Use php function number_format like that :
Code: [Select]
<?php echo number_format($weight_total3'.'' '?>that will show weight with 3 decimals, . for decimal break and space for thousand. So 1011.2021548 will display 1 011.20
Code: [Select]
<?php echo number_format($weight_total0'.'' '?>that will show weight with 0 decimals, . for decimal break and space for thousand. So 1011.2021548 will display 1 011
 ;)

cinos

  • Jr. Member
  • **
  • Posts: 85
Cheers CigarPax!

I would never have thought to look in ro_basket. That fixed the total weight for my final step.  :)

Only problem now seems to be that the fix you mentioned has reordered the page slightly, so that the order is placed at the top and the checkout with the basket images is placed below that.

Not so much of a problem really, it still looks good.  ;D

Thanks again!

Arbait

  • Beginner
  • *
  • Posts: 9
I have used the info from here, and now sound like im on the good way. Thank you, guys!
In my case i want to use VM as a grocery store.

One of the problems i have is that in module cart i have like that:

5 x Salami Carusso €13,70
5 Products €13,70

when the client buy 5 kg of salami.

What to do to have something like that:

5 kg x Salami Carusso €13,70
5 kg €13,70

The client dont buy 5 Carusso salami, but 5 kg of Carusso salami...

I hope that i make myself clear, please help my out of this

deim

  • Beginner
  • *
  • Posts: 1
I have a little problem with this solution. Everything works, but, for example, if i have two products, each 2.00kg, the total weight in the cart says 0.004 kg. Very confusing :-) Did i forget one step? Or do i have to change properties of the total weight?