Class: SolidusMelhorEnvio::ShippingEstimator
- Defined in:
- app/models/solidus_melhor_envio/shipping_estimator.rb
Instance Attribute Summary
Attributes inherited from Api
Instance Method Summary collapse
-
#initialize ⇒ ShippingEstimator
constructor
A new instance of ShippingEstimator.
- #shipping_rates(package, _frontend_only: true) ⇒ Object
Constructor Details
#initialize ⇒ ShippingEstimator
Returns a new instance of ShippingEstimator.
3 4 5 |
# File 'app/models/solidus_melhor_envio/shipping_estimator.rb', line 3 def initialize super(SolidusMelhorEnvio::Account.find_by(app_name: SolidusMelhorEnvio.config.app_name)) end |
Instance Method Details
#shipping_rates(package, _frontend_only: true) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'app/models/solidus_melhor_envio/shipping_estimator.rb', line 7 def shipping_rates(package, _frontend_only: true) melhor_envio_rates = get_rates_from_melhor_envio(package) shipping_rates = melhor_envio_rates.map do |melhor_envio_rate| build_shipping_rate(melhor_envio_rate, package) end unless shipping_rates.empty? default_shipping_rate = ::Spree::Config.shipping_rate_selector_class.new(shipping_rates).find_default default_shipping_rate.selected = true end shipping_rates end |