Author Topic: product weight in email confirmation  (Read 2801 times)

dirkb

  • Jr. Member
  • **
  • Posts: 75
product weight in email confirmation
« on: October 21, 2016, 20:56:25 pm »
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

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 10073
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 3.6.8
Re: product weight in email confirmation
« Reply #1 on: October 22, 2016, 11:10:59 am »
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 http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 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
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

dirkb

  • Jr. Member
  • **
  • Posts: 75
Re: product weight in email confirmation
« Reply #2 on: October 25, 2016, 10:35:57 am »
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

  • Jr. Member
  • **
  • Posts: 422
Re: product weight in email confirmation
« Reply #3 on: October 25, 2016, 11:16:26 am »
It's $item->product_weight. You must add it inside this loop:

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

dirkb

  • Jr. Member
  • **
  • Posts: 75
Re: product weight in email confirmation
« Reply #4 on: October 25, 2016, 11:31:07 am »
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

  • Jr. Member
  • **
  • Posts: 422
Re: product weight in email confirmation
« Reply #5 on: October 25, 2016, 11:36:18 am »
Like that but you forgot echo.

dirkb

  • Jr. Member
  • **
  • Posts: 75
Re: product weight in email confirmation
« Reply #6 on: October 25, 2016, 11:50:06 am »
thanks ... you are my hero of the day, now I have to figure out total weight =)

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 10090
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: product weight in email confirmation
« Reply #7 on: October 25, 2016, 13:07:50 pm »
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.
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

dirkb

  • Jr. Member
  • **
  • Posts: 75
Re: product weight in email confirmation
« Reply #8 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.

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

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 10090
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: product weight in email confirmation
« Reply #9 on: October 25, 2016, 21:29:37 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.

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 :-)

<?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
Code: [Select]
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
Code: [Select]
round($item->product_weight, 2)
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
Code: [Select]
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.
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Jörgen

  • Global Moderator
  • Sr. Member
  • *
  • Posts: 3330
    • Kreativ Fotografi
  • VirtueMart Version: 3.4.x
Re: product weight in email confirmation
« Reply #10 on: October 25, 2016, 21:53:10 pm »
@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

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 10090
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: product weight in email confirmation
« Reply #11 on: October 25, 2016, 23:16:20 pm »
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.
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

dirkb

  • Jr. Member
  • **
  • Posts: 75
Re: product weight in email confirmation
« Reply #12 on: October 26, 2016, 17:03:20 pm »
well, I guess I have to say thank you too - got quiet lectured and a lesson too

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 10090
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Jörgen

  • Global Moderator
  • Sr. Member
  • *
  • Posts: 3330
    • Kreativ Fotografi
  • VirtueMart Version: 3.4.x
Re: product weight in email confirmation
« Reply #14 on: October 27, 2016, 00:06:10 am »
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.