Forked from gavinballard/buy-set-get-x-off-campaign.rb
Last active
March 22, 2017 12:56
-
-
Save shopifypartners/b177d141413a4756820fc8166528009c to your computer and use it in GitHub Desktop.
Shopify Scripts BuySetGetXOffCampaign example - https://www.shopify.com/partners/blog/109804486-getting-started-with-shopify-scripts-a-practical-walkthrough
This file contains hidden or 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
# The campaign class. | |
class BuySetGetXOffCampaign | |
def initialize(selector, discount, partitioner) | |
@selector = selector | |
@discount = discount | |
@partitioner = partitioner | |
end | |
def run(cart) | |
applicable_items = cart.line_items.select do |line_item| | |
@selector.match?(line_item) | |
end | |
discounted_items = @partitioner.partition(cart, applicable_items) | |
discounted_items.each do |line_item| | |
@discount.apply(line_item) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment