Class: Calculator::Shipping::UberDirectQuote

Inherits:
ShippingCalculator
  • Object
show all
Defined in:
app/models/spree/calculator/shipping/uber_direct_quote.rb

Overview

Prices an "Uber Direct Delivery" shipping method against a real, live Uber Direct quote rather than a flat/configured rate. Same zero-registration mechanism as DoordashQuote — any < Spree::ShippingCalculator subclass is auto-discovered by Spree::Stock::Estimator, confirmed directly against spree_core's own shipping_method.rb.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.clear_unavailable(order_id) ⇒ Object



48
49
50
# File 'app/models/spree/calculator/shipping/uber_direct_quote.rb', line 48

def self.clear_unavailable(order_id)
  Thread.current[:spree_uber_direct_quote_unavailable_order_ids]&.delete(order_id)
end

.descriptionObject



16
17
18
# File 'app/models/spree/calculator/shipping/uber_direct_quote.rb', line 16

def self.description
  'Uber Direct (live quote)'
end

.mark_unavailable(order_id) ⇒ Object



40
41
42
# File 'app/models/spree/calculator/shipping/uber_direct_quote.rb', line 40

def self.mark_unavailable(order_id)
  (Thread.current[:spree_uber_direct_quote_unavailable_order_ids] ||= []) << order_id
end

.unavailable?(order_id) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'app/models/spree/calculator/shipping/uber_direct_quote.rb', line 44

def self.unavailable?(order_id)
  Thread.current[:spree_uber_direct_quote_unavailable_order_ids]&.include?(order_id) || false
end

Instance Method Details

#available?(package) ⇒ Boolean

Called by Estimator to filter which shipping methods even attempt a compute_package call. Skips the Uber Direct API round-trip entirely for an order with no ship address yet — the real "can Uber Direct serve this address" check still happens inside SpreeUberDirect::Quote itself.

Returns:

  • (Boolean)


57
58
59
# File 'app/models/spree/calculator/shipping/uber_direct_quote.rb', line 57

def available?(package)
  package.order.ship_address.present?
end

#compute_package(package) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/models/spree/calculator/shipping/uber_direct_quote.rb', line 20

def compute_package(package)
  result = SpreeUberDirect::Quote.call(package.order)
  if result.nil?
    # Same object-identity bridge DoordashQuote's own compute_package
    # needs, for the identical reason: `package.order` is not the
    # same in-memory object `create_proposed_shipments` holds as
    # `self` (spree_core's InventoryUnitBuilder deliberately defers
    # loading that association) — a direct
    # `package.order.warnings |= [...]` here would silently mutate a
    # throwaway copy discarded the instant this method returns. See
    # SpreeUberDirect::OrderDecorator for the merge-back half of this
    # bridge, and spree_doordash's own CHANGELOG (0.1.3) for the full
    # story of how this was originally found live.
    self.class.mark_unavailable(package.order.id)
    return nil
  end

  result.fee_cents / 100.0
end