VirtueMart Forum

VirtueMart 2 + 3 + 4 => Product creation => Topic started by: mediax on December 12, 2015, 14:06:35 PM

Title: Volume input for product and display total Volume in Cart
Post by: mediax on December 12, 2015, 14:06:35 PM
Hi Virtuemart support,

I am using Virtuemart 3.012 and Joomla 3.4.5. Please can someone help me or direct me on how to find a solution for this.

My client needs a Volume field for each product in his store. This volume field must show up on the product details page as well as in the cart. Then in the cart we must be able to have a total volume displayed of all products in the cart. Is this at all possible using custom fields or do I have to manually add new database fields for this?

Any help will be mush appreciated.

Thanks,
MediaX
Title: Re: Volume input for product and display total Volume in Cart
Post by: GJC Web Design on December 12, 2015, 14:38:41 PM
extra fields in DB aren't needed

create a custom field -> string and enter the volume there

if you wanted it on the fly from the dimensions then leave blank and populate in the templates by either php or JS

total in the cart maybe a custom cart field  and populate that with the passed volumes
Title: Re: Volume input for product and display total Volume in Cart
Post by: PRO on December 13, 2015, 14:13:36 PM
in the "product dimensions & weight" tab.

You have
Length,width,height   (which is volume)

Those could be used.

Or, you could always just change the text label on any other un-used field., and use it for volume.

I would not do a custom field for something so simple, that has to be on every product.

If you use an existing field, it is easier.
Title: Re: Volume input for product and display total Volume in Cart
Post by: mediax on December 14, 2015, 07:11:32 AM
Hi, Thank you for the response. I have gone with GJC Solution and created the custom string field and then added that in the product detail template by using this code:

if (!empty($this->product->customfieldsSorted['mx-custom'])) { ?>
   <div class="product-fields">
   <?php
   $custom_title = null ;
   foreach ($this->product->customfieldsSorted['mx-custom'] as $field){
      if ($field->display) {
         ?><div class="product-field product-field-type-<?php echo $field->field_type ?>">
         <?php if ($field->custom_title != $custom_title) { ?>
            <span class="product-fields-title" ><?php echo JText::_($field->custom_title); ?></span>
            <?php if ($field->custom_tip) echo JHTML::tooltip($field->custom_tip,  JText::_($field->custom_title), 'tooltip.png');
         } ?>
         <span class="product-field-display"><?php echo $field->display . "m³" ?></span>
         <span class="product-field-desc"><?php echo jText::_($field->custom_field_desc) ?></span>
         </div>
         <?php
         $custom_title = $field->custom_title;
      }
   } ?>
   </div>
      <?php } // Product Custom ontop end ?>

This works perfect to display the custom field data. Now I have to display that in the cart as well, but I have to do the sum of the field X the amount of that product, and then create a total Volume to display in the cart, please could you assist in how to do this.
Title: Re: Volume input for product and display total Volume in Cart
Post by: mediax on December 14, 2015, 10:50:16 AM
Hi PRO,

Thanks for your response.

After trying to work with the custom string variable in Cart, I gave up on that as I was unable to get the string value to display by itself. I then tried the first option you gave me:

$length = $prow->product_length;
   $width = $prow->product_width;
   $height = $prow->product_height;
   $volume = $length * $height * $width;

$subvolume = $volume * $prow->quantity;
echo $subvolume;

This gave me the correct volume that I needed in the cart field. How do I SUM all the product volumes together for a total CART Volume? Will this be reflected in the order invoice or do I have to add it there as well?

Kind regards,
MediaX
Title: Re: Volume input for product and display total Volume in Cart
Post by: PRO on December 14, 2015, 21:15:58 PM
this is very rough estimate(did not test), but this is what you want to do



$tvolume=0;
foreach ($this->cart->products as $pkey => $prow) {
$length = $prow->product_length;
   $width = $prow->product_width;
   $height = $prow->product_height;
   $volume = $length * $height * $width;
$subvolume = $volume * $prow->quantity;
$tvolume +=$subvolume
}