Page 1 of 1

Creating a custom email trigger for new Affiliate sign ups

Posted: Mon Dec 06, 2010 6:41 am
by jis
How can I creat a custom email trigger? We need to have an email sent to Affiliates when they sign up.

Re: Creating a custom email trigger for new Affiliate sign ups

Posted: Mon Dec 06, 2010 7:06 am
by mazhar
At the moment system doesn't have any support for sending notifications on affiliate sign-up. You can accomplish this with customization. For example first of all create an Email template and fill in the details. In body section of Email template let's say you need store information, current affiliate information and current user account information. Suppose we are going to have following three variables in template body for dynamic information
$store => store information
$affiliate = affiliate information
$user = user account information

Now do the desired coding in template body using these three variables and finally we need to trigger an Email using this new template upon each signup. In order to do this you need to go to eidt Website/ConLib/AffiliateRegForm.ascx.cs file and locate following code block

Code: Select all

 _Affiliate.Save();
Group group = new Group();
group.Name = string.Format("Affiliate [{0}]", _Affiliate.Name);
group.Save();
Token.Instance.User.UserGroups.Add(new UserGroup(Token.Instance.User.UserId,group.GroupId));
Token.Instance.User.Save();
_Affiliate.GroupId = group.GroupId;
_Affiliate.Save();
and then update it as below

Code: Select all

 _Affiliate.Save();
Group group = new Group();
group.Name = string.Format("Affiliate [{0}]", _Affiliate.Name);
group.Save();
Token.Instance.User.UserGroups.Add(new UserGroup(Token.Instance.User.UserId,group.GroupId));
Token.Instance.User.Save();
_Affiliate.GroupId = group.GroupId;
_Affiliate.Save();

//Signup Notification Code Start

            CommerceBuilder.Messaging.EmailTemplateCollection emailTemplates = CommerceBuilder.Messaging.EmailTemplateDataSource.LoadForCriteria(" Name = 'AffiliateSignupTemplateName");
            if (emailTemplates.Count > 0)
            {
                emailTemplates[0].Parameters.Add("store", Token.Instance.Store);
                emailTemplates[0].Parameters.Add("affiliate", _Affiliate);
                emailTemplates[0].Parameters.Add("user", Token.Instance.User);
                emailTemplates[0].ToAddress = Token.Instance.User.Email;
                emailTemplates[0].Send();
            }
            //Signup Notification Code End

where AffiliateSignupTemplateName = what ever is the name of your signup template, so you need to place correct template name in place of it. Save the file and try some demo affiliate signup.