valken-shipping 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +28 -0
- data/Rakefile +29 -0
- data/app/assets/config/valken_shipping_manifest.js +0 -0
- data/app/models/workarea/checkout/shipping_options.decorator +133 -0
- data/app/models/workarea/shipping.decorator +26 -0
- data/app/services/workarea/packaging.decorator +16 -0
- data/config/initializers/workarea.rb +6 -0
- data/config/routes.rb +2 -0
- data/lib/tasks/valken/shipping_tasks.rake +4 -0
- data/lib/valken/shipping.rb +7 -0
- data/lib/valken/shipping/engine.rb +6 -0
- data/lib/valken/shipping/version.rb +5 -0
- metadata +76 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e84c0d4116d7966aa6f084fdf5fe4b18fe78fa8a7b4ae0e0ccf0da055dba6827
|
4
|
+
data.tar.gz: 0e75818f95bc1434dc81cccd4dc1f6f9d97a80db445d9246ce3ee14f6f4d352a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dd4fb785e8735a2c80b833d8c0cce78dc2e88b235f0256320d1df3574679fda4d382b7a57752e7c8cfdc0f9976c54c8f28a3e5a44134e0406787a46a0a814c38
|
7
|
+
data.tar.gz: 6b977128805bc0b99b50bbb10429eec3fc759d0bdd926808e56bd71b655f0426ab50773af3f31fd2d3f072007a1af06e7d86e93753b6211d152e702b7d4ab09d
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2020 sushmitha02
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Valken::Shipping
|
2
|
+
Short description and motivation.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
How to use my plugin.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'valken-shipping'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
```bash
|
21
|
+
$ gem install valken-shipping
|
22
|
+
```
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
Contribution directions go here.
|
26
|
+
|
27
|
+
## License
|
28
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'Valken::Shipping'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
load 'rails/tasks/statistics.rake'
|
18
|
+
|
19
|
+
require 'bundler/gem_tasks'
|
20
|
+
|
21
|
+
require 'rake/testtask'
|
22
|
+
|
23
|
+
Rake::TestTask.new(:test) do |t|
|
24
|
+
t.libs << 'test'
|
25
|
+
t.pattern = 'test/**/*_test.rb'
|
26
|
+
t.verbose = false
|
27
|
+
end
|
28
|
+
|
29
|
+
task default: :test
|
File without changes
|
@@ -0,0 +1,133 @@
|
|
1
|
+
module Workarea
|
2
|
+
decorate Checkout::ShippingOptions, with: :valken do
|
3
|
+
decorated do
|
4
|
+
end
|
5
|
+
|
6
|
+
def all_options
|
7
|
+
@all_options ||=
|
8
|
+
begin
|
9
|
+
packaging = Packaging.new(order, shipping)
|
10
|
+
shipping_option
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def shipping_option
|
15
|
+
carrier_data = collect_carrier_data(selected_carrier)
|
16
|
+
free = carrier_data.push(get_ltl_shipping)
|
17
|
+
info = free.push(get_free_shipping)
|
18
|
+
end
|
19
|
+
|
20
|
+
def selected_carrier
|
21
|
+
product_ids = order.items.to_a.map(&:product_id)
|
22
|
+
product_details = Catalog::Product.in(id: product_ids).pluck(:details)
|
23
|
+
is_hazmat = product_details.any? {|item| item["en"]["Type"] && item["en"]["Type"].first == "Hazmat"}
|
24
|
+
is_gun = product_details.any? {|item| item["en"]["Type"] && item["en"]["Type"].first == "Gun"}
|
25
|
+
return "UPS" if is_hazmat
|
26
|
+
return "FedEx" if is_gun
|
27
|
+
return "none" unless is_hazmat && is_gun
|
28
|
+
end
|
29
|
+
|
30
|
+
def collect_carrier_data(carrier)
|
31
|
+
return get_ups_data if carrier == "UPS"
|
32
|
+
return get_fedex_data if carrier == "FedEx"
|
33
|
+
return get_none_data if carrier == "none"
|
34
|
+
end
|
35
|
+
|
36
|
+
def get_ups_data
|
37
|
+
ups_options = get_options(ActiveShipping::UPS.new(Rails.application.secrets.ups_carrier), Workarea.config.ups_options)
|
38
|
+
end
|
39
|
+
|
40
|
+
def get_fedex_data
|
41
|
+
fedex_response = get_options(ActiveShipping::FedEx.new(Rails.application.secrets.fedex_carrier), Workarea.config.fedex_options)
|
42
|
+
end
|
43
|
+
|
44
|
+
def get_none_data
|
45
|
+
ups = get_ups_data.first
|
46
|
+
fedex = get_fedex_data.first
|
47
|
+
if ups.price > fedex.price
|
48
|
+
return get_fedex_data
|
49
|
+
else
|
50
|
+
return get_ups_data
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def get_free_shipping
|
55
|
+
ShippingOption.new(
|
56
|
+
carrier: "Free Shipping",
|
57
|
+
name: "5 to 9 Day",
|
58
|
+
service_code: "Free",
|
59
|
+
price: Money.new(0.0, "USD"),
|
60
|
+
tax_code: "TAX01"
|
61
|
+
)
|
62
|
+
end
|
63
|
+
|
64
|
+
def get_ltl_shipping
|
65
|
+
weight_price = 0
|
66
|
+
case total_weight
|
67
|
+
when 0..2
|
68
|
+
weight_price = 5
|
69
|
+
when 2..15
|
70
|
+
weight_price = 15
|
71
|
+
when 15..200
|
72
|
+
weight_price = (1 * total_weight)
|
73
|
+
when 200..2500
|
74
|
+
weight_price = 200
|
75
|
+
else
|
76
|
+
weight_price = ((total_weight / 2500).ceil()) * 200
|
77
|
+
end
|
78
|
+
|
79
|
+
ShippingOption.new(
|
80
|
+
carrier: "LTL Shipping",
|
81
|
+
name: "3 to 5 Day",
|
82
|
+
service_code: "LTL01",
|
83
|
+
price: Money.new(weight_price * 100, "USD"),
|
84
|
+
tax_code: "TAX01"
|
85
|
+
)
|
86
|
+
end
|
87
|
+
|
88
|
+
def total_weight
|
89
|
+
packaging = Packaging.new(order, shipping)
|
90
|
+
return 0 if packaging.packages.blank?
|
91
|
+
total_weight = 0
|
92
|
+
packaging.packages.each do |item_package|
|
93
|
+
total_weight += item_package.weight.value
|
94
|
+
end
|
95
|
+
|
96
|
+
total_weight
|
97
|
+
end
|
98
|
+
|
99
|
+
def get_options(carrier, service_code)
|
100
|
+
packaging = Packaging.new(order, shipping)
|
101
|
+
return [] if shipping.address.blank? || packaging.packages.blank?
|
102
|
+
shipping_option = carrier || Workarea.config.gateways.shipping
|
103
|
+
|
104
|
+
origin = ActiveShipping::Location.new(Workarea.config.shipping_origin)
|
105
|
+
response = shipping_option.find_rates(
|
106
|
+
origin,
|
107
|
+
shipping.address.to_active_shipping,
|
108
|
+
packaging.packages
|
109
|
+
)
|
110
|
+
|
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
|
+
end
|
116
|
+
end
|
117
|
+
filtered_options
|
118
|
+
end
|
119
|
+
|
120
|
+
def create_shipping_options(rate, service_code)
|
121
|
+
ShippingOption.new(
|
122
|
+
carrier: rate.carrier,
|
123
|
+
name: service_code[rate.service_code] || rate.service_name,
|
124
|
+
service_code: rate.service_code,
|
125
|
+
price: Money.new(rate.price, rate.currency),
|
126
|
+
tax_code: Shipping::Service.find_tax_code(
|
127
|
+
rate.carrier,
|
128
|
+
rate.service_name
|
129
|
+
)
|
130
|
+
)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Workarea
|
2
|
+
decorate Shipping, with: :valken do
|
3
|
+
decorated do
|
4
|
+
end
|
5
|
+
|
6
|
+
class_methods do
|
7
|
+
end
|
8
|
+
|
9
|
+
def find_method_options(packages, shipping_option)
|
10
|
+
return [] if address.blank? || packages.blank?
|
11
|
+
shipping_option = shipping_option || Workarea.config.gateways.shipping
|
12
|
+
|
13
|
+
origin = ActiveShipping::Location.new(Workarea.config.shipping_origin)
|
14
|
+
response = shipping_option.find_rates(
|
15
|
+
origin,
|
16
|
+
address.to_active_shipping,
|
17
|
+
packages
|
18
|
+
)
|
19
|
+
|
20
|
+
response.rates.sort_by(&:price).map do |rate|
|
21
|
+
ShippingOption.from_rate_estimate(rate)
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Workarea
|
2
|
+
decorate Packaging, with: :valken do
|
3
|
+
decorated do
|
4
|
+
end
|
5
|
+
|
6
|
+
def find_shipping_sku(sku)
|
7
|
+
shipping_skus.detect { |s| s.id == sku } || Shipping::Sku.new(id: sku, weight: find_sku_weight(sku))
|
8
|
+
end
|
9
|
+
|
10
|
+
def find_sku_weight(sku)
|
11
|
+
sku_data = Catalog::Product.find_by_sku(sku).variants
|
12
|
+
sku = sku_data.detect {|variant| variant.sku == sku }
|
13
|
+
sku.weight || 0
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
Workarea.configure do |config|
|
2
|
+
config.weight_table = {"2": 5, "15": 15, "200": 1, "2500": 200}
|
3
|
+
|
4
|
+
config.ups_options = {"01"=> "3 Day", "03"=> "Overnight", "02"=> "2 Day"}
|
5
|
+
config.fedex_options = {"STANDARD_OVERNIGHT"=> "Overnight", "FEDEX_2_DAY"=> "2 Day", "GROUND_HOME_DELIVERY"=> "3 Day"}
|
6
|
+
end
|
data/config/routes.rb
ADDED
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: valken-shipping
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- sushmitha02
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-06-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 5.2.4
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 5.2.4.2
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 5.2.4
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 5.2.4.2
|
33
|
+
description: Choosing multiple carrier shipping options
|
34
|
+
email:
|
35
|
+
- sushmitha.h@trikatechnologies.com
|
36
|
+
executables: []
|
37
|
+
extensions: []
|
38
|
+
extra_rdoc_files: []
|
39
|
+
files:
|
40
|
+
- MIT-LICENSE
|
41
|
+
- README.md
|
42
|
+
- Rakefile
|
43
|
+
- app/assets/config/valken_shipping_manifest.js
|
44
|
+
- app/models/workarea/checkout/shipping_options.decorator
|
45
|
+
- app/models/workarea/shipping.decorator
|
46
|
+
- app/services/workarea/packaging.decorator
|
47
|
+
- config/initializers/workarea.rb
|
48
|
+
- config/routes.rb
|
49
|
+
- lib/tasks/valken/shipping_tasks.rake
|
50
|
+
- lib/valken/shipping.rb
|
51
|
+
- lib/valken/shipping/engine.rb
|
52
|
+
- lib/valken/shipping/version.rb
|
53
|
+
homepage: https://github.com/sushmitha02
|
54
|
+
licenses:
|
55
|
+
- MIT
|
56
|
+
metadata: {}
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
requirements: []
|
72
|
+
rubygems_version: 3.0.6
|
73
|
+
signing_key:
|
74
|
+
specification_version: 4
|
75
|
+
summary: shipping options
|
76
|
+
test_files: []
|