-
-
Save shopifypartners/620e24814d3152802349ac880f2289e6 to your computer and use it in GitHub Desktop.
Shopify Scripts product set partitioner - 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
class ProductSetPartitioner | |
def initialize(set_product_ids) | |
@set_product_ids = set_product_ids | |
end | |
def partition(cart, applicable_line_items) | |
# If all items in the product set are in the cart, then all applicable line | |
# items are eligible for the discount. Otherwise, none of them are. | |
cart_product_ids = cart.line_items.map { |line_item| line_item.variant.product.id }.uniq | |
if (@set_product_ids - cart_product_ids).empty? | |
applicable_line_items | |
else | |
[] | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment