Class: SpreePacketa::Models::ShippingCalculator

Inherits:
Spree::ShippingCalculator
  • Object
show all
Defined in:
lib/spree_packeta/models/shipping_calculator.rb

Instance Method Summary collapse

Instance Method Details

#compute_package(package) ⇒ BigDecimal

Calculate shipping rate for a package

Parameters:

  • package (Spree::Stock::Package)

    The package to calculate for

Returns:

  • (BigDecimal)

    The shipping cost



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/spree_packeta/models/shipping_calculator.rb', line 14

def compute_package(package)
  return 0 if package.contents.empty?

  # For Phase 1, use fixed rate from preferences
  # Phase 2 will implement dynamic rate calculation via Packeta API
  base_rate = BigDecimal(preferred_amount.to_s)

  # Apply weight-based multiplier if needed
  total_weight = calculate_total_weight(package)
  weight_multiplier = calculate_weight_multiplier(total_weight)

  (base_rate * weight_multiplier).round(2)
end