Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save shopifypartners/620e24814d3152802349ac880f2289e6 to your computer and use it in GitHub Desktop.
Save shopifypartners/620e24814d3152802349ac880f2289e6 to your computer and use it in GitHub Desktop.
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