valken-shipping 1.1.0 → 1.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dee0afe2ade7c20a2c998b526101d102663d7bedce33a88917e651848f3295e3
4
- data.tar.gz: 2b278db87909a3626b6bd4fe73bdd0ac3e20e13c49d85a0503ad05250f45fdd9
3
+ metadata.gz: 7608c70f08d733b5da90794c417ad5bc0b70a85ec6250fe8803f97359e5d6f6a
4
+ data.tar.gz: d3ff069bfa00e8bba8e8ff3c5a286bd52d837062d8abaa08c0230c497346c439
5
5
  SHA512:
6
- metadata.gz: d336d5a379d8db24fa4bee2837e2f08fe0e7b18b6283d411370098cf2ae6bb07cc05a518e1b305bfac82d5e5f24071b2ba0154791b8dac41b5c642015d0675e6
7
- data.tar.gz: 37b92d0ef1657ceb71af9e014151fc23d5ee4daf0677536206a7371ab3d25ad58499a940728db711ab0cc7229b9d2b325ddc3d5f9b63bd9a34e1eceafba285e2
6
+ metadata.gz: 140ef76ea1c80c5ecc8acc17e8553d725a648d005fd460e3b866224ac934c328637da2597c98f6bae5982a9bb0fcb6778fe78f6a646adfe485fa9659edb4f647
7
+ data.tar.gz: 601497d3f3e14b71ddd8efeadae6f9830d51d0ecb318e9a4d9b7b5329bc1f0f1be288aeefc9723a38252a0f1c0f8f877f2369d3d3b8fe6e8f18d7ba990f3b7cb
@@ -15,7 +15,7 @@ module Workarea
15
15
  carrier_data = collect_carrier_data(selected_carrier)
16
16
  if Workarea.config.gateways.ups_carrier.class != ActiveShipping::Workarea
17
17
  carrier_data.push(get_ltl_shipping)
18
- carrier_data.push(get_free_shipping)
18
+ carrier_data.push(get_free_shipping) if Workarea.config.show_free_shipping
19
19
  end
20
20
  carrier_data
21
21
  end
@@ -27,11 +27,11 @@ module Workarea
27
27
  def selected_carrier
28
28
  product_ids = order.items.to_a.map(&:product_id)
29
29
  product_details = Catalog::Product.in(id: product_ids).pluck(:details)
30
- is_hazmat = product_details.any? {|item| item["en"]["Type"] && item["en"]["Type"].first == "Hazmat"}
31
- is_gun = product_details.any? {|item| item["en"]["Type"] && item["en"]["Type"].first == "Gun"}
32
- return "UPS" if is_hazmat
33
- return "FedEx" if is_gun
34
- return "none" unless is_hazmat && is_gun
30
+ is_ups = product_details.any? {|item| item["en"]["Type"] && item["en"]["Type"].first == "UPS"}
31
+ is_fedex = product_details.any? {|item| item["en"]["Type"] && item["en"]["Type"].first == "FEDEX"}
32
+ return "UPS" if is_ups
33
+ return "FedEx" if is_fedex
34
+ return "none" unless is_ups && is_fedex
35
35
  end
36
36
 
37
37
  # If the carrier is ups then it will print ups data...or if carrier is fedex then prinnt fedex data...
@@ -57,11 +57,17 @@ module Workarea
57
57
  ups = get_ups_data.sort_by(&:price).first
58
58
  fedex = get_fedex_data.sort_by(&:price).first
59
59
 
60
- if ups.blank? || ups.price > fedex.price
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?
61
69
  return get_fedex_data
62
- elsif fedex.blank? || ups.price < fedex.price
63
- return get_ups_data
64
- elsif ups.price == fedex.price
70
+ elsif fedex.blank?
65
71
  return get_ups_data
66
72
  else
67
73
  return []
@@ -73,7 +79,8 @@ module Workarea
73
79
  def get_free_shipping
