Created
June 15, 2015 20:19
-
-
Save joeljackson/d5c73dc99dd0389363ff to your computer and use it in GitHub Desktop.
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 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