VirtueMart Forum

VirtueMart 2 + 3 + 4 => Templating & Layouts => Topic started by: Belgaron on March 08, 2017, 16:33:07 PM

Title: Add several email attachments to order confirmation
Post by: Belgaron on March 08, 2017, 16:33:07 PM
Hello,
I´d like to add three PDF documents to the order confirmation email. These PDF´s should not be sent with any other email.
I am using Virtuemart 3.0.18 and Joomla 3.6.5. How can I achieve that and what files do I need to modify?
Title: Re: Add several email attachments to order confirmation
Post by: kishoreonwork on March 09, 2017, 23:40:37 PM
you need to edit administrator\components\com_virtuemart\models\order.php

line near to 1695 you will see below code

// Send the email
$res = shopFunctionsF::renderMail('invoice', $order['details']['BT']->email, $vars, null,$vars['doVendor'],$this->useDefaultEmailOrderStatus);


Just above this add following code
if( $order['order_status']=='C'){  //Only for confirmed order

$vars['mediaToSend'][] = 'Full path to your file1';
$vars['mediaToSend'][] = 'Full path to your file2';
$vars['mediaToSend'][] = 'Full path to your file3';

}



Please let me know if this help.

Before making the chnages please make backup of this file.

Thanks
Kishore
Title: Re: Add several email attachments to order confirmation
Post by: Belgaron on March 11, 2017, 17:26:57 PM
Hello kishoreonwork,
thank you for your help. Unfortunately it does not work, the documents are not added as attachments. Do you have any other proposal?
Title: Re: Add several email attachments to order confirmation
Post by: kishoreonwork on March 17, 2017, 13:12:11 PM
Yes there is a problem in the code ,as there are some override in email render function.

Here is the new code which i have tested and working fine for me.

1)The file is components/com_virtuemart/views/invoice/view.html.php

the function name is "renderMailLayout"  look for below code near line no  306

if(!empty($attach) and !$doVendor and in_array($this->orderDetails['details']['BT']->order_status,VmConfig::get('attach_os',0)) ){
$this->mediaToSend = VMPATH_ROOT.DS.'images'.DS.'stories'.DS.'virtuemart'.DS.'vendor'.DS.VmConfig::get('attach');
}



Replace it with

if(!empty($attach) and !$doVendor and in_array($this->orderDetails['details']['BT']->order_status,VmConfig::get('attach_os',0)) ){

$attachment=explode(',',$attach);

foreach($attachment as $file){
$this->mediaToSend[] = VMPATH_ROOT.DS.'images'.DS.'stories'.DS.'virtuemart'.DS.'vendor'.DS.$file;

}


}


2) Now in virtuemart administration backend in configuration ->checkout ->General mail attachment
Enter comma separated file name for your attachments


Thanks
Kishore


Title: Re: Add several email attachments to order confirmation
Post by: Milbo on March 18, 2017, 07:47:34 AM
When I read your first answer, I wanted to interfer and explain that we have that already, but only for one pdf.

It is a nice idea to extend the config possibilities by using explode. We use this already for other options. I think we should check all places and use always the same sign. I fear we use sometimes comma, sometimes semicolon, sometimes "new line".
Title: Re: Add several email attachments to order confirmation
Post by: Belgaron on March 18, 2017, 17:35:33 PM
Hi kishoreonwork, that solution works perfect thank you so much. This solves a long standing issue for me and it is now really easy to add documents from the backend.  :D

Is it possible to override the com_virtuemart/views/invoice/view.html.php ?

I tried to put it in mytemplate/com_virtuemart/invoice/view.html.php but it seems not to work.
Title: Re: Add several email attachments to order confirmation
Post by: Milbo on March 21, 2017, 21:10:59 PM
It is added to vm3.2, wait for the vm3.2.1
Title: Re: Add several email attachments to order confirmation
Post by: kishoreonwork on March 22, 2017, 02:42:29 AM
 Thanks for adding this code to new VM
Title: Re: Add several email attachments to order confirmation
Post by: Belgaron on March 24, 2017, 22:08:53 PM
Thank you Milbo for adding the new code. That makes life a lot easier.