74
80
  ShippingOption.new(
75
81
  carrier: "Free Shipping",
76
- name: "5 to 9 Day",
82
+ name: "Valken Economy",
83
+ sub_name: "5 - 9 Business Days",
77
84
  service_code: "Free",
78
85
  price: Money.new(0.0, "USD"),
79
86
  tax_code: "TAX01"
@@ -98,7 +105,8 @@ module Workarea
98
105
 
99
106
  ShippingOption.new(
100
107
  carrier: "LTL Shipping",
101
- name: "3 to 5 Day",
108
+ name: "Valken Standard",
109
+ sub_name: "3 - 5 Business Days",
102
110
  service_code: "LTL01",
103
111
  price: Money.new(weight_price * 100, "USD"),
104
112
  tax_code: "TAX01"
@@ -124,7 +132,7 @@ module Workarea
124
132
  packaging = Packaging.new(order, shipping)
125
133
  return [] if shipping.address.blank? || packaging.packages.blank?
126
134
  shipping_option = carrier || Workarea.config.gateways.shipping
127
-
135
+
128
136
  origin = ActiveShipping::Location.new(Workarea.config.shipping_origin)
129
137
  begin
130
138
  response = shipping_option.find_rates(
@@ -144,36 +152,35 @@ module Workarea
144
152
  end
145
153
  end
146
154
 
147
- # Get cheapest option from overnight, 2 day & 3 days shipping rates
155
+ # Sort rates by delevry date and pick 1st three rates
156
+ # Find cheapest rate for those three rates
148
157
  # Push all the cheap option for 1, 2, & 3 days into an array and return
149
158
  def filter_shipping_rates(rates, service_code)
150
159
  filtered_rates = []
151
160
 
152
- overnight_option = get_cheapest_option(rates, (Date.today() + 1), service_code[:overnight])
153
- two_day_option = get_cheapest_option(rates, (Date.today() + 2), service_code[:two_day])
154
- three_day_option = get_cheapest_option(rates, (Date.today() + 3), service_code[:three_day])
155
-
156
- filtered_rates.push(overnight_option) if overnight_option.present?
157
- filtered_rates.push(two_day_option) if two_day_option.present?
158
- filtered_rates.push(three_day_option) if three_day_option.present?
159
-
161
+ # find and sort all delivery dates and pick 1st three
162
+ all_delivery_dates = rates.map { |rate| rate.delivery_date }
163
+ uniq_delivery_dates = all_delivery_dates.compact.sort.uniq[0..2]
164
+
165
+ # For each delivery dates, find cheapest rates and create shipping option and push
166
+ uniq_delivery_dates.each_with_index do |date, index|
167
+ selected_rates = rates.select {|rate| rate.delivery_date.present? && rate.delivery_date == date}
168
+ cheap_rate = selected_rates.sort_by(&:price).first
169
+ description = "#{cheap_rate.delivery_date.strftime('%A, %B %d, %Y')}"
170
+ shipping_option = create_shipping_options(cheap_rate, service_code[index], description)
171
+ filtered_rates.push(shipping_option)
172
+ end
160
173
  filtered_rates
161
174
  end
162
175
 
163
- # Select all rates based on deliver date and given date
164
- # Find cheapest rate from selected rates
165
- # Create shipping option for cheatest rate
166
- def get_cheapest_option(rates, date, label)
167
- selected_rates = rates.select { |item| item.delivery_date == date }
168
- cheap_option = create_shipping_options(selected_rates.sort_by(&:price).first, label) if selected_rates.length > 0
169
- end
170
-
171
176
  # creating a ShippingOption
172
- def create_shipping_options(rate, rate_label = nil)
177
+ def create_shipping_options(rate, rate_label = nil, description = nil)
173
178
  ShippingOption.new(
174
179
  carrier: rate.carrier,
175
- name: rate_label || rate.service_name,
180
+ name: Workarea.config.shipping_rates[0].keys[0],
181
+ sub_name: Workarea.config.shipping_rates[0].values[0],
176
182
  service_code: rate.service_code,
183
+ description: description,
177
184
  price: Money.new(rate.price, rate.currency),
178
185
  tax_code: Shipping::Service.find_tax_code(
179
186
  rate.carrier,
@@ -181,7 +188,5 @@ module Workarea
181
188
  )
182
189
  )
183
190
  end
184
-
185
-
186
191
  end
187
192
  end
@@ -0,0 +1,10 @@
1
+ module Workarea
2
+ decorate ShippingOption, with: :valken do
3
+ decorated do
4
+ attr_reader :description, :sub_name
5
+ end
6
+
7
+ class_methods do
8
+ end
9
+ end
10
+ end
@@ -3,12 +3,12 @@ Workarea.configure do |config|
3
3
 
4
4
  config.weight_table = {"2": 5, "15": 15, "200": 1, "2500": 200}
5
5
 
6
- config.shipping_rates = {
7
- :overnight => "Overnight",
8
- :two_day => "2 Day",
9
- :three_day => "3 Day"
10
- }
11
- config.ups_options = {"12"=> "3 Day", "01"=> "Overnight", "02"=> "2 Day"}
12
- config.fedex_options = {"STANDARD_OVERNIGHT"=> "Overnight", "FEDEX_2_DAY"=> "2 Day", "GROUND_HOME_DELIVERY"=> "3 Day"}
6
+ config.shipping_rates = [
7
+ {"Valken Overnight" => "Overnight"},
8
+ {"Valken Express 2-Day" => "2 Business Days"},
9
+ {"Valken Express 3-Day" => "3 Business Days"}
10
+ ]
11
+ config.ups_options = {"12"=> "Valken Express 3-Day", "01"=> "Valken Overnight", "02"=> "Valken Express 2-Day"}
12
+ config.fedex_options = {"STANDARD_OVERNIGHT"=> "Valken Overnight", "FEDEX_2_DAY"=> "Valken Express 2-Day", "GROUND_HOME_DELIVERY"=> "Valken Express 3-Day"}
13
13
  end
14
14
  Valken::Shipping.auto_initialize_gateway
@@ -1,5 +1,5 @@
1
1
  module Valken
2
2
  module Shipping
3
- VERSION = '1.1.0'
3
+ VERSION = '1.1.5'
4
4
  end
5
5
  end
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: 1.1.0
4
+ version: 1.1.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-07-29 00:00:00.000000000 Z
11
+ date: 2020-08-11 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