Skip to content

Instantly share code, notes, and snippets.

@joeljackson
Created June 15, 2015 20:19
Show Gist options
  • Save joeljackson/d5c73dc99dd0389363ff to your computer and use it in GitHub Desktop.
Save joeljackson/d5c73dc99dd0389363ff to your computer and use it in GitHub Desktop.
class Variant::AvailabilityProvider
attr_accessor :variant, :context
def initialize(variant, context = nil)
@variant = variant
@context = context
end
def is_available?
return false if variant.out_of_stock? || !variant.enabled?
return true if variant.is_kit? || variant.is_gift? || variant.is_bundle?
if variant.product.track_variant_availability?
variant.count_available.try(:">", 0)
else
variant.count_on_hand.try(:">", 0)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment