Class: Gemgento::PriceTier
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Gemgento::PriceTier
- Includes:
- ProductTouches
- Defined in:
- app/models/gemgento/price_tier.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#is_valid?(quantity, user_group) ⇒ Boolean
Check if PriceTier is valid for the given quantity and user.
Class Method Details
.calculate_price(product, quantity = 1.0, user_group = nil, store = nil) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/models/gemgento/price_tier.rb', line 22 def self.calculate_price(product, quantity = 1.0, user_group = nil, store = nil) store ||= Gemgento::Store.current price = product.attribute_value('price', store).to_f user_group ||= UserGroup.find_by(magento_id: 0) product.price_tiers.where(store: store).where('quantity <= ?', quantity).each do |price_tier| next unless price_tier.is_valid? quantity, user_group price = price_tier.price if price_tier.price < price end return price end |
Instance Method Details
#is_valid?(quantity, user_group) ⇒ Boolean
Check if PriceTier is valid for the given quantity and user.
15 16 17 |
# File 'app/models/gemgento/price_tier.rb', line 15 def is_valid?(quantity, user_group) return quantity >= self.quantity && (self.user_group.nil? || user_group == self.user_group) end |