Class: Spree::Stock::Estimator
- Inherits:
-
Object
- Object
- Spree::Stock::Estimator
- Defined in:
- app/models/spree/stock/estimator.rb
Instance Attribute Summary collapse
-
#currency ⇒ Object
readonly
Returns the value of attribute currency.
-
#order ⇒ Object
readonly
Returns the value of attribute order.
Instance Method Summary collapse
-
#initialize(order) ⇒ Estimator
constructor
A new instance of Estimator.
- #shipping_rates(package, frontend_only = true) ⇒ Object
Constructor Details
#initialize(order) ⇒ Estimator
Returns a new instance of Estimator.
6 7 8 9 |
# File 'app/models/spree/stock/estimator.rb', line 6 def initialize(order) @order = order @currency = order.currency end |
Instance Attribute Details
#currency ⇒ Object (readonly)
Returns the value of attribute currency.
4 5 6 |
# File 'app/models/spree/stock/estimator.rb', line 4 def currency @currency end |
#order ⇒ Object (readonly)
Returns the value of attribute order.
4 5 6 |
# File 'app/models/spree/stock/estimator.rb', line 4 def order @order end |
Instance Method Details
#shipping_rates(package, frontend_only = true) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/models/spree/stock/estimator.rb', line 11 def shipping_rates(package, frontend_only = true) shipping_rates = Array.new shipping_methods = shipping_methods(package) return [] unless shipping_methods shipping_methods.each do |shipping_method| cost = calculate_cost(shipping_method, package) rate = shipping_method.shipping_rates.new(:cost => cost) unless cost.nil? shipping_rates << rate unless rate.nil? end shipping_rates.sort_by! { |r| r.cost || 0 } unless shipping_rates.empty? if frontend_only shipping_rates.each do |rate| rate.selected = true and break if rate.shipping_method.frontend? end else shipping_rates.first.selected = true end end shipping_rates end |