Post by gulli » Sun Sep 23, 2012 2:16 am

Hi,

I just recently learned of a rather odd issue with opencart and language support: when setting opencart to allow only approved users to login the system sends two emails, the first being the account registration confirmation email and the second being the account approval email after the webmester approves it. The issue is with the account approval email because it sends the email in the language of the backend and not in the users language.

Is there some way of solving this issue?

Regards

Rui

Newbie

Posts

Joined
Thu Aug 30, 2012 11:19 pm

Post by straightlight » Mon Sep 24, 2012 4:07 am

Which OC version are you using ?

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by straightlight » Mon Sep 24, 2012 4:37 am

In admin/model/sale/customer.php file,

replace:

Code: Select all

public function approve($customer_id) {
		$customer_info = $this->getCustomer($customer_id);

		if ($customer_info) {
			$this->db->query("UPDATE " . DB_PREFIX . "customer SET approved = '1' WHERE customer_id = '" . (int)$customer_id . "'");

			$this->load->language('mail/customer');
			
			$this->load->model('setting/store');
						
			$store_info = $this->model_setting_store->getStore($customer_info['store_id']);
			
			if ($store_info) {
				$store_name = $store_info['name'];
				$store_url = $store_info['url'] . 'index.php?route=account/login';
			} else {
				$store_name = $this->config->get('config_name');
				$store_url = HTTP_CATALOG . 'index.php?route=account/login';
			}
	
			$message  = sprintf($this->language->get('text_approve_welcome'), $store_name) . "\n\n";
			$message .= $this->language->get('text_approve_login') . "\n";
			$message .= $store_url . "\n\n";
			$message .= $this->language->get('text_approve_services') . "\n\n";
			$message .= $this->language->get('text_approve_thanks') . "\n";
			$message .= $store_name;
	
			$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($customer_info['email']);
			$mail->setFrom($this->config->get('config_email'));
			$mail->setSender($store_name);
			$mail->setSubject(html_entity_decode(sprintf($this->language->get('text_approve_subject'), $store_name), ENT_QUOTES, 'UTF-8'));
			$mail->setText(html_entity_decode($message, ENT_QUOTES, 'UTF-8'));
			$mail->send();
		}		
	}
with:

Code: Select all

public function approve($customer_id) {
		$customer_info = $this->getCustomer($customer_id);

		if ($customer_info) {
			$this->db->query("UPDATE " . DB_PREFIX . "customer SET approved = '1' WHERE customer_id = '" . (int)$customer_id . "'");
			
			$customer_language_info = $this->db->query("SELECT cgd.`language_id` FROM `" . DB_PREFIX . "customer_group_description` cgd INNER JOIN `" . DB_PREFIX . "customer_group` cg ON (`cg.`customer_group_id` = cgd.`customer_group_id`) INNER JOIN `" . DB_PREFIX . "customer` c ON (c.`customer_group_id` = cg.`customer_group_id`) WHERE c.`customer_id` = '" . (int)$customer_id . "' AND cg.`customer_group_id` = '" . (int)$customer_info['customer_group_id'] . "'");
			
			if ($customer_language_info->num_rows) {			
				$this->load->model('localisation/language');
				
				$language_info = $this->model_localisation_language->getLanguage($customer_language_info->row['language_id']);
				
				if ($language_info) {
					$language_code = $language_info['code'];
					$language_filename = $language_info['filename'];
					$language_directory = $language_info['directory'];
				} else {
					$language_code = '';
					$language_filename = '';
					$language_directory = '';
				}
				
				$language = new Language($language_directory);
				$language->load($language_filename);
				$language->load('mail/customer');
				
				$this->load->model('setting/store');
							
				$store_info = $this->model_setting_store->getStore($customer_info['store_id']);
				
				if ($store_info) {
					$store_name = $store_info['name'];
					$store_url = $store_info['url'] . 'index.php?route=account/login';					
				} else {
					$store_name = $this->config->get('config_name');
					$store_url = HTTP_CATALOG . 'index.php?route=account/login';
				}
		
				$message  = sprintf($language->get('text_approve_welcome'), $store_name) . "\n\n";
				$message .= $language->get('text_approve_login') . "\n";
				$message .= $store_url . "\n\n";
				$message .= $language->get('text_approve_services') . "\n\n";
				$message .= $language->get('text_approve_thanks') . "\n";
				$message .= $store_name;
		
				$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($customer_info['email']);
				$mail->setFrom($this->config->get('config_email'));
				$mail->setSender($store_name);
				$mail->setSubject(html_entity_decode(sprintf($language->get('text_approve_subject'), $store_name), ENT_QUOTES, 'UTF-8'));
				$mail->setText(html_entity_decode($message, ENT_QUOTES, 'UTF-8'));
				$mail->send();
			}
		}		
	}
Note: Each customers must already be assigned to a group when registering an account.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by gulli » Sun Sep 30, 2012 1:46 am

Hi,

Thanks for your reply but I tried it and it's not working. Now when trying to approve a customer I get a blank page and the email doesn't get send.

I'm using opencart 1.5.1.3.

Do you have any other suggestion?

Thanks in advance.

Regards

Newbie

Posts

Joined
Thu Aug 30, 2012 11:19 pm

Post by straightlight » Wed Oct 03, 2012 9:31 pm

Now when trying to approve a customer I get a blank page and the email doesn't get send.
What does your admin - > systems - > error logs states regarding this behavior specifically ?

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: No registered users and 3 guests