valken-shipping 0.2.0 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/workarea/checkout/shipping_options.decorator +82 -34
- data/app/models/workarea/shipping_option.decorator +10 -0
- data/app/services/workarea/packaging.decorator +8 -11
- data/config/initializers/workarea.rb +7 -1
- data/lib/valken/shipping/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 836864919e7e6f3dcb1762f14ea620afd0c56429040ad133fa7b01bf032cc6a3
|
4
|
+
data.tar.gz: 1f0addf9f86025e5f59232cbce1cdefd9dd7b56709969823264c3e50578251b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 465f4ab7305bc7c8efa1e8de744ff6a058f05f0afe389d91e8a0f79a126d12c9a2ba5109869fc39bdda63a4027c78742f6711c37a8e7aa57b2c283735ce4b9c6
|
7
|
+
data.tar.gz: ba70cb673db53d2c44ec47ffec89785538e9fbe1e78acca8599bcecf7d0233ca1849f979c811b17348631918a953e6f6f3ab34595eb35cda55aa43506c479c37
|
@@ -20,6 +20,10 @@ module Workarea
|
|
20
20
|
carrier_data
|
21
21
|
end
|
22
22
|
|
23
|
+
# Selecting the shipping carrier based on order items
|
24
|
+
#
|
25
|
+
# If the product is type hazmat then it returns ups...or if product is type gun then it returns fedex
|
26
|
+
# else if product is not both type then it returns none
|
23
27
|
def selected_carrier
|
24
28
|
product_ids = order.items.to_a.map(&:product_id)
|
25
29
|
product_details = Catalog::Product.in(id: product_ids).pluck(:details)
|
@@ -30,31 +34,48 @@ module Workarea
|
|
30
34
|
return "none" unless is_hazmat && is_gun
|
31
35
|
end
|
32
36
|
|
37
|
+
# If the carrier is ups then it will print ups data...or if carrier is fedex then prinnt fedex data...
|
38
|
+
# else if it is not both then choose cheapest price.
|
33
39
|
def collect_carrier_data(carrier)
|
34
40
|
return get_ups_data if carrier == "UPS"
|
35
41
|
return get_fedex_data if carrier == "FedEx"
|
36
42
|
return get_none_data if carrier == "none"
|
37
43
|
end
|
38
44
|
|
45
|
+
# UPS data.
|
39
46
|
def get_ups_data
|
40
|
-
ups_options
|
47
|
+
@ups_options ||= get_options(Workarea.config.gateways.ups_carrier, Workarea.config.shipping_rates)
|
41
48
|
end
|
42
49
|
|
50
|
+
# FedEx data.
|
43
51
|
def get_fedex_data
|
44
|
-
fedex_response
|
52
|
+
@fedex_response ||= get_options(Workarea.config.gateways.fedex_carrier, Workarea.config.shipping_rates)
|
45
53
|
end
|
46
54
|
|
55
|
+
# If the product is not ups or fedex then it will choose the cheapest price among ups and fedex annd print the value.
|
47
56
|
def get_none_data
|
48
|
-
ups = get_ups_data.first
|
49
|
-
fedex = get_fedex_data.first
|
50
|
-
|
51
|
-
if ups.
|
57
|
+
ups = get_ups_data.sort_by(&:price).first
|
58
|
+
fedex = get_fedex_data.sort_by(&:price).first
|
59
|
+
|
60
|
+
if ups.present? && fedex.present?
|
61
|
+
if ups.price > fedex.price
|
62
|
+
return get_fedex_data
|
63
|
+
elsif ups.price < fedex.price
|
64
|
+
return get_ups_data
|
65
|
+
else
|
66
|
+
return get_ups_data
|
67
|
+
end
|
68
|
+
elsif ups.blank?
|
52
69
|
return get_fedex_data
|
53
|
-
|
70
|
+
elsif fedex.blank?
|
54
71
|
return get_ups_data
|
72
|
+
else
|
73
|
+
return []
|
55
74
|
end
|
75
|
+
|
56
76
|
end
|
57
77
|
|
78
|
+
# Free shipping option.
|
58
79
|
def get_free_shipping
|
59
80
|
ShippingOption.new(
|
60
81
|
carrier: "Free Shipping",
|
@@ -65,19 +86,20 @@ module Workarea
|
|
65
86
|
)
|
66
87
|
end
|
67
88
|
|
89
|
+
# Calculating the ltl shipping rates based on the conditions.
|
68
90
|
def get_ltl_shipping
|
69
91
|
weight_price = 0
|
70
|
-
case
|
92
|
+
case weight_convertion
|
71
93
|
when 0..2
|
72
94
|
weight_price = 5
|
73
95
|
when 2..15
|
74
96
|
weight_price = 15
|
75
97
|
when 15..200
|
76
|
-
weight_price = (1 *
|
98
|
+
weight_price = (1 * weight_convertion)
|
77
99
|
when 200..2500
|
78
100
|
weight_price = 200
|
79
101
|
else
|
80
|
-
weight_price = ((
|
102
|
+
weight_price = ((weight_convertion / 2500).ceil()) * 200
|
81
103
|
end
|
82
104
|
|
83
105
|
ShippingOption.new(
|
@@ -89,49 +111,73 @@ module Workarea
|
|
89
111
|
)
|
90
112
|
end
|
91
113
|
|
92
|
-
|
114
|
+
# Returns the total weight.
|
115
|
+
def weight_convertion
|
93
116
|
packaging = Packaging.new(order, shipping)
|
94
117
|
return 0 if packaging.packages.blank?
|
95
|
-
|
118
|
+
full_weight = 0
|
96
119
|
packaging.packages.each do |item_package|
|
97
|
-
|
120
|
+
new_weight = item_package.weight.convert_to(:lb)
|
121
|
+
full_weight += new_weight.value
|
98
122
|
end
|
99
|
-
|
100
|
-
total_weight
|
123
|
+
full_weight
|
101
124
|
end
|
102
125
|
|
126
|
+
# 1. Sending a call to carrier and get shipping rates
|
127
|
+
# 2. Based on service codes in config, filter the shipping rates
|
128
|
+
# 3. If error, return empty array
|
103
129
|
def get_options(carrier, service_code)
|
104
130
|
packaging = Packaging.new(order, shipping)
|
105
131
|
return [] if shipping.address.blank? || packaging.packages.blank?
|
106
132
|
shipping_option = carrier || Workarea.config.gateways.shipping
|
107
|
-
|
108
|
-
origin = ActiveShipping::Location.new(Workarea.config.shipping_origin)
|
109
|
-
response = shipping_option.find_rates(
|
110
|
-
origin,
|
111
|
-
shipping.address.to_active_shipping,
|
112
|
-
packaging.packages
|
113
|
-
)
|
114
133
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
134
|
+
origin = ActiveShipping::Location.new(Workarea.config.shipping_origin)
|
135
|
+
begin
|
136
|
+
response = shipping_option.find_rates(
|
137
|
+
origin,
|
138
|
+
shipping.address.to_active_shipping,
|
139
|
+
packaging.packages
|
140
|
+
)
|
141
|
+
if carrier.class == ActiveShipping::Workarea
|
142
|
+
response.rates.sort_by(&:price).map do |rate|
|
143
|
+
ShippingOption.from_rate_estimate(rate)
|
124
144
|
end
|
145
|
+
else
|
146
|
+
filter_shipping_rates(response.rates, service_code)
|
125
147
|
end
|
126
|
-
|
148
|
+
rescue ActiveShipping::ResponseError => e
|
149
|
+
return []
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
# Sort rates by delevry date and pick 1st three rates
|
154
|
+
# Find cheapest rate for those three rates
|
155
|
+
# Push all the cheap option for 1, 2, & 3 days into an array and return
|
156
|
+
def filter_shipping_rates(rates, service_code)
|
157
|
+
filtered_rates = []
|
158
|
+
|
159
|
+
# find and sort all delivery dates and pick 1st three
|
160
|
+
all_delivery_dates = rates.map { |rate| rate.delivery_date }
|
161
|
+
uniq_delivery_dates = all_delivery_dates.compact.sort.uniq[0..2]
|
162
|
+
|
163
|
+
# For each delivery dates, find cheapest rates and create shipping option and push
|
164
|
+
uniq_delivery_dates.each_with_index do |date, index|
|
165
|
+
selected_rates = rates.select {|rate| rate.delivery_date.present? && rate.delivery_date == date}
|
166
|
+
cheap_rate = selected_rates.sort_by(&:price).first
|
167
|
+
description = "#{cheap_rate.delivery_date.strftime('%a, %d %b %Y')}"
|
168
|
+
shipping_option = create_shipping_options(cheap_rate, service_code[index], description)
|
169
|
+
filtered_rates.push(shipping_option)
|
127
170
|
end
|
171
|
+
filtered_rates
|
128
172
|
end
|
129
173
|
|
130
|
-
|
174
|
+
# creating a ShippingOption
|
175
|
+
def create_shipping_options(rate, rate_label = nil, description = nil)
|
131
176
|
ShippingOption.new(
|
132
177
|
carrier: rate.carrier,
|
133
|
-
name:
|
178
|
+
name: rate_label || rate.service_name,
|
134
179
|
service_code: rate.service_code,
|
180
|
+
description: description,
|
135
181
|
price: Money.new(rate.price, rate.currency),
|
136
182
|
tax_code: Shipping::Service.find_tax_code(
|
137
183
|
rate.carrier,
|
@@ -139,5 +185,7 @@ module Workarea
|
|
139
185
|
)
|
140
186
|
)
|
141
187
|
end
|
188
|
+
|
189
|
+
|
142
190
|
end
|
143
191
|
end
|
@@ -8,23 +8,20 @@ module Workarea
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def find_sku_weight(sku)
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
else
|
16
|
-
sku.weight || 0
|
17
|
-
end
|
11
|
+
product_by_sku = Catalog::Product.find_by_sku(sku).variants
|
12
|
+
sku_data = product_by_sku.detect {|variant| variant.sku == sku }
|
13
|
+
sku_weight = is_pounds(sku_data) ? convert_to_lb(sku_data.weight || 0) : (sku_data.weight || 0)
|
14
|
+
sku_weight
|
18
15
|
end
|
19
16
|
|
20
17
|
def convert_to_lb(weight)
|
21
18
|
unit = Measured::Weight.new(weight, :lb)
|
22
|
-
unit.convert_to(:oz)
|
23
|
-
|
19
|
+
ounce_unit = unit.convert_to(:oz)
|
20
|
+
ounce_unit.value
|
24
21
|
end
|
25
22
|
|
26
|
-
def is_pounds(
|
27
|
-
|
23
|
+
def is_pounds(sku_data)
|
24
|
+
sku_data.weight_unit == "lb"
|
28
25
|
end
|
29
26
|
end
|
30
27
|
end
|
@@ -3,7 +3,13 @@ Workarea.configure do |config|
|
|
3
3
|
|
4
4
|
config.weight_table = {"2": 5, "15": 15, "200": 1, "2500": 200}
|
5
5
|
|
6
|
-
|
6
|
+
|
7
|
+
config.shipping_rates = [
|
8
|
+
"Overnight",
|
9
|
+
"2 Day",
|
10
|
+
"3 Day"
|
11
|
+
]
|
12
|
+
config.ups_options = {"12"=> "3 Day", "01"=> "Overnight", "02"=> "2 Day"}
|
7
13
|
config.fedex_options = {"STANDARD_OVERNIGHT"=> "Overnight", "FEDEX_2_DAY"=> "2 Day", "GROUND_HOME_DELIVERY"=> "3 Day"}
|
8
14
|
end
|
9
15
|
Valken::Shipping.auto_initialize_gateway
|
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: 1.1.3
|
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-08-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -43,6 +43,7 @@ files:
|
|
43
43
|
- app/assets/config/valken_shipping_manifest.js
|
44
44
|
- app/models/workarea/checkout/shipping_options.decorator
|
45
45
|
- app/models/workarea/shipping.decorator
|
46
|
+
- app/models/workarea/shipping_option.decorator
|
46
47
|
- app/services/workarea/packaging.decorator
|
47
48
|
- config/initializers/workarea.rb
|
48
49
|
- config/routes.rb
|