VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: zmurshid on March 28, 2012, 12:58:01 PM

Title: How to replace the Replyto address in Ask a question
Post by: zmurshid on March 28, 2012, 12:58:01 PM
Hi,

Currently the replyto address is set to vendor's email address in the 'Ask a question about this product'. Can anyone give me a hint on how to replace the Replyto address with the shopper's email address instead. This will become handy for the vendor to reply to the shopper. 

I have checked and tried with the following files, but, couldn't get it done.
mail_html_question.php
productdetails.php
shopfunctionsf.php

I am using J 2.5.1 and VM 2.0.2

Many thanks in advance
Title: Re: How to replace the Replyto address in Ask a question
Post by: chaldama on May 14, 2012, 12:33:44 PM
I need this feature as well. In VM 1.1.9 this worked perfectly, now my customer keeps replying to himself instead of his customer.
Can this be changed anywhere and/or improved in the next VM update?
Title: Re: How to replace the Replyto address in Ask a question
Post by: Thomas Kuschel on May 31, 2012, 18:13:13 PM
I've built-in this feature for my site, working with VirtueMart 2.0.6;

But I don't know if this feature is unsolicited from the developers; I added this to the backend, to switch on and off the feature (default off) as seen in the attachment.

You need to change several files in the system or download the added zip and exchange the files.

Be careful to switch on this feature, many Internet providers do not allow to change the "from or reply-to address"!!

I just implemented this - please be patient and wait till my last tests are successful.

Regards,
Thomas Kuschel
http://www.loytec.com


[attachment cleanup by admin]
Title: Re: How to replace the Replyto address in Ask a question
Post by: Milbo on June 01, 2012, 00:09:10 AM
Servus Thomas,

exactly the reason we implemented it that way. Otherwise too many people get mad with it. But with a nice option, could be nice to add it to the core, is it vendor depended?
Title: Re: How to replace the Replyto address in Ask a question
Post by: Thomas Kuschel on June 01, 2012, 00:29:09 AM
Hi Milbo,

I implemented it on my test server and put it on my online website since 6 p.m.
By default this feature is off. I think, you'll see the implementation tomorrow evening. It is vendor independent, like the switch to set html-mail or raw-mail.
At the moment, I use that feature for invoice mails only. But there is no problem to add this to the ask_question as well within the file productdetails.php (the same extension).

cu Thomas
 
Title: Re: How to replace the Replyto address in Ask a question
Post by: Milbo on June 01, 2012, 18:43:21 PM
Imho the address is added in the shopfuntions. So it should be possible to create one nice solution for all.
Title: Re: How to replace the Replyto address in Ask a question
Post by: Thomas Kuschel on June 01, 2012, 21:49:30 PM
I want to introduce the new feature which is setting the reply address or sender address when sending invoice mail, or an Ask_Question mail, etc. to the vendor.
You can enable this feature "Receive vendor mail with recipient address" via backend (default is off), so there is no side effect adding this feature. In addition you can choose between building a replyTo or definitely sender address with the next parameter "Recipient address set as Sender, not ReplyTo", but several Internet providers do not permit to set the Sender email address.

What does that mean?

- Usually, if somebody is buying a product, he/she will get an e-mail from the website. In addition, the vendor receives the order via e-mail (invoice).
The vendor gets this mail with sender (from) = Address of Joomla website , and address (To) = Address of Vendor;
With this feature on, you'll receive the vendor's e-mail with replyTo = Address of the recipient (the customer) OR with another flag set the sender (from) = Address of the recipient.

Be careful, switching on this feature! Several Internet provider do not allow setting this to another e-mail address as your own webserver e-mail address.

Now, let's start from 1.)  to  3.)

1.) Language
=============
First of all, add the following lines to your language file (administrator): (I use English language at the backend only :-))
FILE: administrator/language/en-GB/en-GB.com_virtuemart.ini


COM_VIRTUEMART_ADMIN_CFG_MAIL_FROM_RECIPIENT="Receive vendor mail with recipient address"
COM_VIRTUEMART_ADMIN_CFG_MAIL_FROM_RECIPIENT_EXPLAIN="Usually the vendor receives the mail from joomla system email address. If you set this, you'll receive the mail coming as recipient address. Set this option if you're really sure what you do! If in doubt, do not switch on this parameter."
COM_VIRTUEMART_ADMIN_CFG_MAIL_FROM_SETSENDER="Recipient address set as Sender, not ReplyTo"
COM_VIRTUEMART_ADMIN_CFG_MAIL_FROM_SETSENDER_EXPLAIN="If set, the mail address of the recipient is set as Sender. If not, the recipient is set as reply address. Set this option if you're really sure what you do! If in doubt, do not switch on this parameter."



