Class: Edi::AmazonVc::ShipCodeMapper

Inherits:
Object
  • Object
show all
Defined in:
app/services/edi/amazon_vc/ship_code_mapper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(orchestrator) ⇒ ShipCodeMapper

Returns a new instance of ShipCodeMapper.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'app/services/edi/amazon_vc/ship_code_mapper.rb', line 11

def initialize(orchestrator)
  @orchestrator = orchestrator
  case @orchestrator.warehouse_code
  #
  # Here we look at the warehouse code to ensure we are looking at Canada vs US shipping methods
  #
  #
  # Amazon Vendor Central ship method codes:
  #
  # Canada: Direct Fulfillment CA EDI Ship Method Codes by Carrier:
  # https://vendorcentral.amazon.com/cgi-bin/fileUpload/VCResourceCenter/getResourceCenterFile.cgi?_encoding=UTF8&fileId=MUu0rLX%2Ba3ljGJ1zdtNVwld65kmRb5drmXqdABZw76M%3D&filename=qwpkW2VHo0l7CkFb8%2BuyWXAYHkHm9Pq5XUh%2BX88IYa%2BwujeXTagIJHO%2Fe0TG7JamyJvKKzKM3wE%3D&type=Z2D%2FKCIlWDzSjE2iaXAkzg%3D%3D
  #
  # USA: Direct Fulfillment EDI Ship Method Codes by Carrier:
  # https://vendorcentral.amazon.com/cgi-bin/fileUpload/VCResourceCenter/getResourceCenterFile.cgi?_encoding=UTF8&fileId=TAfnlECpxrFpYMb%2Fb9%2Bl3BdZ6%2FJLG5reVl%2BdcFY9VlY%3D&filename=qwpkW2VHo0l7CkFb8%2BuyWbX4oNRgeUkh5oXFkMa8XxnPKFGmjxnC0i6sQIarKnRgFewmfM1QIyM%3D&type=Z2D%2FKCIlWDzSjE2iaXAkzg%3D%3D
  #
  # We also limit these to what we expect from Amazon Vendor Central DF Canada and US and/or Rural King
  #
  when "AMDR"
    # This is Canada so use Canadian defaults
    @shipping_map = [

        # These are Amazon Vendor Central DF CA Ship Method Codes:

        ShippingOptionResult.new(code: 'CEVA_TH', name: 'CEVA_TH_CA'), # CEVA Threshold Service
        ShippingOptionResult.new(code: 'CEVA_WG', name: 'CEVA_WG_CA'), # CEVA White Glove Service
        ShippingOptionResult.new(code: 'UPS_EXPEDITED_CA', name: 'worldwide_expedited'), # UPS Expedited Service through Ground
        ShippingOptionResult.new(code: 'UPS_EXPRESS_SAVER_CA', name: 'expresssaver'), #U PS Express Saver Service through Air
        ShippingOptionResult.new(code: 'UPS_STANDARD_CA', name: 'standard'), # UPS Standard service through Ground
        ShippingOptionResult.new(code: 'CP_EXPEDITED_CANADA', name: 'canada_post_expedited_parcel'), # CP Expedited through Ground
        ShippingOptionResult.new(code: 'CP_EXPEDITED_CANADA_SIG', name: 'canada_post_expedited_parcel', signature: true), # CP Expedited through Ground + Signature
        ShippingOptionResult.new(code: 'CP_PRIORITY_COURIER', name: 'canada_post_priority_next_am'), # CP Priority through express air
        ShippingOptionResult.new(code: 'CP_PRIORITY_COURIER_SIG', name: 'canada_post_priority_next_am', signature: true), # CP Priority through express air + Signature
        ShippingOptionResult.new(code: 'CP_XPRESSPOST_CANADA', name: 'canada_post_xpresspost'), # CP Xpresspost through air
        ShippingOptionResult.new(code: 'CP_XPRESSPOST_CANADA_SIG', name: 'canada_post_xpresspost', signature: true), # CP Xpresspost through air + Signature
        # put all these weird PKT ship method codes at the end so they don;t interfere with the mor frequently used ones above. What is "jiffy"??
        ShippingOptionResult.new(code: 'CP_EXPEDITED_CANADA_PKT', name: 'canada_post_expedited_parcel'), # CP Expedited Package (jiffy) through Ground
        ShippingOptionResult.new(code: 'CP_EXPEDITED_CANADA_PKT_SIG', name: 'canada_post_expedited_parcel', signature: true), # CP Expedited Package (jiffy) through Ground + Signature
        ShippingOptionResult.new(code: 'CP_PRIORITY_COURIER_PKT', name: 'canada_post_priority_next_am'), # CP Priority Package (jiffy) through express air
        ShippingOptionResult.new(code: 'CP_PRIORITY_COURIER_PKT_SIG', name: 'canada_post_priority_next_am', signature: true), # CP Priority Package (jiffy) through express air + Signature
        ShippingOptionResult.new(code: 'CP_XPRESSPOST_CANADA_PKT', name: 'canada_post_xpresspost'), # CP Xpresspost Package (jiffy) through air
        ShippingOptionResult.new(code: 'CP_XPRESSPOST_CANADA_PKT_SIG', name: 'canada_post_xpresspost', signature: true), # CP Xpresspost Package (jiffy) through air + Signature
    ]
  else
    # Otherwise, use USA defaults
    @shipping_map = [

        # These are Amazon Vendor Central DF US Ship Method Codes:

        ShippingOptionResult.new(code: 'UPS_GR_RES', name: 'ground'), # UPS Ground
        ShippingOptionResult.new(code: 'UPS_GR_RES_SIG', name: 'ground', signature: true), # UPS Ground + Signature Required
        ShippingOptionResult.new(code: 'UPS_GR_COM', name: 'ground'), # UPS Ground
        ShippingOptionResult.new(code: 'UPS_GR_COM_SIG', name: 'ground', signature: true), # UPS Ground + Signature Required
        ShippingOptionResult.new(code: 'UPS_DOM_3DAY_RES', name: 'threedayselect'), # UPS 3 Day Select
        ShippingOptionResult.new(code: 'UPS_DOM_3DAY_RES_SIG', name: 'threedayselect', signature: true), # UPS 3 Day Select + Signature Required
        ShippingOptionResult.new(code: 'UPS_DOM_3DAY_COM', name: 'threedayselect'), # UPS 3 Day Select
        ShippingOptionResult.new(code: 'UPS_DOM_3DAY_COM_SIG', name: 'threedayselect', signature: true), # UPS 3 Day Select + Signature Required
        ShippingOptionResult.new(code: 'UPS_2ND', name: 'seconddayair'), # UPS 2nd Day Air
        ShippingOptionResult.new(code: 'UPS_2ND_SIG', name: 'seconddayair', signature: true), # UPS 2nd Day Air + Signature Required
        ShippingOptionResult.new(code: 'UPS_2ND_COM', name: 'seconddayair'), # UPS 2nd Day Air
        ShippingOptionResult.new(code: 'UPS_2ND_COM_SIG', name: 'seconddayair', signature: true), # UPS 2nd Day Air + Signature Required
        ShippingOptionResult.new(code: 'UPS_NEXT', name: 'nextdayair'), # UPS Next Day Air
        ShippingOptionResult.new(code: 'UPS_NEXT_SIG', name: 'nextdayair', signature: true), # UPS Next Day Air + Signature Required
        ShippingOptionResult.new(code: 'UPS_NEXT_COM', name: 'nextdayair'), # UPS Next Day Air
        ShippingOptionResult.new(code: 'UPS_NEXT_COM_SIG', name: 'nextdayair', signature: true), # UPS Next Day Air + Signature Required
        ShippingOptionResult.new(code: 'UPS_NEXT_SAVER', name: 'nextdayairsaver'), # UPS Next Day Air Saver
        ShippingOptionResult.new(code: 'UPS_NXT_SVR_SIG', name: 'nextdayairsaver', signature: true), # UPS Next Day Air Saver + Signature Required
        ShippingOptionResult.new(code: 'UPS_NEXT_SAVER_COM', name: 'nextdayairsaver'), # UPS Next Day Air Saver
        ShippingOptionResult.new(code: 'UPS_NEXT_SAVER_COM_SIG', name: 'nextdayairsaver', signature: true), # UPS Next Day Air Saver + Signature Required
        ShippingOptionResult.new(code: 'USPS_DS_EXT', name: 'usps_priority_mail'), # Priority Mail
        ShippingOptionResult.new(code: 'USPS_UPS_GR_BPM', name: 'usps_media_mail'), # UPS SurePost Bound Printed Matter
        ShippingOptionResult.new(code: 'USPS_UPS_GR_PARCEL', name: 'usps_parcel_select'), # UPS SurePost Greater than 1 lb.
        ShippingOptionResult.new(code: 'USPS_UPS_GR_STD', name: 'usps_parcel_select'), # UPS SurePost Less than 1 lb.
        ShippingOptionResult.new(code: 'FEDEX_NEXT_PRI', name: 'fedex_priority_overnight'), # FedEx Priority Overnight
        ShippingOptionResult.new(code: 'FEDEX_NEXT_STD', name: 'fedex_standard_overnight'), # FedEx Standard Overnight
        ShippingOptionResult.new(code: 'FEDEX_SECOND', name: 'fedex_twoday'), # FedEx 2 Day
        ShippingOptionResult.new(code: 'FEDEX_3DAY', name: 'fedex_twoday'), # FedEx 3 Day # TBD implement FedEx Express Saver shipping option in Heatwave!!!!
        ShippingOptionResult.new(code: 'EAGLE', name: 'EAGLE'), # Eagle Standard Ground
        ShippingOptionResult.new(code: 'ABF', name: 'ABF'), # ABF Standard Ground
        ShippingOptionResult.new(code: 'CEVA_WG', name: 'CEVA_WG'), # CEVA Enhanced Delivery
        ShippingOptionResult.new(code: 'CEVA_TH', name: 'CEVA_TH'), # CEVA Standard Delivery
        ShippingOptionResult.new(code: 'XPO_WG', name: 'XPO_WG'), # XPO Enhanced Delivery
        ShippingOptionResult.new(code: 'XPO_TH', name: 'XPO_TH'), # XPO Standard Delivery
        ShippingOptionResult.new(code: 'NSD_ESTES', name: 'NSD_ESTES'), # ESTES Standard
        ShippingOptionResult.new(code: 'FIDELITONE_WATKINS', name: 'FIDELITONE_WATKINS'), # Watkins & Shepard Freight
        ShippingOptionResult.new(code: 'ZENITH_WATKINS', name: 'ZENITH_WATKINS'), # Watkins & Shepard Freight
        ShippingOptionResult.new(code: 'XPO_WATKINS', name: 'XPO_WATKINS'), # Watkins & Shepard Freight
        ShippingOptionResult.new(code: 'NSD_WATKINS', name: 'NSD_WATKINS'), # Watkins & Shepard Freight
        ShippingOptionResult.new(code: 'ZENITH_GROUND', name: 'ZENITH_GROUND'), # Zenith Freight
        ShippingOptionResult.new(code: 'FIDELITONE_ZENITH', name: 'FIDELITONE_ZENITH'), # Zenith Freight
        ShippingOptionResult.new(code: 'XPO_ZENITH', name: 'XPO_ZENITH'), # Zenith Freight
        ShippingOptionResult.new(code: 'NSD_ZENITH', name: 'NSD_ZENITH'), # Zenith Freight
    ]
  end
