Infigo now supports an extended budget functionality following on from the default functionality outlined in this article: Creating and using budgets.
The new enhancement allows storefront administrators to define auto-top of of budgets based upon pre-defined criteria.
This will now support the following:
- Budget applied to:
- All Users
- Department (Defined by department ID(s))
- Budget top up mode
- Will automatically add the budget amount every pre-defined period (known as TopUpOnly)
- Example: Apply £150 every month to the users budget amount
- Will automatically top up to the budget amount every pre-defined period (Known as TopUpTo)
- Example: If the user had £50 budget left, it would automatically add £100 to the user's budget to top them up to £150. However, If they placed an order in month 1, and then the order was cancelled in month 2, the order amount would then be refunded back onto their budget, meaning they would have £150+refund value in their budget.
- Will automatically add to the budget (Known as TopUpStrict).
- Example: Very similar to the above scenario, however, if they were refunded a previous budget amount, it would never go above the defined budget amount.
- Will automatically add the budget amount every pre-defined period (known as TopUpOnly)
Please note: Budget amount must be a positive number
- Budget Recurrence
- This is the time period in which you would like the budget to be topped up.
The budget recurrence is configured via a 'Cron Expression'
- This is the time period in which you would like the budget to be topped up.
Steps to configure
First, you will need to raise a ticket with the support team to request that they install the script on your storefront. and allow you access to the MegaScript Instances menu.
Once the script has been installed, follow the steps below:
1. Sign in to your storefront as a storefront administrator then navigate to Configuration > MegaScripts > MegaScripts Management and ensure the 'Budgets' MegaScript is enabled.
Next, go to Configuration > MegaScripts > MegaScripts Instances. This will take you to the following screen:
2. Select Budget from the dropdown highlighted below and click Create:
3. To create the new instance, you will need to provide a Name, enable RunBackground, and also enable IsCronInterval. For the purposes of this article, we will set Name to "Monthly Budget":
4. The next step in configuration is to set the Cron Expression. Cron Expressions are used in many systems to set a task to run at X time. For example, it can be configured to trigger every Monday; the first day of each month; 12:00 each day etc. For more information on Cron Expressions, please see this external resource.
Note: If your Cron expression is not accepted when you save the script, run it through the validator found here: https://crontab.guru/
We officially support all Cron expressions which are considered valid by this website.
As the budget for this article is set to run at 00:00 on the first of each month, the following expression is used:
0 0 1 * *
Please note that the budget will be updated based on UTC, not your current time zone.
With the cron expression added, the configuration now looks like this:
5. Now that the script instance is configured to run when we want it to, the next step is to add the configuration. Depending on whether you want the budget to apply to a Specific Department or All Users, you will need to copy in the appropriate configuration below:
Specific Department
{ logLevel: 4, targetAudience: { type: 2, data: '32' }, topUpMode: 1, amount: 150, sendEmails: true }
All Users
{ logLevel: 4, targetAudience: { type: 1 }, topUpMode: 1, amount: 150, sendEmails: true }
For the purposes of this article, this is configured to apply to the Department with the ID 32. With the configuration copied in, your MegaScript instance will look something like this:
6. After pasting in the basic configuration, the next step is to change it to match your requirements. A breakdown of each item can be found below:
loglevel
This setting sets how much information is logged within the MegaScript instance logging. For full debugging, set this to 4.
targetAudience
These settings allow you to configure who the budgets will be applied to.
Type:
If Type is set to 1, then the budget will apply to all users.
If it is set to 2, then the budget will apply to whichever department is set using Data. If this
option is selected, Data must be set.
Data:
If Type is set to 2, then this value will need to be the ID of the Department you want the budget
to be applied to.
topUpMode
This is used to set the Top Up Mode as per the beginning of this article:
1: TopUpOnly
2: TopUpTo
3: TopUpStrict
amount
Quite simply, this is the target budget that topUpMode will use/try to achieve.
sendEmails
If set to true, then the email Budget.BudgetApplied will be sent out each time the Cron Expression triggers.
7. With the configuration options above taken into account, and the goal of Department 32 having a budget that resets to £200 at 00:00 on the first of each month, the final configuration will be as seen below:
8. Once the above steps have been completed, all that's left is to click Save, and the script instance will be configured.
Note: If you are applying the budget to a Department/Departments, then steps 2-8 will need to be followed for each Department.
IMPORTANT if you have a MegaScript set to run with a cron expression. If you run the script, then disable it, then re-enable it at a later date, the script will run to 'play catch up'. This means it will run outside of the cron expression you've setup. We are updating this functionality to give you more control, however please note this when using cron expressions and disabling / enabling MegaScripts.
0 Comments