News:

Support the VirtueMart project and become a member

Main Menu

product weight in email confirmation

Started by dirkb, October 21, 2016, 20:56:25 PM

Previous topic - Next topic

dirkb

VM 3.018 Joomla 3.63

hmmm ... I saw 2 posts regarding that, but none work for me.

I want to add a column in the items table. I would like to have the product single weight top after the product name, and a summary with the total weight of the order.

anybody ideas or has done that before ?

thanks d.

GJC Web Design

the product weights are in the order products object so just extract them, x by quantity and display

in the cart list template
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

dirkb

well ... tried ...

<?php echo $this->product->product_weight ?>
<?php echo $this->product->product_weight_uom ?>
<?php echo $this->product->product_weight.$this->product->product_weight_uom ?>

not showing anything in the invoice_items.php

Why is it so complicated to show the individual weight and the total weight in the confirmation email ? shaking my head here ...

Ghost

It's $item->product_weight. You must add it inside this loop:

foreach($this->orderDetails['items'] as $item) {
...
}

dirkb

you mean like that ?

<?php foreach($this->orderDetails['items'] as $item) {
$item->product_weight;
} ?>

I also tried another snippet for total weight which I found on another thread ... not working either

<?php echo $totalWeight = 0;
                        foreach ( $this->orderDetails['items'] as $items ) {
            $q = 'SELECT `product_weight` FROM `#__virtuemart_products` WHERE `virtuemart_product_id`=' . $items->virtuemart_product_id;
            $db = JFactory::getDbo();
            $db->setQuery($q);
            $productWeight = $db->loadResult();
            $totalWeight += $productWeight * $items->product_quantity;
         }
         echo $totalWeight; ?>

Ghost

#5
Like that but you forgot echo.

dirkb

thanks ... you are my hero of the day, now I have to figure out total weight =)

Milbo

Quote from: dirkb on October 25, 2016, 10:35:57 AM
Why is it so complicated to show the individual weight and the total weight in the confirmation email ? shaking my head here ...

You must admit, it was not complicated. There are also tools to help with issues like, is it product_weight  or productWeight. When you edit your layouts. Use the overrides and learn how to use the vmdebug. vmdebug('my this here',$this); would have shown you, that there is no $this->product available.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

dirkb

thanks milbo, I will take a look into it. The "easy" part depends on from what side you look at it. From mine, its not. My php knowledge is very limited. I can copy paste and sometimes, I´m lucky replacing parts of the code and I have a "Yeah" moment, and it works. Tiny things like that might take me days to figure out on my own, if ... lots of times, it does not work.

For example ... that easy thing with single product weigt and total product weight - I tried for 1 day without success, went to the forum, tried, did not work or not correctly. Now, I´m still lost ... for the single product weight, using the code ...

<?php foreach($this->orderDetails['items'] as $item) {
echo $item->product_weight;
} ?>

I get with a product with 22 kg a  display of 22.0000. How can I reduce that to 2 decimals after the comma.
In addition ... if I have another product with 0.5 kg ... its displaying the weight like 0.500022.0000 ... on each single product line.
The total is displayed fine, 22.5 ... but what do I miss with the single product weight ?

See screen ... thanks if anybody has some spare time, it should be easy I guess.

d.

Milbo

Quote from: dirkb on October 25, 2016, 18:01:33 PM
thanks milbo, I will take a look into it. The "easy" part depends on from what side you look at it. From mine, its not. My php knowledge is very limited. I can copy paste and sometimes, I´m lucky replacing parts of the code and I have a "Yeah" moment, and it works. Tiny things like that might take me days to figure out on my own, if ... lots of times, it does not work.

It is easier to invest 30 minutes and to learn the basics of php. We need only basic php here. Just read this pages https://www.tutorialspoint.com/php/php_variable_types.htm
https://www.tutorialspoint.com/php/php_loop_types.htm
https://www.tutorialspoint.com/php/php_arrays.htm

You can find this also in german!
The rest is to handle an object, instead of an array, which uses for properties and functions just the -> . The rest ist to learn the available variables by reading the code and/or with vmdebug. So for example you wanted the weight of a product within the loop. If you understand the foreach() thing, which is reeeaally simple!, then it is quite easy. It is clear, that it cant be any "$this->...", because you are inside the loop and want to access the items of the looped array. But people sometimes think it is too hard to learn that, but no, that is not the hard part in programming.

Quote from: dirkb on October 25, 2016, 18:01:33 PM
For example ... that easy thing with single product weigt and total product weight - I tried for 1 day without success, went to the forum, tried, did not work or not correctly. Now, I´m still lost ... for the single product weight, using the code ...
Because you think yourself it is easier to stay away from it then just to learn it. But of course, yes. You start to change your mind :-)

Quote from: dirkb on October 25, 2016, 18:01:33 PM
<?php foreach($this->orderDetails['items'] as $item) {
echo $item->product_weight;
} ?>

I get with a product with 22 kg a  display of 22.0000. How can I reduce that to 2 decimals after the comma.
Enter "php round" in your searchengine, take the first link  http://php.net/manual/de/function.round.php
There you see

float round ( float $val [, int $precision = 0 [, int $mode = PHP_ROUND_HALF_UP ]] )

It is not hard to read it it. The normal command is just round($myNumber); any parameter set in [] is optional. So in your case you want to round to 2 digits (Nachkommastellen) and your variable is not $myNumber, it is $item->product_weight and the return value is a "float".

So you can just write

round($item->product_weight, 2)


Quote from: dirkb on October 25, 2016, 18:01:33 PM
In addition ... if I have another product with 0.5 kg ... its displaying the weight like 0.500022.0000 ... on each single product line.
The total is displayed fine, 22.5 ... but what do I miss with the single product weight ?

Because you missed to read the simple chapter about variable types. In fact it is quite hard to understand all consequences of the variable types. But the simple understanding is enough for templating.

When you want to concatenate Strings (Wörter zusammenfügen), then you use the dot "." .

For example

echo 'my length '. $item->product_length .' and my height '.$item->product_height;


But you want to sum up numbers, values, not strings. So you must use the classic + sign.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Jörgen

@Milbo

Very nice to see such great generosity and mentorship when trying to explain the basics in programming and php.

But remember, "No good deed ever goes unpunished"  ;)

+5 from me

regards

Jörgen @ Kreativ Fotografi
Joomla 3.9.18
Virtuemart 3.4.x
Olympiantheme Hera (customized)
This reflects current status when viewing old post.

Milbo

Thank you very much, in fact the idea is to create a small tutorial out of it, with the most important basics for layouting. 80% of the layout code is quite simple and easy to read, if you know the basics how to read program code.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

dirkb

well, I guess I have to say thank you too - got quiet lectured and a lesson too

Milbo

Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Jörgen

Thank You Milbo

This looks promising. Nice to get a better understanding about the scope for data passed through views in VM.

regards

Jörgen @ Kreativ Fotografi
Joomla 3.9.18
Virtuemart 3.4.x
Olympiantheme Hera (customized)
This reflects current status when viewing old post.