2.) Add new parameters to the backend's configuration
=======================================================
FILE: administrator/components/com_virtuemart/views/config/tmpl/default_shop.php (line 74)
Before:

<?php echo JText::_('COM_VIRTUEMART_ADMIN_CFG_MAIL_FORMAT_HTML'?>
</option>
</select>
</td>
</tr>
<?php /* <tr>
<td class="key">
<span class="hasTip" title="<?php echo JText::_('COM_VIRTUEMART_ADMIN_CFG_DATEFORMAT_EXPLAIN'); ?>
">


After:


<?php echo JText::_('COM_VIRTUEMART_ADMIN_CFG_MAIL_FORMAT_HTML'?>
</option>
</select>
</td>
</tr>
<tr>
<td class="key">
<span class="hasTip" title="<?php echo JText::_('COM_VIRTUEMART_ADMIN_CFG_MAIL_FROM_RECIPIENT_EXPLAIN'); ?>">
<label for="mail_from_recipient"><?php echo JText::_('COM_VIRTUEMART_ADMIN_CFG_MAIL_FROM_RECIPIENT'?></span>
</span>
</td>
<td>
<?php echo VmHTML::checkbox('mail_from_recipient'$this->config->get('mail_from_recipient',0)); ?>
</td>
</tr>
<tr>
<td class="key">
<span class="hasTip" title="<?php echo JText::_('COM_VIRTUEMART_ADMIN_CFG_MAIL_FROM_SETSENDER_EXPLAIN'); ?>">
<label for="mail_from_setsender"><?php echo JText::_('COM_VIRTUEMART_ADMIN_CFG_MAIL_FROM_SETSENDER'?></span>
</span>
</td>
<td>
<?php echo VmHTML::checkbox('mail_from_setsender'$this->config->get('mail_from_setsender',0)); ?>
</td>
</tr>
<?php /* <tr>
<td class="key">
<span class="hasTip" title="<?php echo JText::_('COM_VIRTUEMART_ADMIN_CFG_DATEFORMAT_EXPLAIN'); ?>
">



3.) Add some code to the virtuemart class shopFunctionsF
=========================================================
FILE: components/com_virtuemart/helpers/shopfunctionsf.php (line 222)

Exchange the following function within the class:

/**
* With this function you can use a view to sent it by email.
* Just use a task in a controller todo the rendering of the email.
*
* @param string $view for example user, cart
* @param string $recipient shopper@whatever.com
* @param bool $vendor true for notifying vendor of user action (e.g. registration)
* @return true if successful
*/
private function sendVmMail (&$view, $recipient, $vendor=false ) {
$jlang =JFactory::getLanguage();
if(VmConfig::get('enableEnglish', 1)){
$jlang->load('com_virtuemart', JPATH_SITE, 'en-GB', true);
}
$jlang->load('com_virtuemart', JPATH_SITE, $jlang->getDefault(), true);
$jlang->load('com_virtuemart', JPATH_SITE, null, true);

ob_start();
$view->renderMailLayout($vendor, $recipient);
$body = ob_get_contents();
ob_end_clean();

$subject = (isset($view->subject)) ? $view->subject : JText::_('COM_VIRTUEMART_DEFAULT_MESSAGE_SUBJECT');
$mailer = JFactory::getMailer();
$mailer->addRecipient($recipient);
$mailer->setSubject($subject);
$mailer->isHTML(VmConfig::get('order_mail_html',true));
$mailer->setBody($body);

$mailfrom = array();
if($vendor){   //this is the mail to the vendor!
$mail_from_recipient = VmConfig::get('mail_from_recipient','0');
if ($mail_from_recipient =='1'){
if(isset($view->user)){
$mailfrom[0] = $view->user['email'];
$mailfrom[1] = $view->user['name'];
}else{
$user = JFactory::getUser(); //fallback
if (!empty($user->id)) {
$mailfrom[0] = $user->email;
$mailfrom[1] = $user->name;
}
}
} //else fetch the Joomla setup email address
}else{
$mailfrom[0]=$view->vendorEmail;
$mailfrom[1]= $view->vendor->vendor_name;
}
if(!empty($mailfrom)){
$mail_from_setSender = VmConfig::get('mail_from_setsender','0');
if ($mail_from_setSender=='0') {
$mailer->addReplyTo($mailfrom);
}else {
$mailer->setSender($mailfrom);
}
}

if (isset($view->mediaToSend)) {
foreach ((array)$view->mediaToSend as $media) {
//Todo test and such things.
$mailer->addAttachment($media);
}
}

return $mailer->Send();
}


I have tested this with the invoice mail on my live system for 24 hours;
Is there anybody who can test this new feature with Ask_Question or other mailing functions too?

p.s. FYI (@Milbo): The function sendVmMail is the latest from the cvs which I have merged with my code; but found a doubled line there:
      $jlang =JFactory::getLanguage(); I removed this line.

cu Thomas Kuschel
Title: Re: How to replace the Replyto address in Ask a question
Post by: Aroab38 on June 12, 2012, 10:35:04 AM
Hi Thomas

Thank you for your detailed solution. I implemented it but it doesn't change the Reply To for the Vendor order email. So if an order comes in and I reply to it I actually reply to myself and first have to copy/paste the customer's email address.


I get the following tabs in the backend and have tried checking the boxes in all variations but no luck.

Receive vendor mail with recipient address    
Recipient address set as Sender, not ReplyTo

I have used Virtuemart 1.1.9 until last week without a problem so it's not a server side problem.

@Milbo may I ask why you guys coded it this way by default?
Title: Re: How to replace the Replyto address in Ask a question
Post by: Thomas Kuschel on June 12, 2012, 10:48:04 AM
Hi Aroab38,
which Virtuemart Version?
Did you set the Vendor at the backend of virtuemart correctly? - Is there any php cache in use?

For testing, only activate the
"Receive vendor mail with recipient address "  - so the reply-to address should work. Have you pressed the SAVE button afterwards?

Thomas
Title: Re: How to replace the Replyto address in Ask a question
Post by: Aroab38 on June 12, 2012, 11:15:13 AM
Hi Thomas

Thank you for your prompt reply!

I have set up the Vendor correctly as per wiki instruction. Is there anything specific I should look out for?

I am not too sure about PHP Cache, where do I purge this? I use Akeeba Admin Tools to purge and did without any change.

Yes I pressed the SAVE button afterwards ;) LOL!

