I am having a little bit of trouble with discount codes and want to check best practice.
I need to check the user-inputted code against various criteria:
does it exist (code = code (text)
is it expired (yes / no)
is the current user in the Excluded users list (list of data type Users) - list of users who aren’t eligible for the discount, only when this voucher’s Once Per User is yes
is the code eligible Once per User (yes / no) - whether this code should only be used once per user
is the cart item’s product in the Products Excluded list (list of data type Products) - the discount shouldn’t be applied to products that are in this list
is the code over its Limit (number) - the max number of times this code can be used
does this code Remove shipping (yes / no) - if yes, the shipping fee is removed from the order
There are some hard stops:
doesn’t exist
expired
user excluded (only when once per user is yes)
over its limit
the Cart Item’s product has Discount Eligible (yes/no) is no
and some variables:
does the code remove shipping
is this cart item in the excluded products list (I haven’t put this as a hard stop because the discount might be applied to other products on the list)
Here are my questions:
I first want to ask whether you’d recommend using backend workflow or on-page? I’m thinking I should run a backend workflow on a list (cart items) as some products aren’t eligible
Is it better to add a terminate workflow step for each hard stop, rather that say “if it’s condition A OR condition B OR condition C”?
would you trigger custom events to fork off different scenarios?
discount codes would have:
type - free shipping, percentage, fixed price etc
value
orders_count
max uses (all customers)
expiry date
one time (per customer)
status - active, inactive, expired
code
product categories (used to filter products if needed)
when add discount to order then lookup the discount to see if it is valid - I’d just use a status and expiry here
if valid then apply the discount to the order - here you’d have front end custom events filtered to the type of discount
if invalid show error
in the backend each time an order is processed I’d update the discount code properties and status
also have an expiry workflow here to change the status once the discount expires
in terms of updating the cart items, you could do this on the front end since the cart items would likely be less than 100 so a change list of things would work fine
I generally try to avoid “terminate” as it just feels unnecessary if you have the right conditions on custom events
you could do this
event - terminate - event - terminate - event
but that involves checking conditions 5 times so it’s less wu to do
event - event - event
ie 3 conditions to check
the only time a terminate would be more efficient is if the conditions to check after it are heavy - but most conditions I use are aggregate count > 0 or existing page data conditions which are very lightweight.
are there any other takes on this? at the moment I have a backend workflow running on a list (the cart items), and if it’s valid, it saves ‘apply discount’ as ‘yes’ to the database against that cart item
I would use the backend workflow so you could check against the coupons while ignoring privacy rules. I would assume you would want the codes to not be public so anyone can just grab your list of coupon codes.
I do sometimes add a terminate workflow when it helps simplify my logic.
I would not necessarily trigger or fork off different scenarios unless it made it more simple to do so.
I build differently when I build for myself compared to when I build for someone else. I sometimes make it simpler to understand when I build for someone else because I want them to be able to understand what I did later on.
Hope that helps give another opinion, there are definitely multiple ways to do one thing in Bubble.