RealTimeDesigner Support Network
Wiki Forums Libraries Docs Support RealTimeDesigner Home
Welcome! Log In Create A New Profile

Advanced

Creating a "discount code" using coupons method

Posted by Alex 
Creating a "discount code" using coupons method
April 28, 2010 01:51PM
I know this is a wanted tutorial, so here i am.
Here i'll describe how to add in your designer a "discount code" for your customers by using external variables and rules.

Step 1: create an external variable dedicated to this
In admin panel, go to "PRODUCT CONFIGURATOR OPTIONS => Manage/Define External Variables", and add one entry.

Name it as you wish, for example "discount_code". This will be visible to you, but not to users. Do not use spaces or special character for this field.

For description, write something clear: it's the text that will be shown to your users. For example, something like "Enter discount code here, if you have one".

Next, set "Show in cart as coupon code" to YES: this is actually the value that will make the variable visible to your users, and will cause the description and a textfield to appear on top of cart for each variable having this option set to YES.

Finally, set "Expire With Submittal" to YES: this will void the value entered by users upon order submittal. If you will set this to NO, the value will remain in memory tii the end of the entire session, which generally means when user closes his browser.

Finally, hit the "Add New" button: congrats, your extvar is now created and users will be able to set values for it in cart!

Step 2: create an external variable rule to apply the discount
In admin panel, go to "PRODUCT CONFIGURATOR OPTIONS => Manage/Define External Variables".
On top of the page, click the "Manage/Define External Variables Rules" link. Here's where you control extvar rules.

You need to add one rule now, let's see what the various fields are:

Rule Name: This will be visible to you, but not to users. It's the name you will use to identify the rule for the next step.
Fior example, "discount_rule"

Rule Desc (max 255 chars): Again, write something clear: it's the text that will be shown in cart to your users.
It will appear on top of each cart entry, as rules can be assigned at product level.
So, this text will appear on top of products subjected to the rule only.
For example, something like "Prices are discounted by 20%".

Source Variable: Here you define which external variable the rule is linked to.
For example, as set in step 1, select "discount_code" here.

Checkvalue: This is the most important part. This fields checks the value passed for the "Source Variable" extvar, which in this case means what your users wrote in the coupon into cart.
The value here can be simple, for example "mycode", or a regular expression to match different strings.
For example, the checkvalue /^rule_.+/ will match any value starting with string "rule_".
For your reference, the preg_match PHP function will be used for regular expressions. If you need to learn how to match complex strng, please refer to preg_match manual page.

Modifier and % Modifier: this is actually easy. These fields controls how fieds subjected to the rule will be modified.
For example, If the goal is the rule to give a 20% discount, you need to set the "% Modifier" field to -20

Good! Now you have your 20% discount rule set. Time to set where it should be applied!

Step 3: Subject pricing fields to rules at product level
In admin panel, go to "PRODUCT OPTIONS => Configure Products => Configure Pricing Structure".
On top, click the "Apply External Variables Rules" button. This is the place.

Initial view will show all the pricing matrix you have in collapsed form. Click the "Expand/Collapse fullview" button to expand the matrix you want to apply the discount rule to.
Now, don 't be scared: depending on how many rules you have, and how many pricing addons the current product has, you may see lot of checkboxes here.
All is easy, though.
Each checkbox will allow you to subject/unsubject each possible pricing field with one extvar rule.
There are some facilities, however:
- Click on a checkbox to select/deselect a single value;
- Click on a rule name to select/deselect all instances of that rule;
- Click on an addon/property name to select/deselect all rules for the addon/property;

In this page, you will see every possible pricing related entry: basic ones, custom addons and also product configurator addons (if any).
If what you want is the rule to give a gloal 20% discount, simply check all the checkboxes.
This basically will apply a -20% modifier to every possible value, which at the end means a global 20% discount.

Once done, click the "save this matrix links" button on bottom of the expanded matrix.

At this point, if you have multiple matrix, you will see a "Clone to matrix" option on top of each matrix. You can use it to replicate the rules assignement you made in other matrices.
Simply select a specific matrix if you want to clone to it too, or "all matrixes" if you want to clone into all of the select product's matrixes.

Great! Now your product is affected by the new rule!

Step 4: The user experience and order management
So, now you have:
- created an external variable
- created an external variable discount rule
- subjected one or more products to that rule
Now, what about the user experinece and order management on your end?

User flow will be easy. The only new thing for him will be one (or more) textfields shown on top of cart, along with an "Apply Codes" button. When he will set a value, the cart will reload and the value will be kept in memory.
If that value matches the rule checkvalue, every price shown in cart that is set to be subjected to the rule will be modified on the fly. If the value will NOT match the ckeckvalue, it will still be saved but will have no effect on pricing.
For this reason, external variables can also be used to ask your users whatever you want: using them to alter pricing is just an extra option.

On your admin end, when you will view a submitted order in "ORDERS => Manage Orders", you may see some blue lines.
If any external variables value had been set, you will see a blue line named "Passed Extvars" in the top-left area.
No matter if those values matched any rule: whatever your customer entered as a value will be shown here, if anything.
Pricing of the order will be already modified acconrdingly to rules, if any of them matched.
As per my example, if you see a blue value like "discount_code=mycode" and "mycode" is the checkvalue you set for a rule, then all items in the order which are subjected to the rule will appear as already discounted.

At the end...
I hope this tutorial was clear enough. I tired to descirbe anything, but at the end the concepts are really simple.
If you want to provide your users discount codes this way, there's a lot of flexibility you can apply.
For example, you could create multiple external varialbes and rules for different types of customer. You can even pre-fill those values by using the "link method" of extvars themselves.
Or you could simply change weekly the "checkvalue" of rules to be sure the same discount code can't be used forever.

As usual, the important thing here is to understnd the concept: external variables can be used for lot of different tasks, and the "discount code" described here is just one possible application.

Also, in case you use the "external notification on submittal", remember that also extvars can be passed to it. In other words, you may alter your own bridge's action by checking what your user passed, or what you passed yourself by using the "link method".

If anyone feels to integrate this thread with other external variables suggestions or ideas, please do.

Bbye!
Re: Creating a "discount code" using coupons method
June 25, 2010 04:25PM
wow...this is very confusing. Can you make it a little easier to understand Alex?
Re: Creating a "discount code" using coupons method
June 25, 2010 10:36PM
I can't really think at making it easier, as this tutorial is already a step-by-step one.
But as usual i'm a developer, so it's possible it's clear only to my eyes.

However... have you tried to follow the described steps, as they're written? If so, can you tell us what's confusing?
I don't think the ENTIRE tutorial is confusing smiling smiley

One note: i will be away (leaving tomorrow early morn) as i wrote here
Sorry, only registered users may post in this forum.

Click here to login