Class: Calculator::Shipping::DoordashQuote
- Inherits:
-
ShippingCalculator
- Object
- ShippingCalculator
- Calculator::Shipping::DoordashQuote
- Defined in:
- app/models/spree/calculator/shipping/doordash_quote.rb
Overview
Prices a "DoorDash Delivery" shipping method against a real, live
DoorDash Drive quote rather than a flat/configured rate.
Spree::Stock::Estimator calls calculator.compute(package), which
Spree::Calculator#compute dispatches to compute_package by
demodulizing the argument's class name (Spree::Stock::Package ->
"package") — no override of #compute itself needed.
Class Method Summary collapse
Instance Method Summary collapse
-
#available?(package) ⇒ Boolean
Called by Estimator to filter which shipping methods even attempt a compute_package call.
- #compute_package(package) ⇒ Object
Class Method Details
.description ⇒ Object
17 18 19 |
# File 'app/models/spree/calculator/shipping/doordash_quote.rb', line 17 def self.description 'DoorDash Drive (live quote)' end |
Instance Method Details
#available?(package) ⇒ Boolean
Called by Estimator to filter which shipping methods even attempt a compute_package call. Skips the DoorDash API round-trip entirely for an order with no ship address yet (early checkout, before Estimator would sensibly be asked at all) — the real "can DoorDash serve this address" check still happens inside SpreeDoordash::Quote itself (compute_package returning nil is what actually makes the rate not show up).
35 36 37 |
# File 'app/models/spree/calculator/shipping/doordash_quote.rb', line 35 def available?(package) package.order.ship_address.present? end |
#compute_package(package) ⇒ Object
21 22 23 24 25 26 |
# File 'app/models/spree/calculator/shipping/doordash_quote.rb', line 21 def compute_package(package) result = SpreeDoordash::Quote.call(package.order) return nil unless result result.fee_cents / 100.0 end |