valken-shipping 1.1.2 → 1.1.7

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: 14b667ecf912e540effbb2b13c41a18d32022d9468f06645ea7ef521c03d7188
4
- data.tar.gz: 9b97b46ad99cc5abf8c8eb6f7037f6fe9313e5a12039dc8485beeb4ee20290ce
3
+ metadata.gz: 21a15ea0992134b70026f5e873cce4752bb2d208b45c33f89f6fd105bfb09a01
4
+ data.tar.gz: a975398b63c62662d7dc1d5de4238298e12377b9d10867dd56cadc0e5fc7149f
5
5
  SHA512:
6
- metadata.gz: f53ed14462bf4cddf96725b82b902171d1ef96aa23bfe51dba53d2ae14a9adfb05e5c537b658075d6933923998fb240dde077b78fbdb82c2e9e5a62f5346edf1
7
- data.tar.gz: bfcfad206f8656f9cf38ba0c581b0e74968d669ff0f7d7fd21aad7a169f006fb886c8ad24278213a59645dbc08e0c03b4690520cb85e6d462067e95d87d8b149
6
+ metadata.gz: 600c74fd671573e899bd8a8a527a04ba19057fd0f9049828336ca9261898501a1d876ff87257ea4b54cdfde99e949524f4a8e21fdbc17047e1457b5a896df84c
7
+ data.tar.gz: 875c6a24365e57ebd4374ac33cf4ce9f6af884414afd083bed38c9a737adc0a83989cd96a658ca828df0dab6a0b70417e795b4829bf5e631bc5a178fee7222b8
@@ -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...
@@ -79,7 +79,8 @@ module Workarea
79
79
  def get_free_shipping
80
80
  ShippingOption.new(
81
81
  carrier: "Free Shipping",
82
- name: "5 to 9 Day",
82
+ name: "Valken Economy",
83
+ sub_name: "5 - 9 Business Days",
83
84
  service_code: "Free",
84
85
  price: Money.new(0.0, "USD"),
85
86
  tax_code: "TAX01"
@@ -104,7 +105,8 @@ module Workarea
104
105
 
105
106
  ShippingOption.new(
106
107
  carrier: "LTL Shipping",
107
- name: "3 to 5 Day",
108
+ name: "Valken Standard",
109
+ sub_name: "3 - 5 Business Days",
108
110
  service_code: "LTL01",
109
111
  price: Money.new(weight_price * 100, "USD"),
110
112
  tax_code: "TAX01"
@@ -150,36 +152,35 @@ module Workarea
150
152
  end
151
153
  end
152
154
 
153
- # 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
154
157
  # Push all the cheap option for 1, 2, & 3 days into an array and return
155
158
  def filter_shipping_rates(rates, service_code)
156
159
  filtered_rates = []
157
160
 
158
- overnight_option = get_cheapest_option(rates, (Date.today() + 1), service_code[:overnight])
159
- two_day_option = get_cheapest_option(rates, (Date.today() + 2), service_code[:two_day])
160
- three_day_option = get_cheapest_option(rates, (Date.today() + 3), service_code[:three_day])
161
-
162
- filtered_rates.push(overnight_option) if overnight_option.present?
163
- filtered_rates.push(two_day_option) if two_day_option.present?
164
- filtered_rates.push(three_day_option) if three_day_option.present?
165
-
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
166
173
  filtered_rates
167
174
  end
168
175
 
169
- # Select all rates based on deliver date and given date
170
- # Find cheapest rate from selected rates
171
- # Create shipping option for cheatest rate
172
- def get_cheapest_option(rates, date, label)
173
- selected_rates = rates.select { |item| item.delivery_date == date }
174
- cheap_option = create_shipping_options(selected_rates.sort_by(&:price).first, label) if selected_rates.length > 0
175
- end
176
-
177
176
  # creating a ShippingOption
178
- def create_shipping_options(rate, rate_label = nil)
177
+ def create_shipping_options(rate, rate_label = nil, description = nil, sub_name)
179
178
  ShippingOption.new(
180
179
  carrier: rate.carrier,
181
- name: rate_label || rate.service_name,
180
+ name: rate_label.keys.join || rate.service_name,
181
+ sub_name: sub_name.values.join,
182
182
  service_code: rate.service_code,
183
+ description: description,
183
184
  price: Money.new(rate.price, rate.currency),
184
185
  tax_code: Shipping::Service.find_tax_code(
185
186
  rate.carrier,
@@ -187,7 +188,5 @@ module Workarea
187
188
  )
188
189
  )
189
190
  end
190
-
191
-
192
191
  end
193
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.2'
3
+ VERSION = '1.1.7'
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.2
4
+ version: 1.1.7
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