From your posted solution I was unsure of the last bit of code  $jlang =JFactory::getLanguage();    I didn't do anything with that. Was it just a note to Milbo or should I delete that code somewhere?

Thanks in advance!

Title: Re: How to replace the Replyto address in Ask a question
Post by: Thomas Kuschel on June 12, 2012, 11:40:11 AM
QuoteI have set up the Vendor correctly as per wiki instruction. Is there anything specific I should look out for?
I don't think so.
QuoteI am not too sure about PHP Cache, where do I purge this? I use Akeeba Admin Tools to purge and did without any change.
Which Joomla Version? 1.5: Tools->Purge Expired Cache // Clean Cache; 2.5: Site->Maintanance->Purge Expired Cache // Clean Cache.
QuoteYes I pressed the SAVE button afterwards ;) LOL!
If you've set the parameter, the parameter should be shown after logout / login - it should remain to the last choose? Also, you can check the database table #__virtuemart_configs, if there is the parameter mail_from_recipient found in the text field config.
QuoteFrom your posted solution I was unsure of the last bit of code  $jlang =JFactory::getLanguage();    I didn't do anything with that. Was it just a note to Milbo or should I delete that code somewhere?
That was a Milbo specific note...

Once again:
Virtuemart Version ?
Joomla Version ?

Note: You could place some debug messages inside the exchanged methode private function sendVmMail (&$view, $recipient, $vendor=false )
to see what happens, or add lines like $mailer->addRecipient('anothermailaddress@example.com'); ...
Title: Re: How to replace the Replyto address in Ask a question
Post by: Aroab38 on June 12, 2012, 15:06:48 PM
I'm using Joomla 2.5.4 and VM 2.0.6

QuoteAlso, you can check the database table #__virtuemart_configs, if there is the parameter mail_from_recipient found in the text field config.
I have attached a copy of the virtuemart_configs table. I'm not too clued up with SQL but it doesn't look like that parameter is in there. Could you please advise?

