Post by RuralSquirrel » Mon Dec 17, 2012 3:51 pm

Hello Forum,

I'm using OC 1.5.3.1 on a client's site, and I've modified bits and pieces of it to fit. The cart currently has products that represent the following:
- items for sale and will get shipped
- registrations for tour programs
- donations & sponsorships

Everything is working great with the store, but I'm trying to make the management process run more smoothly. Each of the three types of products sold is managed in the office by a different department. For example, when a product from the "Donations" category is purchased online, I would love for the admin email AND the fundraising manager to automatically get a copy of the order confirmation email.

The admin email will ALWAYS get the confirmation email (that is standard in OC, so nothing changes here). My hunch is that I need to modify order.php in /catalog/model/checkout/ so that if there is a product named like "Donation" (or "abc" in my example code below), somehow the "To" address in the mail function appends another email address. Here is what I currently have, but in sandbox mode, it's not working yet...

Code: Select all

<?php
class ModelCheckoutOrder extends Model {		

// all functions here until the confirm() function have remained the same

public function confirm($order_id, $order_status_id, $comment = '', $notify = false) {
		
$order_info = $this->getOrder($order_id);
		
		// Set Admin Email List
		$emailList = '';
		
if ($order_info && !$order_info['order_status_id']) {
// lots of code here left unchanged until...
			
			// Products
			$template->data['products'] = array();
				
			foreach ($order_product_query->rows as $product) {
				$option_data = array();
				
				$order_option_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_option WHERE order_id = '" . (int)$order_id . "' AND order_product_id = '" . (int)$product['order_product_id'] . "'");
				
				foreach ($order_option_query->rows as $option) {
					if ($option['type'] != 'file') {
						$value = $option['value'];
					} else {
						$value = utf8_substr($option['value'], 0, utf8_strrpos($option['value'], '.'));
					}
					
					$option_data[] = array(
						'name'  => $option['name'],
						'value' => (utf8_strlen($value) > 250 ? utf8_substr($value, 0, 250) . '..' : $value)
					);					
				}
			  
				$template->data['products'][] = array(
					'name'     => $product['name'],
					'model'    => $product['model'],
					'option'   => $option_data,
					'quantity' => $product['quantity'],
					'price'    => $this->currency->format($product['price'] + ($this->config->get('config_tax') ? $product['tax'] : 0), $order_info['currency_code'], $order_info['currency_value']),
					'total'    => $this->currency->format($product['total'] + ($this->config->get('config_tax') ? ($product['tax'] * $product['quantity']) : 0), $order_info['currency_code'], $order_info['currency_value'])
				);
				
				// Testing different admin email addresses based on products ordered
				
				if (strpos($product['name'],"abc")) { 
					$emailList .= '; test@example.com';
				}
				
			}
	
			// nothing else changed until I need to find a way to append the variable "emailList", which I've tried below in the "setTo" value.
			
				$mail = new Mail(); 
				$mail->protocol = $this->config->get('config_mail_protocol');
				$mail->parameter = $this->config->get('config_mail_parameter');
				$mail->hostname = $this->config->get('config_smtp_host');
				$mail->username = $this->config->get('config_smtp_username');
				$mail->password = $this->config->get('config_smtp_password');
				$mail->port = $this->config->get('config_smtp_port');
				$mail->timeout = $this->config->get('config_smtp_timeout');
				$mail->setTo($this->config->get('config_email') . $emailList);
				$mail->setFrom($this->config->get('config_email'));
				$mail->setSender($order_info['store_name']);
				$mail->setSubject(html_entity_decode($subject, ENT_QUOTES, 'UTF-8'));
				$mail->setText(html_entity_decode($text, ENT_QUOTES, 'UTF-8'));
				$mail->send();
				
				// Send to additional alert emails
				$emails = explode(',', $this->config->get('config_alert_emails'));
				
				foreach ($emails as $email) {
					if ($email && preg_match('/^[^\@]+@.*\.[a-z]{2,6}$/i', $email)) {
						$mail->setTo($email);
						$mail->send();
					}
				}				
			}		
		}
	}
Maybe I'm making this more complicated than it is. I hope I've explained my goal well enough and hope that there are some friendly, smart coders here willing to help!

Thanks,
Mindy : )

Newbie

Posts

Joined
Tue Jul 31, 2012 12:51 pm

Post by RuralSquirrel » Mon Dec 17, 2012 4:07 pm

Actually... before anyone invests time in this, I believe I've found an extension that will work...

http://www.opencart.com/index.php?route ... ail&page=7

Fingers crossed this does the trick!
Mindy :)

Newbie

Posts

Joined
Tue Jul 31, 2012 12:51 pm

Post by marzz » Fri Feb 28, 2014 5:40 am

The admin email will ALWAYS get the confirmation email (that is standard in OC, so nothing changes here)
What if the admin email has 3 email addresses in there? and also in Settings, Mail 3 addresses?
Only 2 email addresses are getting mail?

Newbie

Posts

Joined
Wed Mar 27, 2013 11:37 pm
Who is online

Users browsing this forum: No registered users and 2 guests