Class: Calculator::Shipping::BoxnowRate
- Inherits:
-
Spree::ShippingCalculator
- Object
- Spree::ShippingCalculator
- Calculator::Shipping::BoxnowRate
- 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 — tier is determined by the smallest sorted dimension
{ small: 8.0, medium: 17.0, large: 36.0 }.freeze
- SIZES_ORDERED =
%i[small medium large].freeze
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.description ⇒ Object
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
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/models/spree/calculator/shipping/boxnow_rate.rb', line 37 def compute_package(package) return nil if package.weight.to_f > MAX_WEIGHT_KG boxes = minimum_bounding_boxes(package) return nil if boxes.nil? best_size = nil boxes.each do |sml| padded = apply_packing_margin({ height: sml[0], width: sml[1], depth: sml[2] }, package) s, m, d = [padded[:height], padded[:width], padded[:depth]].map(&:to_f).sort next if s > MAX_HEIGHT_CM || m > MAX_WIDTH_CM || d > MAX_DEPTH_CM size = box_size_for_height(s) next unless size best_size = smaller_size(best_size, size) end return nil unless best_size price_for(best_size) end |