valken-shipping 1.1.2 → 1.1.3

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: 836864919e7e6f3dcb1762f14ea620afd0c56429040ad133fa7b01bf032cc6a3
4
+ data.tar.gz: 1f0addf9f86025e5f59232cbce1cdefd9dd7b56709969823264c3e50578251b8
5
5
  SHA512:
6
- metadata.gz: f53ed14462bf4cddf96725b82b902171d1ef96aa23bfe51dba53d2ae14a9adfb05e5c537b658075d6933923998fb240dde077b78fbdb82c2e9e5a62f5346edf1
7
- data.tar.gz: bfcfad206f8656f9cf38ba0c581b0e74968d669ff0f7d7fd21aad7a169f006fb886c8ad24278213a59645dbc08e0c03b4690520cb85e6d462067e95d87d8b149
6
+ metadata.gz: 465f4ab7305bc7c8efa1e8de744ff6a058f05f0afe389d91e8a0f79a126d12c9a2ba5109869fc39bdda63a4027c78742f6711c37a8e7aa57b2c283735ce4b9c6
7
+ data.tar.gz: ba70cb673db53d2c44ec47ffec89785538e9fbe1e78acca8599bcecf7d0233ca1849f979c811b17348631918a953e6f6f3ab34595eb35cda55aa43506c479c37
@@ -150,36 +150,34 @@ module Workarea
150
150
  end
151
151
  end
152
152
 
153
- # 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
154
155
  # Push all the cheap option for 1, 2, & 3 days into an array and return
155
156
  def filter_shipping_rates(rates, service_code)
156
157
  filtered_rates = []
157
158
 
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
-
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
166
171
  filtered_rates
167
172
  end
168
173
 
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
174
  # creating a ShippingOption
178
- def create_shipping_options(rate, rate_label = nil)
175
+ def create_shipping_options(rate, rate_label = nil, description = nil)
179
176
  ShippingOption.new(
180
177
  carrier: rate.carrier,
181
178
  name: rate_label || rate.service_name,
182
179
  service_code: rate.service_code,
180
+ description: description,
183
181
  price: Money.new(rate.price, rate.currency),
184
182
  tax_code: Shipping::Service.find_tax_code(
185
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.1.2'
3
+ VERSION = '1.1.3'
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.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-07-31 00:00:00.000000000 Z
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