end

Instance Attribute Details

#orchestratorObject (readonly)

Returns the value of attribute orchestrator.



9
10
11
# File 'app/services/edi/amazon_vc/ship_code_mapper.rb', line 9

def orchestrator
  @orchestrator
end

#shipping_mapObject (readonly)

Returns the value of attribute shipping_map.



9
10
11
# File 'app/services/edi/amazon_vc/ship_code_mapper.rb', line 9

def shipping_map
  @shipping_map
end

Instance Method Details

#az_to_hw(shipping_code) ⇒ Object

Pass an Amazon VC shipping code, e.g UPS_GR_COM, and potentially a carrier code, and retrieves a shipping option result object describing the service requested



107
108
109
110
111
# File 'app/services/edi/amazon_vc/ship_code_mapper.rb', line 107

def az_to_hw(shipping_code)
  match = shipping_map.detect { |sor| sor.code == shipping_code }
  raise "Unmatched shipping code #{shipping_code}" unless match
  match
end

#hw_to_az(shipping_method_name, signature = false) ⇒ Object

Translates a heatwave shipping option parameters into an amazon vc shipping code



114
115
116
117
118
# File 'app/services/edi/amazon_vc/ship_code_mapper.rb', line 114

def hw_to_az(shipping_method_name, signature=false)
  match = shipping_map.detect { |sor| sor.name == shipping_method_name && sor.signature == signature.to_b }&.code
  raise "Unmatched shipping code #{shipping_method_name}" unless match
  match
end