How to Fix the Product Return Email Notifications in OpenCart 2.2.0.0 - 3.0.2.0
There have been reports that the emails for product returns are not working as expected.
In OpenCart 2.2.0.0 - 2.3.0.2 the emails are sent only by the main store even in a multi-store scenario.
As for the ones in OpenCart 3.0.0.0 - 3.0.2.0, they are not being sent to customers at all.
Well, the good news is that this is fixed in the GitHub repository for the next version of OpenCart.
So, the only choice we have is to give you the fix right here, right now for your current OpenCart version.
The Problem… (For OpenCart 3.0.0.0 - 3.0.2.0)
So, when you click on Add History here, the email to the customer will not be sent, even if the Customer Notified field says “Yes”.
The Problem… (For OpenCart 2.2.0.0 - 2.3.0.2)
The email is being sent, but you cannot change the Sender email address and it will always be sent from the main store email, even if you’re running a multi-store setup.
The store name in the fields "From" and in the mail subject are also fixed.
The Fix for OpenCart 3.0.0.0 - 3.0.2.0
There are two small files you need to install in your setup to resolve this issue.
The first one is an .SQL file that you need to upload via your web hosting control panel.
IMPORTANT NOTE: Where you have the `oc_event`, replace oc_ with your database table prefix. You can find it in your config.php file.
DELETE FROM `oc_event` WHERE `trigger`='admin/model/sale/return/addReturnHistory/after' AND `action`='mail/return'; INSERT INTO `oc_event` SET `code`='admin_mail_return_history', `trigger`='admin/model/sale/return/addReturnHistory/after', `action`='mail/return', `status`=1, `sort_order`=0;
Copy that code and paste it into a text editor (like Notepad++, Dreamweaver, etc.).
Save the file and name it return_email_fix_oc3_event.sql.
Now, go to your web hosting control panel. For our example, we will be using cPanel.
First Step
Login and go to phpMyAdmin.
Second Step
-
Select your Database
-
Click Import
-
Click Choose File
Third Step
-
Upload the .SQL file you just saved.
-
Click Go.
That’s done. The next file is a small modification.
Again, copy this code and paste it into your text editor:
<?xml version="1.0" encoding="utf-8"?> <modification> <name>Fix: Return E-mail is Multistore (for OpenCart 2.2.0.0 - 3.0.2.0)</name> <code>return_email_fix</code> <version>1.0</version> <author>iSenseLabs</author> <link>https://isenselabs.com</link> <file path="admin/{model/sale,controller/mail}/return.php"> <operation error="skip"> <!-- Hooks in OpenCart 2.x, skipped in OpenCart 3.x --> <search><![CDATA[$subject = sprintf($this->language->get('text_subject'), html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8'), $return_id);]]></search> <add position="replace"><![CDATA[ $order_id = $return_query->row['order_id']; $this->load->model('sale/order'); $order_info = $this->model_sale_order->getOrder($order_id); $store_id = (int)$order_info['store_id']; $this->load->model('setting/setting'); $store_name = $this->model_setting_setting->getSettingValue('config_name', $store_id); $store_email = $this->model_setting_setting->getSettingValue('config_email', $store_id); $subject = sprintf($this->language->get('text_subject'), html_entity_decode($store_name, ENT_QUOTES, 'UTF-8'), $return_id);]]></add> </operation> <operation error="skip"> <!-- Hooks in OpenCart 3.x, skipped in OpenCart 2.x --> <search><![CDATA[$data['comment'] = strip_tags(html_entity_decode($comment, ENT_QUOTES, 'UTF-8'));]]></search> <add position="after"><![CDATA[ $order_id = $return_info['order_id']; $this->load->model('sale/order'); $order_info = $this->model_sale_order->getOrder($order_id); $store_id = (int)$order_info['store_id']; $this->load->model('setting/setting'); $store_name = $this->model_setting_setting->getSettingValue('config_name', $store_id); $store_email = $this->model_setting_setting->getSettingValue('config_email', $store_id);]]></add> </operation> <operation error="skip"> <!-- Hooks in OpenCart 3.x, skipped in OpenCart 2.x --> <search><![CDATA[$mail->setSubject(sprintf($this->language->get('text_subject'), html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8'), $return_id));]]></search> <add position="replace"><![CDATA[$mail->setSubject(sprintf($this->language->get('text_subject'), html_entity_decode($store_name, ENT_QUOTES, 'UTF-8'), $return_id));]]></add> </operation> <operation error="skip"> <!-- Hooks in all OpenCarts --> <search><![CDATA[$mail->setFrom($this->config->get('config_email'));]]></search> <add position="replace"><![CDATA[$mail->setFrom($store_email);]]></add> </operation> <operation error="skip"> <!-- Hooks in all OpenCarts --> <search><![CDATA[$mail->setSender(html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8'));]]></search> <add position="replace"><![CDATA[$mail->setSender(html_entity_decode($store_name, ENT_QUOTES, 'UTF-8'));]]></add> </operation> </file> </modification>
Save the file and name it install.xml.
Next, compress the file into a .ZIP and remove the XML part of the name so the file is called return_email_fix.ocmod.zip.
Now, go to your OpenCart dashboard, then Extensions > Installer and upload the .ZIP there.
Now go to Extension > Modifications and click the Refresh button.
That's it.
After implementing these changes, your OpenCart store will be properly sending the customer notifications for product returns via email.
The Fix for OpenCart 2.2.0.0 - 2.3.0.2
If your OpenCart store is running one of those versions, then you will be having problems with the Sender email address, as well as the email subject and “From” field when you process product returns and send customer notifications.
The file you need to use is just the modification, NOT the .SQL file.
So, copy and paste the code from the modification above into a text editor.
This time, you can just name the file return_email_fix.ocmod.xml.
Go to your OpenCart dashboard, go to Extensions > Extension Installer and upload the .XML file there.
Next, go to Modifications and hit the Refresh button.
And you’re all done!
These fixes should resolve any issues with the emails that your store should be sending to customers when you’re processing their Product returns in OpenCart 2.2.0.0 to 3.0.2.0.