valken-shipping 1.0.0 → 1.1.4

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: 0b0fc21d3ef74613ab62ca3f5993836bc52c8ad229cf50039216de9b9bd01073
4
- data.tar.gz: 65f121acd97813fa08a0b5d9f405894281cde213e6860c1c7593a8f6e5c10d63
3
+ metadata.gz: fa9324cff477a6c9ab22438c530c614b020f66e209ae5e50ac88f0ced04b7a49
4
+ data.tar.gz: 0dc95eabe9d8fcfe12cd667288f9b0a84548b3e2ecf631d0a0b04189c1b20724
5
5
  SHA512:
6
- metadata.gz: ec65e99367d4da03661b12186d24bd29dfe1c44f2c80c5a7ac19388ee67ab60434ada4ba2c8ba120c1518a1c0bf8f0149d8eefb2eb6569e2312c5269cb157775
7
- data.tar.gz: 7b045821a8865ca84fb2ee297e7717cbbc1309a37ad2fe990a0f6cdcfbca541cd57da8086338ad029937d5c46b35ae0a08af49b9170fea55363c3bba77373436
6
+ metadata.gz: 5e8b065cc02c8af0d8ecee5a34ea80fcb7f6d86fe3e22ed6d2824513c956637404f8bc4973bcbfe3afa5851fa6e58423bf2e8de2227ee26a0c336bbf4078eae0
7
+ data.tar.gz: 34f59bb3e5fdb30bdf227120aca4b1d71016b5af15b79a094d9c5d9c3d8a02f4ac47d5a7ef0e1aa1303c0a4489b40bde4de86a425a75dd40e02fa40dfe37be94
@@ -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,9 +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
70
+ elsif fedex.blank?
63
71
  return get_ups_data
64
72
  else
65
73
  return []
@@ -122,7 +130,7 @@ module Workarea
122
130
  packaging = Packaging.new(order, shipping)
123
131
  return [] if shipping.address.blank? || packaging.packages.blank?
124
132
  shipping_option = carrier || Workarea.config.gateways.shipping
125
-
133
+
126
134
  origin = ActiveShipping::Location.new(Workarea.config.shipping_origin)
127
135
  begin
128
136
  response = shipping_option.find_rates(
@@ -142,36 +150,34 @@ module Workarea
142
150
  end
143
151
  end
144
152
 
145
- # Get cheapest option from overnight, 2 day & 3 days shipping rates
153
+ # Sort rates by delevry date and pick 1st three rates
154
+ # Find cheapest rate for those three rates
146
155
  # Push all the cheap option for 1, 2, & 3 days into an array and return
147
156
  def filter_shipping_rates(rates, service_code)
148
157
  filtered_rates = []
149
158
 
150
- overnight_option = get_cheapest_option(rates, (Date.today() + 1), service_code[:overnight])
151
- two_day_option = get_cheapest_option(rates, (Date.today() + 2), service_code[:two_day])
152
- three_day_option = get_cheapest_option(rates, (Date.today() + 3), service_code[:three_day])
153
-
154
- filtered_rates.push(overnight_option) if overnight_option.present?
155
- filtered_rates.push(two_day_option) if two_day_option.present?
156
- filtered_rates.push(three_day_option) if three_day_option.present?
157
-
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)
170
+ end
158
171
  filtered_rates
159
172
  end
160
173
 
161
- # Select all rates based on deliver date and given date
162
- # Find cheapest rate from selected rates
163
- # Create shipping option for cheatest rate
164
- def get_cheapest_option(rates, date, label)
165
- selected_rates = rates.select { |item| item.delivery_date == date }
166
- cheap_option = create_shipping_options(selected_rates.sort_by(&:price).first, label) if selected_rates.length > 0
167
- end
168
-
169
174
  # creating a ShippingOption
170
- def create_shipping_options(rate, rate_label = nil)
175
+ def create_shipping_options(rate, rate_label = nil, description = nil)
171
176
  ShippingOption.new(
172
177
  carrier: rate.carrier,
173
178
  name: rate_label || rate.service_name,
174
179
  service_code: rate.service_code,
180
+ description: description,
175
181
  price: Money.new(rate.price, rate.currency),
176
182
  tax_code: Shipping::Service.find_tax_code(
177
183
  rate.carrier,
@@ -0,0 +1,10 @@
1
+ module Workarea
2
+ decorate ShippingOption, with: :valken do
3
+ decorated do
4
+ attr_reader :description
5
+ end
6
+
7
+ class_methods do
8
+ end
9
+ end
10
+ end
@@ -3,11 +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
- }
6
+
7
+ config.shipping_rates = [
8
+ "Overnight",
9
+ "2 Day",
10
+ "3 Day"
11
+ ]
11
12
  config.ups_options = {"12"=> "3 Day", "01"=> "Overnight", "02"=> "2 Day"}
12
13
  config.fedex_options = {"STANDARD_OVERNIGHT"=> "Overnight", "FEDEX_2_DAY"=> "2 Day", "GROUND_HOME_DELIVERY"=> "3 Day"}
13
14
  end
@@ -1,5 +1,5 @@
1
1
  module Valken
2
2
  module Shipping
3
- VERSION = '1.0.0'
3
+ VERSION = '1.1.4'
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.0.0
4
+ version: 1.1.4
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-28 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