Promo-code
We have added a separate “PROMO CODE” Section in the My Account. This feature allows customers to refer colleague using a unique URL, track referrals, and reward customers with promo codes. We can navigate to the Promo code section from the header menu pr
- Navigating to the Promo Code Tab:
- Log in to the website account.
- Go to the “My Account” page.
- A new tab called “Promo Code” has been created for this purpose.
Generating and Sharing the Referral Link:
- Each customer will be provided with a unique referral URL containing their customer ID.
- On the “Promo Code for Referral Link” tab, there is a share button.
- Clicking the share button will copy the unique referral URL to your clipboard.
Using the Referral Link:
- The customer can share this URL with their friends.
- When a new customer uses the referral link, they will be directed to the registration page.
- The URL will include the unique ID of the referring customer.
Registering a New Customer:
- The new customer completes the registration form.
- Upon clicking “Create Account,” a new customer account is created.
- The unique ID from the referral URL is stored in the new customer’s record as the “Referral ID.”
Tracking Referrals:
- To find out who referred a new customer:
- Search for the new customer’s email ID in NetSuite.
- Navigate to the Referral ID field to see the referring customer.”
- The “Referral ID” field is of type list/record and holds the details of the referring customer.
Rewarding the Referring Customer:
- By searching the “Referral ID” in NetSuite, you can find the referring customer’s record.
- This allows you to identify who referred the new customer and reward them accordingly.
- The promo code will be sent to the referring customer based on the referral ID.
How the Promo Code is Sent:
We have created a workflow and workflow script to validate email sending. The workflow functions as follows:
- When a newly created customer places their first order:
- An email is sent to the customer regarding their sales order.
- An additional email is sent to the referred customer, providing them with a promotional code.
The Extension:
The Template file:
Entry file : JJ.promoCode.promoCode.js
define(
'JJ.promoCode.promoCode'
, [
'JJ.promoCode.promoCode.Router'
]
, function (
promoCodeRouter
) {
'use strict';
return {
mountToApp: function mountToApp(container) {
var myAccountMenu = container.getComponent("MyAccountMenu");
var preordersMenuGroup = {
id: "promoCode",
name: "Promo Code",
index: 6
}
myAccountMenu.addGroup(preordersMenuGroup);
var myAccountMenu = container.getComponent("MyAccountMenu");
var preOrdersViewAll = {
id: "promoCode",
groupid: "promoCode",
name: "Referral Link",
index: 1,
url: "promocode"
}
myAccountMenu.addGroupEntry(preOrdersViewAll);
return new promoCodeRouter(container);
}
};
});
Create new router file : JJ.promoCode.promoCode.Router.js
define(
'JJ.promoCode.promoCode.Router', [
'JJ.promoCode.promoCode.View', 'Backbone'
],
function (
promoCodeView, Backbone
) {
'use strict';
return Backbone.Router.extend({
routes: {
'promocode': 'PromoCode',
},
initialize: function (application) {
this.application = application;
},
//PromoCodeRouter is used for creating new page for Referral Link.
PromoCode: function () {
var view = new promoCodeView({
application: this.application
})
view.showContent();
}
});
}
);
View file: promoCode.View.js
// @module JJ.promoCode.promoCode
define('JJ.promoCode.promoCode.View'
, [
'jj_promocode_promocode.tpl'
, 'Backbone',
'Utils',
'Profile.Model'
]
, function promoCodeView(
jj_promocode_promocode_tpl
, Backbone,
Utils,
ProfileModel
) {
'use strict';
return Backbone.View.extend({
template: jj_promocode_promocode_tpl,
title: Utils.translate('Referral Link'),
page_header: Utils.translate('Referral Link'),
attributes: {
id: 'promocode',
'class': 'promoCodeView'
}
, getBreadcrumbPages: function () {
return {
text: this.title
, href: '/promocode'
};
},
getSelectedMenu: function getSelectedMenu() {
return 'promocode';
}
, getContext: function getContext() {
// To copy the URL to clipboard
$(document).ready(function () {
$('.referral-link-share-button').on('click', function () {
var inputField = $('.referral-link-url').get(0);
inputField.select();
document.execCommand('copy');
inputField.setSelectionRange(0, 0);
alert('The URL has been copied to clipboard. You can now share with your friends.');
});
});
// To pass the unique URL to the template.
var profileModel = ProfileModel.getInstance();
var customerId = profileModel.id;
var scEnvironment = SC.ENVIRONMENT;
var baseUrl = scEnvironment.checkoutUrl;
var touchpoint = scEnvironment.siteSettings.touchpoints.register;
return {
customerId: customerId,
baseUrl: baseUrl,
touchpoint: touchpoint
};
}
});
});
Then we have workflow and workflow script for sending the mail and validation like only for first salesOrder the email has to send so for this refer : https://jjknowledgebase.com/post/70193
We need add some HTML code and javascript code in getcontext in view.js of registeration view:
Template:
<div class="registration-form-controls-group" data-validation="control-group" hidden>
<label class="registration-form-label">
{{translate 'Referral Link <small class="registration-form-required">*</small>'}}
</label>
<div class="registration-form-controls" data-validation="control">
<input type="text" name="custentity_referral_id" id="register-referral-link" class="registration-form-input"
value="{{custId}}">
</div>
</div>
View.js getcontext function
let url = new URL(window.location.href);
let custId = url.searchParams.get('custId');
$("#register-referral-link").val(custId);