Created
January 20, 2014 21:37
-
-
Save laspluviosillas/8529698 to your computer and use it in GitHub Desktop.
Example of retrieving offerings.
This file contains 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
Spree::LineItem.class_eval do | |
def offering | |
variant.offering(self.qty) | |
end | |
end | |
Spree::Variant.class_eval do | |
# has_many :volume_prices (viene de la gema) | |
has_many :offerings | |
# Get the right offering for a given Quantity. | |
def offering(qty) | |
if has_volume_prices? | |
self.volume_price(qty).offering | |
else | |
# If this variant does not have any volume prices, then it should only be associated to one offering. | |
offerings.first | |
end | |
end | |
def has_volume_prices? | |
volume_prices.count > 0 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment