News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Volume input for product and display total Volume in Cart

Started by mediax, December 12, 2015, 14:06:35 PM

Previous topic - Next topic

mediax

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

GJC Web Design

#1
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
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

PRO

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.

mediax

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.

mediax

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

PRO

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
}