valken-shipping 1.1.1 → 1.1.6

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: 57a7395b28d67876810628798a91b4749cbabb1f6d441dcfd0dac802c3ceebbb
4
- data.tar.gz: 5fd87c3d631dc6775d19b8264cf7011d4b72ae8c6faef59886fcb4bd9b06cb2f
3
+ metadata.gz: f7da22f8d6fc40becb3da5d39d703d7ad4f3c459b26c15f0332fdd6b6b2ad423
4
+ data.tar.gz: 6d06c92a47f4f45f6e14afd763e05db9086fb09ce464d5aea14a7fd3bc7c165c
5
5
  SHA512:
6
- metadata.gz: 9e6b0c57e20a5f1ba8a654c31e7ef25415410e0fb5ece1f5270b74fdccfda2ad83cd4a90df9d3f804c68c2a70edfbbb032ac57499530623232e814a9980602e9
7
- data.tar.gz: f7c17c654347b8283517945e19a7ccc9e4eac3bac25679ef594d2e3f7a754bb673ea2dcd6d1e74a6da952de0b2ba73fe21d618cf969b8bfec722f08aff43cfb9
6
+ metadata.gz: 3917e7fcd9e3e4c88ea4ca1a293dde0d980a6192ff815c33647cae783425596ddac4b6bd817e858d8ca3c501dfd7d6a6fec928598fd48c2ca0f37be9c9e88991
7
+ data.tar.gz: da3fd915a5cd8a84d25d8b8a6b6a5c861c3642e4cfca688da40cf71f649bd09c87a6a7d65f88ba892b2ea30e5f29ee7c86aa92942bf11da50e6bcb176abaf9c4
@@ -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,12 +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
- return [] if ups.blank? && fedex.blank?
61
- 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?
62
69
  return get_fedex_data
63
- elsif fedex.blank? || ups.price < fedex.price
64
- return get_ups_data
65
- elsif ups.price == fedex.price
70
+ elsif fedex.blank?
66
71
  return get_ups_data
67
72
  else
68
73
  return []
@@ -74,7 +79,8 @@ module Workarea
74
79
  def get_free_shipping
75
80
  ShippingOption.new(
76
81
  carrier: "Free Shipping",
77
- name: "5 to 9 Day",
82
+ name: "Valken Economy",
83
+ sub_name: "5 - 9 Business Days",
78
84
  service_code: "Free",
79
85
  price: Money.new(0.0, "USD"),
80
86
  tax_code: "TAX01"
@@ -99,7 +105,8 @@ module Workarea
99
105
 
100
106
  ShippingOption.new(
101
107
  carrier: "LTL Shipping",
102
- name: "3 to 5 Day",
108
+ name: "Valken Standard",
109
+ sub_name: "3 - 5 Business Days",
103
110
  service_code: "LTL01",
104
111
  price: Money.new(weight_price * 100, "USD"),
105
112
  tax_code: "TAX01"
@@ -145,36 +152,36 @@ module Workarea
145
152
  end
146
153
  end
147
154
 
148
- # 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
149
157
  # Push all the cheap option for 1, 2, & 3 days into an array and return
150
158
  def filter_shipping_rates(rates, service_code)
151
159
  filtered_rates = []
152
160
 
153
- overnight_option = get_cheapest_option(rates, (Date.today() + 1), service_code[:overnight])
154
- two_day_option = get_cheapest_option(rates, (Date.today() + 2), service_code[:two_day])
155
- three_day_option = get_cheapest_option(rates, (Date.today() + 3), service_code[:three_day])
156
-
157
- filtered_rates.push(overnight_option) if overnight_option.present?
158
- filtered_rates.push(two_day_option) if two_day_option.present?
159
- filtered_rates.push(three_day_option) if three_day_option.present?
160
-
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, Workarea.config.shipping_rates[index])
171
+ filtered_rates.push(shipping_option)
172
+ end
161
173
  filtered_rates
162
174
  end
163
175
 
164
- # Select all rates based on deliver date and given date
165
- # Find cheapest rate from selected rates
166
- # Create shipping option for cheatest rate
167
- def get_cheapest_option(rates, date, label)
168
- selected_rates = rates.select { |item| item.delivery_date == date }
169
- cheap_option = create_shipping_options(selected_rates.sort_by(&:price).first, label) if selected_rates.length > 0
170
- end
171
-
172
176
  # creating a ShippingOption
173
- def create_shipping_options(rate, rate_label = nil)
177
+ def create_shipping_options(rate, rate_label = nil, description = nil, sub_name)
178
+ byebug
174
179
  ShippingOption.new(
175
180
  carrier: rate.carrier,
176
- name: rate_label || rate.service_name,
181
+ name: rate_label.keys.join || rate.service_name,
182
+ sub_name: sub_name.values.join,
177
183
  service_code: rate.service_code,
184
+ description: description,
178
185
  price: Money.new(rate.price, rate.currency),
179
186
  tax_code: Shipping::Service.find_tax_code(
180
187
  rate.carrier,
@@ -182,7 +189,5 @@ module Workarea
182
189
  )
183
190
  )
184
191
  end
185
-
186
-
187
192
  end
188
193
  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.1'
3
+ VERSION = '1.1.6'
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.1
4
+ version: 1.1.6
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-31 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