VirtueMart Forum

VirtueMart 2 + 3 + 4 => Templating & Layouts => Topic started by: LuukDriessen on January 21, 2013, 09:51:38 AM

Title: Total Weight in E-mail confirmation
Post by: LuukDriessen on January 21, 2013, 09:51:38 AM
Hello,

I am looking for someone who can help me with the total weight of the products.
I want these total weight showing up on the E-mail confirmation.

Because when we have an order we want to directly see the weight.

Is this possible? Which file I need to edit?

Can someone help me with this? I think that eventually a lot of people wants this function.

Thanks in advance

gr Luuk
Title: Re: Total Weight in E-mail confirmation
Post by: LuukDriessen on January 25, 2013, 12:38:32 PM
I did some research.

I found/knew that <?php echo $product->product_weight ?> is used to show the weight of the product.

But how can I fix this that it contains the total width? Is this possible?

I want to attach this rule in the e-mail that the owner receives. Also I want that the weight is not visible in the customers email. Which file/part do I need to edit then?

Thanks in advance
Title: Re: Total Weight in E-mail confirmation
Post by: K&K media production on January 27, 2013, 12:27:30 PM
Hi

to display the weight you can use this code in confirmation email:


                        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;
}
echo $totalWeight;


To display it only in the vendor email, put it for example in mail_html_vendor.php.


Regards,
Maik
Title: Re: Total Weight in E-mail confirmation
Post by: LuukDriessen on January 28, 2013, 11:51:36 AM
Hi,

Thanks for your reply.

I added the code to mail_html_vendor.php and now it shows the weight. Thanks!

But unfortunately the weight doesn't get counted when I have a different quantity per product. I only see the weight of the products that are selected. So the first product is 2 kg and the other is 1 kg. Together these are 3 kg. So it shows 3 kg.  But when I order 3 times product 1 and 2 times product 2 these weights doesn't get counted.

So the code doesn't make use of the quantity.
Title: Re: Total Weight in E-mail confirmation
Post by: K&K media production on January 28, 2013, 13:04:27 PM
OK, there is one thing missing.

Please try this:


                        $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;


Regards,
Maik
Title: Re: Total Weight in E-mail confirmation
Post by: LuukDriessen on January 28, 2013, 14:12:34 PM
Quote from: kkmediaproduction on January 28, 2013, 13:04:27 PM
OK, there is one thing missing.

Please try this:


                        $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;


Regards,
Maik


Great great great! Now it's working!

I think many people will use this function :)

Thank you very much!

8)
Title: Re: Total Weight in E-mail confirmation
Post by: PRO on January 28, 2013, 20:16:53 PM
really no need to query the DB like that product weight is already in the array

Title: Re: Total Weight in E-mail confirmation
Post by: LuukDriessen on January 31, 2013, 10:38:16 AM
                        $totalWeight = 0;
                        foreach ( $this->orderDetails['items'] as $items ) {
            $db = JFactory::getDbo();
            $db->setQuery($q);
            $productWeight = $db->loadResult();
            $totalWeight += $productWeight * $items->product_quantity;
         }
         echo $totalWeight;



Is this the code that I should insert into the page? I delete the query code.
Title: Re: Total Weight in E-mail confirmation
Post by: K&K media production on January 31, 2013, 12:02:41 PM
No, the weight is not in the items array. You must use my code with query.
Title: Re: Total Weight in E-mail confirmation
Post by: servlet on August 14, 2013, 16:35:32 PM
Please paste the code in this category for next VM verion: http://forum.virtuemart.net/index.php?board=139.0