Class: Shipping::Calculator

Inherits:
BaseService show all
Defined in:
app/services/shipping/calculator.rb

Overview

Operation to set a new source on invoices and related order and opportunity
Shipping::Calculator.new.process({})

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseService

#initialize, #log_debug, #log_error, #log_info, #log_warning, #logger, #options, #tagged_logger

Constructor Details

This class inherits a constructor from BaseService

Class Method Details

.sampleObject



5
6
7
8
9
10
11
12
13
14
# File 'app/services/shipping/calculator.rb', line 5

def self.sample
  samples = []
  samples << Shipping::ShippingItem.new(sku: 'RLY-4PL-CC', qty_shipped: 1, base_weight: 6.95, shipping_length: 10.5, shipping_width: 10, shipping_height: 5)
  samples << Shipping::ShippingItem.new(sku: 'WSHM-240-03052', qty_shipped: 2, base_weight: 31.2, shipping_length: 36, shipping_width: 16, shipping_height: 16)
  samples << Shipping::ShippingItem.new(sku: 'RLY-12PL', qty_shipped: 3, base_weight: 13.6, shipping_length: 18, shipping_width: 16, shipping_height: 8)
  samples << Shipping::ShippingItem.new(sku: 'WSHM-240-03056', qty_shipped: 10, base_weight: 30, shipping_length: 36, shipping_width: 17, shipping_height: 17)
  samples << Shipping::ShippingItem.new(sku: 'TBS-KIT', qty_shipped: 1, base_weight: 70, shipping_length: 48, shipping_width: 24, shipping_height: 18)
  samples
  Shipping::ShippingCommand.new(shipping_lines: samples, destination_state_code: 'IL')
end

Instance Method Details

#process(shipment_command) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/services/shipping/calculator.rb', line 16

def process(shipment_command)
  return shipment_command unless shipment_command.valid?
  rates = []
  rates << shipping_calculation(shipment_command.destination_state_code, shipment_command.total_weight, shipment_command.oversize?, Shipping::ShippingRate.standard)
  rates << shipping_calculation(shipment_command.destination_state_code, shipment_command.total_weight, shipment_command.oversize?, Shipping::ShippingRate.expedited)
  rates << shipping_calculation(shipment_command.destination_state_code, shipment_command.total_weight, shipment_command.oversize?, Shipping::ShippingRate.priority)
  rates << shipping_calculation(shipment_command.destination_state_code, shipment_command.total_weight, shipment_command.oversize?, Shipping::ShippingRate.priority_am)
  rates

  shipment_command.shipping_rates = rates
  return shipment_command
end