QuoteNote: You could place some debug messages inside the exchanged methode private function sendVmMail (&$view, $recipient, $vendor=false )
to see what happens, or add lines like $mailer->addRecipient('anothermailaddress@example.com');
I have no idea how to do this :-[

Thanks again for your time helping me!


[attachment cleanup by admin]
Title: Re: How to replace the Replyto address in Ask a question
Post by: stAn99 on June 20, 2012, 22:14:35 PM
Hello Folks, i modified the function a little bit so it sets the sender by default and also uses the order details when the user is not logged in. I tested on VM 2.0.6 and it should be compatible with all Joomla.

/**
* With this function you can use a view to sent it by email.
* Just use a task in a controller todo the rendering of the email.
*
* @param string $view for example user, cart
* @param string $recipient shopper@whatever.com
* @param bool $vendor true for notifying vendor of user action (e.g. registration)
*/
private function sendVmMail (&$view, $recipient, $vendor=false) {
$jlang =JFactory::getLanguage();
if(VmConfig::get('enableEnglish', 1)){
     $jlang->load('com_virtuemart', JPATH_SITE, 'en-GB', true);
}
$jlang->load('com_virtuemart', JPATH_SITE, $jlang->getDefault(), true);
$jlang->load('com_virtuemart', JPATH_SITE, null, true);

ob_start();
$view->renderMailLayout($vendor, $recipient);
$body = ob_get_contents();
ob_end_clean();

$subject = (isset($view->subject)) ? $view->subject : JText::_('COM_VIRTUEMART_DEFAULT_MESSAGE_SUBJECT');
$mailer = JFactory::getMailer();
$mailer->addRecipient($recipient);
$mailer->setSubject($subject);
$mailer->isHTML(VmConfig::get('order_mail_html',true));
$mailer->setBody($body);

if($vendor){   //this is the mail to the vendor!
$mail_from_recipient = VmConfig::get('mail_from_recipient','1');
if ($mail_from_recipient =='1'){
if(isset($view->user)){
$replyto[0] = $view->user['email'];
$replyto[1] = $view->user['name'];
$mailer->addReplyTo($replyto);
}else{
$user = JFactory::getUser(); //fallback
if (!empty($user->id)) {
$mailfrom[0] = $user->email;
$mailfrom[1] = $user->name;

}
else
{
  // what if the user is not logged in or the view does not have the user assigned
  if (!empty($view->orderDetails))
{
   $email = $view->orderDetails['details']['BT']->email;
   $name = $view->orderDetails['details']['BT']->first_name.' '.$view->orderDetails['details']['BT']->last_name;
   $mailfrom[0] = $email;
   $mailfrom[1] = $name;
   
}

}
}
} //else fetch the Joomla setup email address
}else{
$replyto[0]=$view->vendorEmail;
$replyto[1]= $view->vendor->vendor_name;
$mailer->addReplyTo($replyto);
}


if(!empty($mailfrom)){
$mail_from_setSender = VmConfig::get('mail_from_setsender','1');
if ($mail_from_setSender=='0') {
$mailer->addReplyTo($mailfrom);
}else {
$mailer->setSender($mailfrom);
}
}

if (isset($view->mediaToSend)) {
foreach ((array)$view->mediaToSend as $media) {
//Todo test and such things.
$mailer->addAttachment($media);
}
}

return $mailer->Send();
}
Title: Re: How to replace the Replyto address in Ask a question
Post by: Thomas Kuschel on June 20, 2012, 22:44:02 PM
Hi stAn99,
Note:
I deliberately set the sender _not_ to default because afterwards, the behavior of the function would be changed when implemented in 2.0.6. -
tnx for implementing branch for non-logged-in users (at my site, non-logged-in users would never visit that branch, so I spent no thoughts about it).

In addition, please add the full description in front of the function (adding the "return value"):
/**
* With this function you can use a view to sent it by email.
* Just use a task in a controller todo the rendering of the email.
*
* @param string $view for example user, cart
* @param string $recipient shopper@whatever.com
* @param bool $vendor true for notifying vendor of user action (e.g. registration)
* @return true if successful
*/

because it's very useful for debugging with an IDE, e.g. eclipse.
Thomas
Title: Re: How to replace the Replyto address in Ask a question
Post by: alatak on June 22, 2012, 15:07:12 PM
Hi

I will have a look at your code.

I have fixed already several reply issues. One of them, in some cases,  is that when a user was logged, the vendor email adress was the one from the user.
It will available in the next test version (2.0.7.I).  I will upload this version tonight.
Title: Re: How to replace the Replyto address in Ask a question
Post by: chaldama on July 31, 2012, 12:56:42 PM
I almost forgot about this topic! Somehow I never receive forum notifications.

Thank you Thomas and all others!

Has this feature now been incorporated in the current VM 2.0.8 version?
Title: Re: How to replace the Replyto address in Ask a question
Post by: BaidareW on August 05, 2012, 22:39:09 PM
Sorry guys, maybe tired after watching so many Olympic games, but with VM 2.08e I still reply to my self instead of customer when replying to order e-mail and don't know hot to set this as it was in VM 1.

Also where to find "Receive vendor mail with recipient address" ? Couldn't find it :)

Thanks for your answers :)
Title: Re: How to replace the Replyto address in Ask a question
Post by: hoseonline on July 25, 2013, 11:54:14 AM
I,

I had implement the code, but the Sender isnt change :(
Is there any solution to change the Sender?