Class: Calculator::Shipping::BoxnowRate

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

Constant Summary collapse

MAX_WEIGHT_KG =

Hard limits (BoxNow)

20.0
MAX_HEIGHT_CM =
36.0
MAX_WIDTH_CM =
45.0
MAX_DEPTH_CM =
60.0
SIZE_MAX_HEIGHT_CM =

Size thresholds (height decides the size; width/depth are constant limits)

{
  small:  8.0,
  medium: 17.0,
  large:  36.0
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.descriptionObject



31
32
33
# File 'app/models/spree/calculator/shipping/boxnow_rate.rb', line 31

def self.description
  Spree.t(:shipping_boxnow_rate)
end

Instance Method Details

#compute_package(package) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/models/spree/calculator/shipping/boxnow_rate.rb', line 35

def compute_package(package)
  return nil if package.weight.to_f > MAX_WEIGHT_KG

  dims = estimated_parcel_dimensions_cm(package)
  return nil if dims.nil?

  dims = apply_packing_margin(dims, package)

  # allow rotation by sorting dims (smallest->height threshold)
  s, m, d = [dims[:height], dims[:width], dims[:depth]].map(&:to_f).sort
  return nil if s > MAX_HEIGHT_CM || m > MAX_WIDTH_CM || d > MAX_DEPTH_CM

  size = box_size_for_height(s)
  return nil unless size

  price_for(size)
end