Skip to content

Instantly share code, notes, and snippets.

@laspluviosillas
Created January 20, 2014 21:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laspluviosillas/8529698 to your computer and use it in GitHub Desktop.
Save laspluviosillas/8529698 to your computer and use it in GitHub Desktop.
Example of retrieving offerings.
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