OpenCart Extension – Email Notification on Affiliate Registration

Standard

Till OpenCart version 1.5.5.1, we don’t get an email notification when an Affiliate signs up. This article describes a very simple process to create an extension that will enable sending email notification for each Affiliate signup to the store owner. I didn’t check the process with OpenCart version 1.5.6. But, it should be working.

While developing a site using OpenCart version 1.5.5.1, I found that on each new Affiliate signup, my client doesn’t get an email notification about the signup. Each time he has to login in the administration panel and check whether any new Affiliate has signed up or not. I started investigating the same and found that in the entire codebase of OpenCart, that’s missing. To resolve the issue, I cam up with the following simple vQMod extension.

The Code (XML):

<modification>
  <id><![CDATA[Email Notification on Each Affilifate Signup  ]]></id>
  <version><![CDATA[1.0]]></version>
  <vqmver><![CDATA[2.1.5]]></vqmver>
  <author><![CDATA[AxeFinch (vqmod by axefinch)]]></author>
  <file name="catalog/controller/affiliate/register.php">
   <operation>
    <search position="after" index="1"><![CDATA[ $this->model_affiliate_affiliate->addAffiliate($this->request->post);]]></search>
    <add><![CDATA[$message ="<strong>You have a new affiliate waiting to be approved.</strong><br><br>"
                             .'<a href="http://www.YOURSITE.com/admin/">Login to review</a>';
                  $message .= '<br><br>';
                  $message .= '<strong>Name:</strong> ' . $this->request->post['firstname'] . ' ' . $this->request->post['lastname'];
                  $message .= '<br>';
                  $message .= '<strong>Email:</strong> ' . $this->request->post['email'];

                  $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('EMAIL_ADDRESS_TO_NOTIFY');
                  $mail->setFrom($this->config->get('config_email'));
                  $mail->setSender($this->config->get('config_name'));
                  $mail->setSubject("An Affiliate Account Has Been Requested");
                  $mail->setHtml($message);
                  $mail->send();
           ]]>
      </add>
   </operation>
  </file>
</modification>

How to deploy the code:

  1. You MUST have vQMod installed and enabled in your OpenCart installation
  2. Copy the above code
  3. Open a text editor and paste the code
  4. Change the YOURSITE.com and EMAIL_ADDRESS_TO_NOTIFY as per your requirement
  5. Save the file as an XML file. You can name it anything like affiliate_signup_notification.xml
  6. Upload the XML file in vqmoq/xml folder in your OpenCart installation
  7. That’s all.

I didn’t test it with the latest OpenCart version 1.5.6. Please let me know your findings and/or comments through the comments area below.

Happy coding :)

Advertisements

7 thoughts on “OpenCart Extension – Email Notification on Affiliate Registration

  1. This is rreally cool. Thanks for the code.
    I can use it in a couple of uses
    1) When an user review comes, send email to admin
    2) With some modificiation, send FedEx Shipping number to the customer

    Appreciate this.

    Somesh

I will be happy to answer your queries

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s