valken-shipping 1.1.9 → 2.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/helpers/workarea/addresses_helper.rb +61 -0
- data/app/models/workarea/checkout/shipping_options.decorator +2 -183
- data/app/models/workarea/shipping.decorator +241 -5
- data/app/models/workarea/shipping_option.decorator +1 -1
- data/config/initializers/shipping_configuration.rb +12 -0
- data/config/initializers/workarea.rb +6 -2
- data/lib/valken/shipping/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43d1c8ec3f7d6af25efe3e0a3acf25e439987772d8118e6775c0ee4f147a4bcf
|
4
|
+
data.tar.gz: 156232c1e92cadbe56479771259ae8d1614f7cfbe1c0eb652824730af7841456
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f83375a1ff6d916416599be7c2c4770b7abaaa9ee3f431e3e736ff69ec0bf3acd7b0c2551f91347769db7957235a138d4246fc56e30059a68f1291a877101313
|
7
|
+
data.tar.gz: 1f4da466456726729188c7c802e9b295adc91196862172c33edf2e35634cfccd743b4032f7d2dc2ffa41911bed8b2999180faa71647b94ff4dff3b2653c64757
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Workarea
|
2
|
+
module AddressesHelper
|
3
|
+
def country_options
|
4
|
+
Workarea.config.countries.map do |country|
|
5
|
+
[country.name, country.alpha2]
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def region_options
|
10
|
+
@region_options ||= Workarea.config.countries.reduce([]) do |memo, country|
|
11
|
+
regions = country.subdivisions
|
12
|
+
.map { |id, region| [region.translations[I18n.locale.to_s] || region.name, id] }
|
13
|
+
.sort_by { |name, id| name || id }
|
14
|
+
|
15
|
+
memo << [country.name, regions]
|
16
|
+
memo
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def is_usa_only?
|
21
|
+
|
22
|
+
orders = current_order rescue nil
|
23
|
+
return false if orders.blank? || orders.items.blank?
|
24
|
+
|
25
|
+
usa_only_attribute = Workarea.config.shipping_attributes[:usa_only]
|
26
|
+
return product_details(orders).map{ |item| item[:en][usa_only_attribute] }.flatten.include?("true")
|
27
|
+
end
|
28
|
+
|
29
|
+
def product_details(orders)
|
30
|
+
@product_details ||= Catalog::Product.in(id: orders.items.to_a.map(&:product_id)).pluck(:details)
|
31
|
+
end
|
32
|
+
|
33
|
+
def formatted_address(address)
|
34
|
+
pieces = {
|
35
|
+
recipient: "#{address.first_name} #{address.last_name}\n#{address.company}".strip,
|
36
|
+
street: "#{address.street} #{address.street_2}".strip,
|
37
|
+
city: address.city,
|
38
|
+
region: address.region_name,
|
39
|
+
region_short: address.region,
|
40
|
+
postalcode: address.postal_code,
|
41
|
+
country: address.country.alpha2
|
42
|
+
}
|
43
|
+
|
44
|
+
address_format = address.country.address_format || Country['US'].address_format
|
45
|
+
result = pieces.reduce(address_format) do |memo, (name, value)|
|
46
|
+
memo.gsub(/{{#{name}}}/, html_escape(value.to_s))
|
47
|
+
end
|
48
|
+
|
49
|
+
if address.phone_number.present?
|
50
|
+
formatted_phone = number_to_phone(
|
51
|
+
address.phone_number,
|
52
|
+
extension: address.phone_extension
|
53
|
+
)
|
54
|
+
|
55
|
+
result << "\n#{formatted_phone}"
|
56
|
+
end
|
57
|
+
|
58
|
+
result.gsub(/\n/, tag(:br)).html_safe
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -1,197 +1,16 @@
|
|
1
1
|
module Workarea
|
2
2
|
decorate Checkout::ShippingOptions, with: :valken do
|
3
3
|
decorated do
|
4
|
+
class NoAvailableShippingOption < RuntimeError; end
|
4
5
|
end
|
5
6
|
|
6
7
|
def all_options
|
7
8
|
@all_options ||=
|
8
9
|
begin
|
9
10
|
packaging = Packaging.new(order, shipping)
|
10
|
-
|
11
|
+
shipping.find_method_options(order, shipping)
|
11
12
|
end
|
12
13
|
end
|
13
14
|
|
14
|
-
def shipping_option
|
15
|
-
carrier_data = []
|
16
|
-
if Workarea.config.gateways.ups_carrier.class != ActiveShipping::Workarea
|
17
|
-
carrier_data.push(get_free_shipping) if Workarea.config.show_free_shipping
|
18
|
-
carrier_data.push(get_ltl_shipping)
|
19
|
-
end
|
20
|
-
carrier_data.push(collect_carrier_data(selected_carrier))
|
21
|
-
carrier_data.flatten
|
22
|
-
end
|
23
|
-
|
24
|
-
# Selecting the shipping carrier based on order items
|
25
|
-
#
|
26
|
-
# If the product is type hazmat then it returns ups...or if product is type gun then it returns fedex
|
27
|
-
# else if product is not both type then it returns none
|
28
|
-
def selected_carrier
|
29
|
-
product_ids = order.items.to_a.map(&:product_id)
|
30
|
-
product_details = Catalog::Product.in(id: product_ids).pluck(:details)
|
31
|
-
is_ups = product_details.any? {|item| item["en"]["Type"] && item["en"]["Type"].first == "UPS"}
|
32
|
-
is_fedex = product_details.any? {|item| item["en"]["Type"] && item["en"]["Type"].first == "FEDEX"}
|
33
|
-
return "UPS" if is_ups
|
34
|
-
return "FedEx" if is_fedex
|
35
|
-
return "none" unless is_ups && is_fedex
|
36
|
-
end
|
37
|
-
|
38
|
-
# If the carrier is ups then it will print ups data...or if carrier is fedex then prinnt fedex data...
|
39
|
-
# else if it is not both then choose cheapest price.
|
40
|
-
def collect_carrier_data(carrier)
|
41
|
-
return get_ups_data if carrier == "UPS"
|
42
|
-
return get_fedex_data if carrier == "FedEx"
|
43
|
-
return get_none_data if carrier == "none"
|
44
|
-
end
|
45
|
-
|
46
|
-
# UPS data.
|
47
|
-
def get_ups_data
|
48
|
-
@ups_options ||= get_options(Workarea.config.gateways.ups_carrier, Workarea.config.shipping_rates)
|
49
|
-
end
|
50
|
-
|
51
|
-
# FedEx data.
|
52
|
-
def get_fedex_data
|
53
|
-
@fedex_response ||= get_options(Workarea.config.gateways.fedex_carrier, Workarea.config.shipping_rates)
|
54
|
-
end
|
55
|
-
|
56
|
-
# If the product is not ups or fedex then it will choose the cheapest price among ups and fedex annd print the value.
|
57
|
-
def get_none_data
|
58
|
-
ups = get_ups_data.sort_by(&:price).first
|
59
|
-
fedex = get_fedex_data.sort_by(&:price).first
|
60
|
-
|
61
|
-
if ups.present? && fedex.present?
|
62
|
-
if ups.price > fedex.price
|
63
|
-
return get_fedex_data
|
64
|
-
elsif ups.price < fedex.price
|
65
|
-
return get_ups_data
|
66
|
-
else
|
67
|
-
return get_ups_data
|
68
|
-
end
|
69
|
-
elsif ups.blank?
|
70
|
-
return get_fedex_data
|
71
|
-
elsif fedex.blank?
|
72
|
-
return get_ups_data
|
73
|
-
else
|
74
|
-
return []
|
75
|
-
end
|
76
|
-
|
77
|
-
end
|
78
|
-
|
79
|
-
# Free shipping option.
|
80
|
-
def get_free_shipping
|
81
|
-
ShippingOption.new(
|
82
|
-
carrier: "Free Shipping",
|
83
|
-
name: "Valken Economy",
|
84
|
-
sub_name: "5 - 9 Business Days",
|
85
|
-
service_code: "Free",
|
86
|
-
price: Money.new(0.0, "USD"),
|
87
|
-
tax_code: "TAX01"
|
88
|
-
)
|
89
|
-
end
|
90
|
-
|
91
|
-
# Calculating the ltl shipping rates based on the conditions.
|
92
|
-
def get_ltl_shipping
|
93
|
-
weight_price = 0
|
94
|
-
case weight_convertion
|
95
|
-
when 0..2
|
96
|
-
weight_price = 5
|
97
|
-
when 2..15
|
98
|
-
weight_price = 15
|
99
|
-
when 15..200
|
100
|
-
weight_price = (1 * weight_convertion)
|
101
|
-
when 200..2500
|
102
|
-
weight_price = 200
|
103
|
-
else
|
104
|
-
weight_price = ((weight_convertion / 2500).ceil()) * 200
|
105
|
-
end
|
106
|
-
|
107
|
-
ShippingOption.new(
|
108
|
-
carrier: "LTL Shipping",
|
109
|
-
name: "Valken Standard",
|
110
|
-
sub_name: "3 - 5 Business Days",
|
111
|
-
service_code: "LTL01",
|
112
|
-
price: Money.new(weight_price * 100, "USD"),
|
113
|
-
tax_code: "TAX01"
|
114
|
-
)
|
115
|
-
end
|
116
|
-
|
117
|
-
# Returns the total weight.
|
118
|
-
def weight_convertion
|
119
|
-
packaging = Packaging.new(order, shipping)
|
120
|
-
return 0 if packaging.packages.blank?
|
121
|
-
full_weight = 0
|
122
|
-
packaging.packages.each do |item_package|
|
123
|
-
new_weight = item_package.weight.convert_to(:lb)
|
124
|
-
full_weight += new_weight.value
|
125
|
-
end
|
126
|
-
full_weight
|
127
|
-
end
|
128
|
-
|
129
|
-
# 1. Sending a call to carrier and get shipping rates
|
130
|
-
# 2. Based on service codes in config, filter the shipping rates
|
131
|
-
# 3. If error, return empty array
|
132
|
-
def get_options(carrier, service_code)
|
133
|
-
packaging = Packaging.new(order, shipping)
|
134
|
-
return [] if shipping.address.blank? || packaging.packages.blank?
|
135
|
-
shipping_option = carrier || Workarea.config.gateways.shipping
|
136
|
-
|
137
|
-
origin = ActiveShipping::Location.new(Workarea.config.shipping_origin)
|
138
|
-
begin
|
139
|
-
response = shipping_option.find_rates(
|
140
|
-
origin,
|
141
|
-
shipping.address.to_active_shipping,
|
142
|
-
packaging.packages
|
143
|
-
)
|
144
|
-
if carrier.class == ActiveShipping::Workarea
|
145
|
-
response.rates.sort_by(&:price).map do |rate|
|
146
|
-
ShippingOption.from_rate_estimate(rate)
|
147
|
-
end
|
148
|
-
else
|
149
|
-
filter_shipping_rates(response.rates, service_code)
|
150
|
-
end
|
151
|
-
rescue ActiveShipping::ResponseError => e
|
152
|
-
return []
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
# Sort rates by delevry date and pick 1st three rates
|
157
|
-
# Find cheapest rate for those three rates
|
158
|
-
# Push all the cheap option for 1, 2, & 3 days into an array and return
|
159
|
-
def filter_shipping_rates(rates, service_code)
|
160
|
-
filtered_rates = []
|
161
|
-
|
162
|
-
# find and sort all delivery dates and pick 1st three
|
163
|
-
all_delivery_dates = rates.map { |rate| rate.delivery_date }
|
164
|
-
# sorting the uniq delivery dates and reversing those delivery dates.
|
165
|
-
uniq_delivery_dates = all_delivery_dates.compact.sort.uniq[0..2].reverse
|
166
|
-
|
167
|
-
# removing overnight. Assuming the 3rd option is always overnight
|
168
|
-
uniq_delivery_dates.pop if uniq_delivery_dates.length == 3
|
169
|
-
|
170
|
-
# For each delivery dates, find cheapest rates and create shipping option and push
|
171
|
-
uniq_delivery_dates.each_with_index do |date, index|
|
172
|
-
selected_rates = rates.select {|rate| rate.delivery_date.present? && rate.delivery_date == date}
|
173
|
-
cheap_rate = selected_rates.sort_by(&:price).first
|
174
|
-
description = "#{cheap_rate.delivery_date.strftime('%A, %B %d, %Y')}"
|
175
|
-
shipping_option = create_shipping_options(cheap_rate, service_code[index], description, Workarea.config.shipping_rates[index])
|
176
|
-
filtered_rates.push(shipping_option)
|
177
|
-
end
|
178
|
-
filtered_rates
|
179
|
-
end
|
180
|
-
|
181
|
-
# creating a ShippingOption
|
182
|
-
def create_shipping_options(rate, rate_label = nil, description = nil, sub_name)
|
183
|
-
ShippingOption.new(
|
184
|
-
carrier: rate.carrier,
|
185
|
-
name: rate_label.keys.join || rate.service_name,
|
186
|
-
sub_name: sub_name.values.join,
|
187
|
-
service_code: rate.service_code,
|
188
|
-
description: description,
|
189
|
-
price: Money.new(rate.price, rate.currency),
|
190
|
-
tax_code: Shipping::Service.find_tax_code(
|
191
|
-
rate.carrier,
|
192
|
-
rate.service_name
|
193
|
-
)
|
194
|
-
)
|
195
|
-
end
|
196
15
|
end
|
197
16
|
end
|
@@ -1,26 +1,262 @@
|
|
1
1
|
module Workarea
|
2
2
|
decorate Shipping, with: :valken do
|
3
|
-
decorated do
|
3
|
+
decorated do
|
4
|
+
field :tracking_number, type: String
|
4
5
|
end
|
5
6
|
|
6
7
|
class_methods do
|
7
8
|
end
|
8
9
|
|
9
|
-
def
|
10
|
+
def order
|
11
|
+
@order
|
12
|
+
end
|
13
|
+
|
14
|
+
def shipping
|
15
|
+
@shipping
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
def default_options(packages)
|
10
20
|
return [] if address.blank? || packages.blank?
|
11
|
-
shipping_option =
|
12
|
-
|
21
|
+
shipping_option = Workarea.config.gateways.shipping
|
22
|
+
|
13
23
|
origin = ActiveShipping::Location.new(Workarea.config.shipping_origin)
|
14
24
|
response = shipping_option.find_rates(
|
15
25
|
origin,
|
16
26
|
address.to_active_shipping,
|
17
27
|
packages
|
18
28
|
)
|
19
|
-
|
20
29
|
response.rates.sort_by(&:price).map do |rate|
|
21
30
|
ShippingOption.from_rate_estimate(rate)
|
22
31
|
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def find_method_options(order, shipping)
|
35
|
+
@order ||= order
|
36
|
+
@shipping ||= shipping
|
37
|
+
carrier_data = []
|
38
|
+
|
39
|
+
packaging = Packaging.new(order, shipping)
|
40
|
+
return [] if packaging.packages.blank?
|
41
|
+
|
42
|
+
return default_options(packaging.packages) if Workarea.config.gateways.ups_carrier.class == ActiveShipping::Workarea
|
43
|
+
|
44
|
+
shipping_options_api = get_final_shipping_options(collect_carrier_data)
|
45
|
+
return [] if @error.present?
|
46
|
+
|
47
|
+
carrier_data.push(shipping_options_api) if shipping_options_api.present? && shipping_options_api.any?
|
48
|
+
|
49
|
+
if Workarea.config.gateways.ups_carrier.class != ActiveShipping::Workarea
|
50
|
+
carrier_data.push(get_ltl_shipping)
|
51
|
+
carrier_data.push(get_free_shipping) if Workarea.config.show_free_shipping
|
52
|
+
else
|
53
|
+
return []
|
54
|
+
end
|
55
|
+
|
56
|
+
carrier_data.flatten.reverse
|
57
|
+
end
|
58
|
+
|
59
|
+
def get_final_shipping_options(rates)
|
60
|
+
options = []
|
61
|
+
|
62
|
+
if is_ground
|
63
|
+
ground_rate = rates.detect{|rate| rate.service_code == "GROUND_HOME_DELIVERY" || rate.service_code == "03" }
|
64
|
+
return [] if ground_rate.blank?
|
65
|
+
|
66
|
+
description = "#{ground_rate.delivery_date.strftime('%A, %B %d, %Y')}"
|
67
|
+
days_to_deliver = (ground_rate.delivery_date - Date.today).to_i
|
68
|
+
|
69
|
+
label = Workarea.config.shipping_rates[(days_to_deliver - 1)]
|
70
|
+
return options.push(create_shipping_options(ground_rate, label, description))
|
71
|
+
end
|
72
|
+
|
73
|
+
rates.each_with_index do |rate, index|
|
74
|
+
description = "#{rate.delivery_date.strftime('%A, %B %d, %Y')}"
|
75
|
+
label = Workarea.config.shipping_rates[index]
|
76
|
+
options.push(create_shipping_options(rate, label, description))
|
77
|
+
end
|
78
|
+
options
|
79
|
+
end
|
80
|
+
|
81
|
+
# If the carrier is ups then it will print ups data...or if carrier is fedex then prinnt fedex data...
|
82
|
+
# else if it is not both then choose cheapest price.
|
83
|
+
def collect_carrier_data
|
84
|
+
return get_ups_data if is_ups
|
85
|
+
return get_fedex_data if is_fedex
|
86
|
+
return get_none_data unless is_ups && is_fedex
|
87
|
+
end
|
88
|
+
|
89
|
+
# UPS data.
|
90
|
+
def get_ups_data
|
91
|
+
@ups_options ||= get_options(Workarea.config.gateways.ups_carrier, Workarea.config.shipping_rates)
|
92
|
+
end
|
93
|
+
|
94
|
+
# FedEx data.
|
95
|
+
def get_fedex_data
|
96
|
+
@fedex_response ||= get_options(Workarea.config.gateways.fedex_carrier, Workarea.config.shipping_rates)
|
97
|
+
end
|
98
|
+
|
99
|
+
# If the product is not ups or fedex then it will choose the cheapest price among ups and fedex annd print the value.
|
100
|
+
def get_none_data
|
101
|
+
return [] if get_ups_data.blank? || get_fedex_data.blank?
|
102
|
+
final_options = []
|
103
|
+
temp_options = get_fedex_data + get_ups_data
|
104
|
+
return [] unless temp_options.any?
|
105
|
+
|
106
|
+
delivery_dates = temp_options.map(&:delivery_date).uniq.sort
|
107
|
+
delivery_dates.each_with_index do |date, index|
|
108
|
+
selected_rates = temp_options.select {|rate| rate.delivery_date == date}
|
109
|
+
final_options.push(selected_rates.sort_by(&:price).first)
|
110
|
+
end
|
111
|
+
return final_options
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
# Free shipping option.
|
116
|
+
def get_free_shipping
|
117
|
+
ShippingOption.new(
|
118
|
+
carrier: "Free Shipping",
|
119
|
+
name: "Valken Economy",
|
120
|
+
sub_name: "5 - 9 Business Days",
|
121
|
+
service_code: "Free",
|
122
|
+
price: Money.new(0.0, "USD"),
|
123
|
+
tax_code: "TAX01"
|
124
|
+
)
|
125
|
+
end
|
126
|
+
|
127
|
+
# Calculating the ltl shipping rates based on the conditions.
|
128
|
+
def get_ltl_shipping
|
129
|
+
weight_price = 0
|
130
|
+
case weight_convertion
|
131
|
+
when 0..2
|
132
|
+
weight_price = 5
|
133
|
+
when 2..15
|
134
|
+
weight_price = 15
|
135
|
+
when 15..200
|
136
|
+
weight_price = (1 * weight_convertion)
|
137
|
+
when 200..2500
|
138
|
+
weight_price = 200
|
139
|
+
else
|
140
|
+
weight_price = ((weight_convertion / 2500).ceil()) * 200
|
141
|
+
end
|
142
|
+
|
143
|
+
ShippingOption.new(
|
144
|
+
carrier: "LTL Shipping",
|
145
|
+
name: "Valken Standard",
|
146
|
+
sub_name: "3 - 5 Business Days",
|
147
|
+
service_code: "LTL01",
|
148
|
+
price: Money.new(weight_price * 100, "USD"),
|
149
|
+
tax_code: "TAX01"
|
150
|
+
)
|
151
|
+
end
|
152
|
+
|
153
|
+
# Returns the total weight.
|
154
|
+
def weight_convertion
|
155
|
+
packaging = Packaging.new(order, shipping)
|
156
|
+
return 0 if packaging.packages.blank?
|
157
|
+
full_weight = 0
|
158
|
+
packaging.packages.each do |item_package|
|
159
|
+
new_weight = item_package.weight.convert_to(:lb)
|
160
|
+
full_weight += new_weight.value
|
161
|
+
end
|
162
|
+
full_weight
|
163
|
+
end
|
164
|
+
|
165
|
+
# 1. Sending a call to carrier and get shipping rates
|
166
|
+
# 2. Based on service codes in config, filter the shipping rates
|
167
|
+
# 3. If error, return empty array
|
168
|
+
def get_options(carrier, service_code)
|
169
|
+
packaging = Packaging.new(order, shipping)
|
170
|
+
return [] if @shipping.address.blank? || packaging.packages.blank?
|
171
|
+
shipping_option = carrier || Workarea.config.gateways.shipping
|
172
|
+
|
173
|
+
origin = ActiveShipping::Location.new(Workarea.config.shipping_origin)
|
174
|
+
begin
|
175
|
+
response = shipping_option.find_rates(
|
176
|
+
origin,
|
177
|
+
@shipping.address.to_active_shipping,
|
178
|
+
packaging.packages
|
179
|
+
)
|
180
|
+
if carrier.class == ActiveShipping::Workarea
|
181
|
+
response.rates.sort_by(&:price).map do |rate|
|
182
|
+
ShippingOption.from_rate_estimate(rate)
|
183
|
+
end
|
184
|
+
else
|
185
|
+
filter_shipping_rates(response.rates, service_code)
|
186
|
+
end
|
187
|
+
rescue ActiveShipping::ResponseError => e
|
188
|
+
@error = e
|
189
|
+
return []
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
# Sort rates by delevry date and pick 1st three rates
|
194
|
+
# Find cheapest rate for those three rates
|
195
|
+
# Push all the cheap option for 1, 2, & 3 days into an array and return
|
196
|
+
def filter_shipping_rates(rates, service_code)
|
197
|
+
filtered_rates = []
|
198
|
+
# find and sort all delivery dates and pick 1st three
|
199
|
+
all_delivery_dates = rates.map { |rate| rate.delivery_date }
|
200
|
+
# sorting the uniq delivery dates and reversing those delivery dates.
|
201
|
+
uniq_delivery_dates = all_delivery_dates.compact.sort.uniq[0..2]
|
202
|
+
|
203
|
+
# removing overnight. Assuming the 3rd option is always overnight
|
204
|
+
uniq_delivery_dates.pop if uniq_delivery_dates.length == 3
|
205
|
+
|
206
|
+
# For each delivery dates, find cheapest rates and create shipping option and push
|
207
|
+
uniq_delivery_dates.each_with_index do |date, index|
|
208
|
+
selected_rates = rates.select {|rate| rate.delivery_date.present? && rate.delivery_date == date}
|
209
|
+
cheap_rate = selected_rates.sort_by(&:price).first
|
210
|
+
description = "#{cheap_rate.delivery_date.strftime('%A, %B %d, %Y')}"
|
211
|
+
|
212
|
+
filtered_rates.push(cheap_rate)
|
213
|
+
end
|
214
|
+
filtered_rates
|
215
|
+
end
|
216
|
+
|
217
|
+
# creating a ShippingOption
|
218
|
+
def create_shipping_options(rate, rate_label = nil, description = nil)
|
219
|
+
ShippingOption.new(
|
220
|
+
carrier: rate.carrier,
|
221
|
+
name: rate_label.keys.join || rate.service_name,
|
222
|
+
sub_name: rate_label.values.join,
|
223
|
+
service_code: rate.service_code,
|
224
|
+
description: description,
|
225
|
+
delivery_date: rate.delivery_date,
|
226
|
+
price: Money.new(rate.price, rate.currency),
|
227
|
+
tax_code: Shipping::Service.find_tax_code(
|
228
|
+
rate.carrier,
|
229
|
+
rate.service_name
|
230
|
+
)
|
231
|
+
)
|
232
|
+
end
|
233
|
+
|
234
|
+
# Selecting the shipping carrier based on order items
|
235
|
+
#
|
236
|
+
# If the product is type hazmat then it returns ups...or if product is type gun then it returns fedex
|
237
|
+
# else if product is not both type then it returns none
|
238
|
+
def is_fedex
|
239
|
+
carrier_type_attribute = Workarea.config.shipping_attributes[:carrier_type]
|
240
|
+
product_carrier_type = product_details.map{ |item| item[:en][carrier_type_attribute] }.flatten
|
241
|
+
product_carrier_type.include?("FEDEX")
|
242
|
+
end
|
243
|
+
|
244
|
+
def is_ups
|
245
|
+
carrier_type_attribute = Workarea.config.shipping_attributes[:carrier_type]
|
246
|
+
product_carrier_type = product_details.map{ |item| item[:en][carrier_type_attribute] }.flatten
|
247
|
+
product_carrier_type.include?("UPS")
|
248
|
+
end
|
249
|
+
|
250
|
+
def is_ground
|
251
|
+
ground_ship_attribute = Workarea.config.shipping_attributes[:ground_shipping_only]
|
252
|
+
product_carrier_type = product_details.map{ |item| item[:en][ground_ship_attribute] }.flatten
|
253
|
+
product_carrier_type.include?("true")
|
254
|
+
end
|
255
|
+
|
256
|
+
def product_details
|
257
|
+
# product_attributes = @order.items.map(&:product_attributes)
|
23
258
|
|
259
|
+
@product_details ||= Catalog::Product.in(id: @order.items.to_a.map(&:product_id)).pluck(:details)
|
24
260
|
end
|
25
261
|
end
|
26
262
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
Workarea::Configuration.define_fields do
|
2
|
+
fieldset 'Shipping', namespaced: false do
|
3
|
+
field 'Shipping Attributes',
|
4
|
+
type: :hash,
|
5
|
+
default: {
|
6
|
+
'usa_only' => 'usa only',
|
7
|
+
'carrier_type' => 'Type',
|
8
|
+
'ground_shipping_only' => 'ground shipping only'
|
9
|
+
},
|
10
|
+
description: 'Mapping of product details keys with shipping logic. Note: This maps only the keys not the values.'
|
11
|
+
end
|
12
|
+
end
|
@@ -1,11 +1,15 @@
|
|
1
1
|
Workarea.configure do |config|
|
2
|
+
|
3
|
+
config.countries = [Country['US']]
|
4
|
+
|
2
5
|
ActiveShipping::Carriers.register :UPS, 'active_shipping/carriers/ups'
|
3
6
|
|
4
7
|
config.weight_table = {"2": 5, "15": 15, "200": 1, "2500": 200}
|
5
8
|
|
6
9
|
config.shipping_rates = [
|
7
|
-
{"Valken
|
8
|
-
{"Valken Express 2-Day" => "2 Business Days"}
|
10
|
+
{"Valken Overnight" => "Overnight"},
|
11
|
+
{"Valken Express 2-Day" => "2 Business Days"},
|
12
|
+
{"Valken Express 3-Day" => "3 Business Days"}
|
9
13
|
]
|
10
14
|
config.ups_options = {"12"=> "Valken Express 3-Day", "01"=> "Valken Overnight", "02"=> "Valken Express 2-Day"}
|
11
15
|
config.fedex_options = {"STANDARD_OVERNIGHT"=> "Valken Overnight", "FEDEX_2_DAY"=> "Valken Express 2-Day", "GROUND_HOME_DELIVERY"=> "Valken Express 3-Day"}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: valken-shipping
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sushmitha02
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-09-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -41,10 +41,12 @@ files:
|
|
41
41
|
- README.md
|
42
42
|
- Rakefile
|
43
43
|
- app/assets/config/valken_shipping_manifest.js
|
44
|
+
- app/helpers/workarea/addresses_helper.rb
|
44
45
|
- app/models/workarea/checkout/shipping_options.decorator
|
45
46
|
- app/models/workarea/shipping.decorator
|
46
47
|
- app/models/workarea/shipping_option.decorator
|
47
48
|
- app/services/workarea/packaging.decorator
|
49
|
+
- config/initializers/shipping_configuration.rb
|
48
50
|
- config/initializers/workarea.rb
|
49
51
|
- config/routes.rb
|
50
52
|
- lib/tasks/valken/shipping_tasks.rake
|