valken-shipping 0.1.0 → 0.2.0

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: e84c0d4116d7966aa6f084fdf5fe4b18fe78fa8a7b4ae0e0ccf0da055dba6827
4
- data.tar.gz: 0e75818f95bc1434dc81cccd4dc1f6f9d97a80db445d9246ce3ee14f6f4d352a
3
+ metadata.gz: 3a7479a62094f25d2a3bed078783fa64e87d1df2589126a5428139389d16a584
4
+ data.tar.gz: 62dbd43d9ecc4df5474ef1dd9a3e544885c72704f10c5d4611ed526ac1a5ebf7
5
5
  SHA512:
6
- metadata.gz: dd4fb785e8735a2c80b833d8c0cce78dc2e88b235f0256320d1df3574679fda4d382b7a57752e7c8cfdc0f9976c54c8f28a3e5a44134e0406787a46a0a814c38
7
- data.tar.gz: 6b977128805bc0b99b50bbb10429eec3fc759d0bdd926808e56bd71b655f0426ab50773af3f31fd2d3f072007a1af06e7d86e93753b6211d152e702b7d4ab09d
6
+ metadata.gz: 2d6e57218303abfe50301f1c1d4d000f890af7f15293ed93c6ec735e16f57682c2a2b80a4d46eff1218d69f7632bc1782d7d7585faa566da097592be761c411f
7
+ data.tar.gz: bb00c7c168791983e2ab1d557de2d296b37a32bf5edf6ca0cfa5d8ca9ff5b78bbaf80a0fabdb51646af1a6d612d4209c215694863628735408003c689f4153f2
@@ -13,8 +13,11 @@ module Workarea
13
13
 
14
14
  def shipping_option
15
15
  carrier_data = collect_carrier_data(selected_carrier)
16
- free = carrier_data.push(get_ltl_shipping)
17
- info = free.push(get_free_shipping)
16
+ if Workarea.config.gateways.ups_carrier.class != ActiveShipping::Workarea
17
+ carrier_data.push(get_ltl_shipping)
18
+ carrier_data.push(get_free_shipping)
19
+ end
20
+ carrier_data
18
21
  end
19
22
 
20
23
  def selected_carrier
@@ -34,16 +37,17 @@ module Workarea
34
37
  end
35
38
 
36
39
  def get_ups_data
37
- ups_options = get_options(ActiveShipping::UPS.new(Rails.application.secrets.ups_carrier), Workarea.config.ups_options)
40
+ ups_options = get_options(Workarea.config.gateways.ups_carrier, Workarea.config.ups_options)
38
41
  end
39
42
 
40
43
  def get_fedex_data
41
- fedex_response = get_options(ActiveShipping::FedEx.new(Rails.application.secrets.fedex_carrier), Workarea.config.fedex_options)
44
+ fedex_response = get_options(Workarea.config.gateways.fedex_carrier, Workarea.config.fedex_options)
42
45
  end
43
46
 
44
47
  def get_none_data
45
48
  ups = get_ups_data.first
46
49
  fedex = get_fedex_data.first
50
+ return [] unless ups || fedex
47
51
  if ups.price > fedex.price
48
52
  return get_fedex_data
49
53
  else
@@ -108,13 +112,19 @@ module Workarea
108
112
  packaging.packages
109
113
  )
110
114
 
111
- filtered_options = []
112
- response.rates.sort_by(&:price).each do |rate|
113
- if service_code[rate.service_code].present?
114
- filtered_options.push(create_shipping_options(rate, service_code))
115
+ if carrier.class == ActiveShipping::Workarea
116
+ response.rates.sort_by(&:price).map do |rate|
117
+ ShippingOption.from_rate_estimate(rate)
118
+ end
119
+ else
120
+ filtered_options = []
121
+ response.rates.sort_by(&:price).each do |rate|
122
+ if service_code[rate.service_code].present?
123
+ filtered_options.push(create_shipping_options(rate, service_code))
124
+ end
115
125
  end
126
+ filtered_options
116
127
  end
117
- filtered_options
118
128
  end
119
129
 
120
130
  def create_shipping_options(rate, service_code)
@@ -10,7 +10,21 @@ module Workarea
10
10
  def find_sku_weight(sku)
11
11
  sku_data = Catalog::Product.find_by_sku(sku).variants
12
12
  sku = sku_data.detect {|variant| variant.sku == sku }
13
- sku.weight || 0
13
+ if is_pounds(sku)
14
+ convert_to_lb(sku.weight || 0)
15
+ else
16
+ sku.weight || 0
17
+ end
18
+ end
19
+
20
+ def convert_to_lb(weight)
21
+ unit = Measured::Weight.new(weight, :lb)
22
+ unit.convert_to(:oz)
23
+ unit.value
24
+ end
25
+
26
+ def is_pounds(sku)
27
+ sku.weight_unit == "lb"
14
28
  end
15
29
  end
16
30
  end
@@ -1,6 +1,9 @@
1
- Workarea.configure do |config|
1
+ Workarea.configure do |config|
2
+ ActiveShipping::Carriers.register :UPS, 'active_shipping/carriers/ups'
3
+
2
4
  config.weight_table = {"2": 5, "15": 15, "200": 1, "2500": 200}
3
5
 
4
6
  config.ups_options = {"01"=> "3 Day", "03"=> "Overnight", "02"=> "2 Day"}
5
7
  config.fedex_options = {"STANDARD_OVERNIGHT"=> "Overnight", "FEDEX_2_DAY"=> "2 Day", "GROUND_HOME_DELIVERY"=> "3 Day"}
6
8
  end
9
+ Valken::Shipping.auto_initialize_gateway
@@ -1,7 +1,42 @@
1
+ require 'workarea'
2
+ require 'workarea/storefront'
3
+ require 'workarea/admin'
1
4
  require "valken/shipping/engine"
2
5
 
3
6
  module Valken
4
7
  module Shipping
5
- # Your code goes here...
8
+
9
+ def self.ups_credentials
10
+ return {} unless Rails.application.secrets.ups_carrier.present?
11
+ Rails.application.secrets.ups_carrier.symbolize_keys
12
+ end
13
+
14
+ def self.fedex_credentials
15
+ return {} unless Rails.application.secrets.fedex_carrier.present?
16
+ Rails.application.secrets.fedex_carrier.symbolize_keys
17
+ end
18
+
19
+ def self.ups_gateway=(gateway)
20
+ Workarea.config.gateways.ups_carrier = gateway
21
+ end
22
+
23
+ def self.fedex_gateway=(gateway)
24
+ Workarea.config.gateways.fedex_carrier = gateway
25
+ end
26
+
27
+ def self.auto_initialize_gateway
28
+ if ups_credentials.present? && fedex_credentials.present?
29
+ if Rails.env.test?
30
+ self.ups_gateway = ActiveShipping::Workarea.new
31
+ self.fedex_gateway = ActiveShipping::Workarea.new
32
+ else
33
+ self.ups_gateway = ActiveShipping::UPS.new ups_credentials
34
+ self.fedex_gateway = ActiveShipping::FedEx.new fedex_credentials
35
+ end
36
+ else
37
+ self.ups_gateway = ActiveShipping::Workarea.new
38
+ self.fedex_gateway = ActiveShipping::Workarea.new
39
+ end
40
+ end
6
41
  end
7
- end
42
+ end
@@ -1,5 +1,5 @@
1
1
  module Valken
2
2
  module Shipping
3
- VERSION = '0.1.0'
3
+ VERSION = '0.2.0'
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: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - sushmitha02
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-23 00:00:00.000000000 Z
11
+ date: 2020-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails