Class: SolidusEasypost::Estimator

Inherits:
Object
  • Object
show all
Defined in:
lib/solidus_easypost/estimator.rb

Instance Method Summary collapse

Instance Method Details

#shipping_rates(package, _frontend_only = true) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/solidus_easypost/estimator.rb', line 5

def shipping_rates(package, _frontend_only = true)
  easypost_rates = ShipmentBuilder.from_package(package).rates.sort_by(&:rate)

  shipping_rates = easypost_rates.map { |rate| build_shipping_rate(rate) }.compact
  shipping_rates.min_by(&:cost)&.selected = true

  shipping_rates
end