Who needs this guide?
This guide is for you if you're:
A Shopify Plus merchant
who is setting up a Seamless Product rewards
and who already has existing Line Item scripts set up in the Scripts Editor
What does the guide do?
During the guide, you'll:
Assess the purpose of your existing script
Add the LoyaltyLion rewards script, so you can start giving free products as rewards
Adjust your existing scripts to not discount anything twice!
Assess your existing script
Typical usages of Shopify Scripts include:
Giving specific customers (e.g. employees) a discount
Giving a discount based on spending
You'll want to assess each script and understand what your intended behaviour is in relation to free products from LoyaltyLion rewards: should a free product be affected by the other part of the script or not?
Add the LoyaltyLion script
At the top of your script, add the LoyaltyLionFreeProductRewards
class down to the corresponding end
block. By adding this, you won't yet have modified your Cart, but you will have made our helpers available to your other functions in your script.
Typically, most users will want to run the LoyaltyLionFreeProductRewards
discounts before any other functions/discounts in your script; the shopper has spent rewards points to get these free products, so having another function/discount take priority may be less generous and may not be what the shopper prefers/expects.
You'll therefore want to immediately run the free product rewards functions and assign the resulting cart to an interim variable (rather than to the Output.cart):
product_rewards = LoyaltyLionFreeProductRewards.new
cart = product_rewards.process_cart(Input.cart)
Adjust your existing scripts
Most users will prefer to not have any other script functions apply to products made free by our cart script. To do so, use the helper we provide. For example:
# In your "employee discount" function
line_items.each do |line|
next if LoyaltyLionFreeProductRewards.applied_to_line?(line)
# next skips to the next line item in the list
# If we got past the `next`, the product was _not_ a LoyaltyLion reward product,
# so we can e.g. give a 10% employee discount here.
end