Page 1 of 2

BCC customer order email to store owner

Posted: Mon Aug 23, 2010 9:03 am
by mikki
Hi Everyone,

It's been suggested I try here by "frame" over at the original open/chromiumcat forums. So I'll just post what I put there.

------------------------------------------------------http://forum.chromiumcart.com/index.php ... l---------
Wanted to ask if it possible that when an order is completed and the confirmation email sent to the customer that that email could be BCCed to the store owner also?

It's basically a bit of a work-around for a small issue. I'm still running a 0.7 build and although the whole thing is going 1.x next year the client has no money for it at the moment. So it's all patches for the moment :]
-----------------------------------------------------------------------------------------------------------------------------------------

Thanks to anyone who can assist.

Re: BCC customer order email to store owner

Posted: Mon Aug 23, 2010 9:42 am
by Brent
In library/cart/order.php, about line 122
change

Code: Select all

if ($this->config->get('config_email_send') ) {
				    $this->mail->setTo($this->data['email']);
				    $this->mail->setFrom($this->config->get('config_email'));
				    $this->mail->setSender($this->config->get('config_store'));
				    $this->mail->setSubject($this->data['email_subject']);
				    $this->mail->setText($this->data['email_text']);
				    $this->mail->setHtml(html_entity_decode($this->data['email_html']));
				    $this->mail->send();
			    }
to

Code: Select all

if ($this->config->get('config_email_send') ) {
				    $this->mail->setTo($this->data['email']);
				    $this->mail->setFrom($this->config->get('config_email'));
				    $this->mail->setSender($this->config->get('config_store'));
				    $this->mail->setSubject($this->data['email_subject']);
				    $this->mail->setText($this->data['email_text']);
				    $this->mail->setHtml(html_entity_decode($this->data['email_html']));
				    $this->mail->send();
					$this->mail->setTo($this->config->get('config_email'));
					$this->mail->send();
			    }
This is automatic in AlegroCart.

Re: BCC customer order email to store owner

Posted: Mon Aug 23, 2010 2:22 pm
by leo
Another solution:

change library/cart/order.php from:

Code: Select all

if ($this->config->get('config_email_send')) {
$this->mail->setTo($this->data['email']);
$this->mail->setFrom($this->config->get('config_email'));
$this->mail->setSender($this->config->get('config_store'));
$this->mail->setSubject($this->data['email_subject']);
$this->mail->setText($this->data['email_text']);
$this->mail->setHtml($this->data['email_html']);
$this->mail->send();
}
to

Code: Select all

if ($this->config->get('config_email_send')) {
$this->mail->setTo($this->data['email']);
$this->mail->setFrom($this->config->get('config_email'));
$this->mail->setSender($this->config->get('config_store'));
$this->mail->setBcc($this->config->get('config_email'));
$this->mail->setSubject($this->data['email_subject']);
$this->mail->setText($this->data['email_text']);
$this->mail->setHtml($this->data['email_html']);
$this->mail->send();
}
and change library/mail/mail.php from:

Code: Select all

var $to;
var $from;

to

Code: Select all

var $to;
var $bcc;
var $from;
and from:

Code: Select all

function setTo($to) {
$this->to = $to;
}
function setFrom($from) {
$this->from = $from;
}
to

Code: Select all

function setTo($to) {
$this->to = $to;
}
function setBcc($bcc) {
this->bcc = $bcc;
}
function setFrom($from) {
$this->from = $from;
}
and from:

Code: Select all

if (is_array($this->to)) {
$to = implode($this->to, ',');
} else {
$to = $this->to;
}
if ($this->charset) {
$charset = $this->charset;
} else { 
$charset = 'utf-8';
}
to

Code: Select all

if (is_array($this->to)) {
$to = implode($this->to, ',');
} else {
$to = $this->to;
}
if (is_array($this->bcc)) {
$bcc = implode($this->bcc, ',');
} else {
$bcc = $this->bcc;
}
if ($this->charset) {
$charset = $this->charset;
} else { 
$charset = 'utf-8';
}
and from:

Code: Select all

$headers .= 'Reply-To: ' . $this->sender . '<' . $this->from . '>' . $eol;   
$headers .= 'X-Mailer: PHP/' . phpversion() . $eol;  
to

Code: Select all

$headers .= 'Reply-To: ' . $this->sender . '<' . $this->from . '>' . $eol;   
if ($this->bcc) {
$headers  .= 'Bcc: ' . $bcc . $eol; 
}
$headers .= 'X-Mailer: PHP/' . phpversion() . $eol;  

Re: BCC customer order email to store owner

Posted: Tue Aug 24, 2010 3:32 am
by mikki
Thanks for your help guys. I'll have a look into that. Am still running Opencart 0.7.7/8 and everything does work fine apart from sometimes paypal doesn't send tracking back to the cart so there is an order (payment sent), but not log of it in the backend, heh. It's just because it's old.

If anyone does have the time could they break down what the changes are actaully doing and how does it know to BCC to the store owner. I assume it's variable that uses the owner info from the admin to get the forwarding address. Sorry, am a designer and far less of a code monkey :]

Re: BCC customer order email to store owner

Posted: Tue Aug 24, 2010 7:35 am
by Brent
Leo
Thanks for posting the Bcc Code.
I needed to do that for Bulk Newsletter and Mail functions.
Your code saved a lot of time.
Thanks again.

Re: BCC customer order email to store owner

Posted: Sun Oct 03, 2010 5:33 am
by mikki
Going to give this a go later (had lots of other stuff to do to the side so it got put back).

Just wondering what the difference in funtionality there is between Brent and Leo's solutions are. Seeing as Brent's is just changing one thing in one file and Leo's is changing a lot of things in a lot of files :]

Re: BCC customer order email to store owner

Posted: Sun Oct 03, 2010 10:02 am
by leo
The first solution sends the e-mail to the owner adding his e-mail address to To: (the customer sees the shop owner's e-mail address), the second one sends a Bcc copy.

Re: BCC customer order email to store owner

Posted: Sun Oct 03, 2010 10:41 am
by mikki
Ah. Neat. It's a lot more effort to put it in a defferent field :]

Re: BCC customer order email to store owner

Posted: Sun Oct 03, 2010 11:04 am
by leo
A new function setBcc has to be added and the header of the e-mail has to be modified.

Re: BCC customer order email to store owner

Posted: Mon Dec 13, 2010 5:44 pm
by mikki
Well, this has reared it's ugly head once more. Hope some people are still around :]

The problem is that sometimes Paypal/the cart doesn't process an order correctly. In theory the cart sends a payment to paypal and then paypal confirms it and it's then added in the the backend as a successful order and all the info that entails. However, sometimes it doesn't get back to the backend so there is no order showing up. However there is a paypal transaction, but it only shows the name and the amount; not what they ordered (so you have to keep asking the buyer and you can't track the progress of the order in the backend).

The order email cc was supposed to be a patch for this. However it only works if the transaction is successfuly accepted back to the backend in the first place. So in fact it doesn't fix anything, heh.

So the obvious question is: Can a full order statement be sent to the admin without it first needing to be parsed through paypal and back. ie: even if it fails to be added to the back end there is a copy sent to the admin which details their actual items?