-
-
Save gavinballard/dadd4508682b3d72bc58ad47347d21f7 to your computer and use it in GitHub Desktop.
Shopify Scripts Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Use an array to keep track of the discount campaigns desired. | |
CAMPAIGNS = [ | |
# $5 off all items with the "sale" tag | |
ItemCampaign.new( | |
AndSelector.new( | |
TagSelector.new("sale"), | |
ExcludeGiftCardSelector.new, | |
), | |
MoneyDiscount.new(5_00, "5$ off all items on sale",), | |
), | |
# 10% off all items with a price lower than $100 | |
ItemCampaign.new( | |
AndSelector.new( | |
ExcludeGiftCardSelector.new, | |
PriceSelector.new(:lower_than, Money.new(cents: 100_00)), | |
), | |
PercentageDiscount.new(10, "10% off all items under 100$"), | |
), | |
# Give every 3rd item with the tag "letter" for free | |
BogoCampaign.new( | |
TagSelector.new("letter"), | |
PercentageDiscount.new(100, "Third item is free"), | |
LowToHighPartitioner.new(2,1), | |
) | |
] | |
# Iterate through each of the discount campaigns. | |
CAMPAIGNS.each do |campaign| | |
# Apply the campaign onto the cart. | |
campaign.run(Input.cart) | |
end | |
# In order to have the changes to the line items be reflected, the output of | |
# the script needs to be specified. | |
Output.cart = Input.cart |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment