spree_postal_service 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/.gitignore +14 -0
- data/.rspec +1 -0
- data/.travis.yml +11 -0
- data/CONTRIBUTING.md +30 -0
- data/Gemfile +3 -0
- data/Guardfile +5 -0
- data/LICENSE.md +26 -0
- data/README.md +88 -0
- data/Rakefile +18 -0
- data/config/locales/en.yml +12 -0
- data/config/locales/pt.yml +12 -0
- data/config/locales/sv.yml +12 -0
- data/lib/spree/calculator/postal_service.rb +83 -0
- data/lib/spree_postal_service/engine.rb +13 -0
- data/lib/spree_postal_service/version.rb +16 -0
- data/lib/spree_postal_service.rb +3 -0
- data/script/rails +7 -0
- data/spec/lib/postal_service_spec.rb +124 -0
- data/spec/spec_helper.rb +26 -0
- data/spec/translations/locale_spec.rb +15 -0
- data/spree_postal_service.gemspec +38 -0
- metadata +209 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
---
|
|
2
|
+
!binary "U0hBMQ==":
|
|
3
|
+
metadata.gz: !binary |-
|
|
4
|
+
MjNhNjlkNGY2NGM3N2UxYWRkYWI4YWZmYTA4NjM4MTY0YWE0NzY2ZA==
|
|
5
|
+
data.tar.gz: !binary |-
|
|
6
|
+
NzRlNjlmZWQwZGY2ZWU5ZDQ3NzIxMDM4YTEyMGMzZTExYjk1YWU5Yg==
|
|
7
|
+
SHA512:
|
|
8
|
+
metadata.gz: !binary |-
|
|
9
|
+
NGIwNGZiMjE5MzljZGIwNThkNmJjNDM1YjIwNzQxNjAzMzczMTFkMzAzZThl
|
|
10
|
+
Y2E5OThlZTRiYzE4NGY4MzZlMmY4NTU4YTI3YTFmOTAwYzZkZDhhNGE0YWY3
|
|
11
|
+
MzYyMjY4MDk1YjYwZDRlNDJkYjZmNjM5NTZhMjE5ZmViZDY4YWY=
|
|
12
|
+
data.tar.gz: !binary |-
|
|
13
|
+
ODI0YzVjNDA2MWMzOTIyZTRkMjlmYTQxMjNmMjI5NzYxZDExNTZkNTllYjU5
|
|
14
|
+
NWZiMzc0Njc3ODRjNDAwNDUyYzZiYmIyMzczMzA4YjUwYjJlODcyY2VmMGFl
|
|
15
|
+
Nzk0MWUwMDM5YTQ2YmVjMWQ0N2Q5ZTFjM2I3OTgyYTRlMjhlMzA=
|
data/.gitignore
ADDED
data/.rspec
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
--color
|
data/.travis.yml
ADDED
data/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
In the spirit of [free software][1], **everyone** is encouraged to help improve this project.
|
|
4
|
+
|
|
5
|
+
Here are some ways *you* can contribute:
|
|
6
|
+
|
|
7
|
+
* by using prerelease versions
|
|
8
|
+
* by reporting [bugs][2]
|
|
9
|
+
* by suggesting new features
|
|
10
|
+
* by writing [translations][3]
|
|
11
|
+
* by writing or editing documentation
|
|
12
|
+
* by writing specifications
|
|
13
|
+
* by writing code (*no patch is too small*: fix typos, add comments, clean up inconsistent whitespace)
|
|
14
|
+
* by refactoring code
|
|
15
|
+
* by resolving [issues][2]
|
|
16
|
+
* by reviewing patches
|
|
17
|
+
|
|
18
|
+
Starting point:
|
|
19
|
+
|
|
20
|
+
* Fork the repo
|
|
21
|
+
* Clone your repo
|
|
22
|
+
* Run `bundle install`
|
|
23
|
+
* Run `bundle exec rake test_app` to create the test application in `spec/test_app`
|
|
24
|
+
* Make your changes
|
|
25
|
+
* Ensure specs pass by running `bundle exec rspec spec`
|
|
26
|
+
* Submit your pull request
|
|
27
|
+
|
|
28
|
+
[1]: http://www.fsf.org/licensing/essays/free-sw.html
|
|
29
|
+
[2]: https://github.com/futhr/spree-postal-service/issues
|
|
30
|
+
[3]: http://www.localeapp.com/projects/4917
|
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
Copyright (c) 2011-2014 Torsten Rüger, Tobias Bohwalli and other contributors.
|
|
2
|
+
All rights reserved.
|
|
3
|
+
|
|
4
|
+
Redistribution and use in source and binary forms, with or without modification,
|
|
5
|
+
are permitted provided that the following conditions are met:
|
|
6
|
+
|
|
7
|
+
* Redistributions of source code must retain the above copyright notice,
|
|
8
|
+
this list of conditions and the following disclaimer.
|
|
9
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
|
10
|
+
this list of conditions and the following disclaimer in the documentation
|
|
11
|
+
and/or other materials provided with the distribution.
|
|
12
|
+
* Neither the name Spree nor the names of its contributors may be used to
|
|
13
|
+
endorse or promote products derived from this software without specific
|
|
14
|
+
prior written permission.
|
|
15
|
+
|
|
16
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
17
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
18
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
19
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
|
20
|
+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
21
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
22
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
23
|
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
24
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
25
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
26
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# Spree Postal Service
|
|
2
|
+
|
|
3
|
+
[](https://travis-ci.org/futhr/spree-postal-service)
|
|
4
|
+
[](https://codeclimate.com/github/futhr/spree-postal-service)
|
|
5
|
+
|
|
6
|
+
A postal service is delivers based on weight only(*). Like most post services in europe will.
|
|
7
|
+
|
|
8
|
+
This spree extension adds a spree-calculator to model this.
|
|
9
|
+
|
|
10
|
+
**Other features:**
|
|
11
|
+
|
|
12
|
+
- Size and weight restrictions can be specified
|
|
13
|
+
- You specify a weight/price table
|
|
14
|
+
- Handling fee may be added ( with a maximum when it won't be applied anymore)
|
|
15
|
+
- Multi-parcel shipments are automatically created
|
|
16
|
+
- You can specify a maximum order price, orders over this will not be charged
|
|
17
|
+
|
|
18
|
+
Off course this relies on your weight data to be correct (and if you want the restrictions to work, the size data too).
|
|
19
|
+
Use the same measurements as in the product info page.
|
|
20
|
+
|
|
21
|
+
(*) You may install several ShippingMethods for (usually) different countries.
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
Add to your `Gemfile`:
|
|
26
|
+
```ruby
|
|
27
|
+
gem 'spree_postal_service', github: 'futhr/spree-postal-service', branch: '1-1-stable'
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Go to admin interface
|
|
31
|
+
|
|
32
|
+
`http://localhost:3000/admin/shipping_methods/new`
|
|
33
|
+
|
|
34
|
+
and use _Postal Service_ as calculator.
|
|
35
|
+
|
|
36
|
+
The size/weight _table_ must have the same amount of (space separated) entries.
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## Example
|
|
41
|
+
|
|
42
|
+
With the default settings (measurements in kg and cm):
|
|
43
|
+
|
|
44
|
+
- Max weight of one item: 18
|
|
45
|
+
- Max width of one item: 60
|
|
46
|
+
- Max length of one item: 90
|
|
47
|
+
- Default weight: 1kg (applies when product weight is 0)
|
|
48
|
+
- Handling fee: 10
|
|
49
|
+
- Amount, over which handling fee won't be applied: 50
|
|
50
|
+
- Max total of the order: 120.0
|
|
51
|
+
- Weights (space separated): 1 2 5 10 20
|
|
52
|
+
- Prices (space separated): 6 9 12 15 18
|
|
53
|
+
|
|
54
|
+
## Applies?
|
|
55
|
+
|
|
56
|
+
The Shipping method does not apply to the order if:
|
|
57
|
+
|
|
58
|
+
- Any items weighs more than 18 kg
|
|
59
|
+
- Any item is longer than 90 cm
|
|
60
|
+
- Any items second longest side (width) is over 60 cm. Eg a 70x70x20 item.
|
|
61
|
+
|
|
62
|
+
## Costs
|
|
63
|
+
|
|
64
|
+
- Items weighing 10 kg of worth 100 Euros will cost 15 Euros
|
|
65
|
+
- Items weighing 10 kg of worth 40 Euros will cost 25 Euros (15 + 10 handling)
|
|
66
|
+
- Items weighing less than 1 kg of worth 60 Euros will cost 6 Euros
|
|
67
|
+
- Items weighing less than 1 kg of worth 40 Euros will cost 16 Euros (6 + 10)
|
|
68
|
+
- Items weighing 25 kg of worth 200 Euros will cost 30 Euros (2 packages, 18 + 12 euro)
|
|
69
|
+
- 3 items without weight information of worth 100 euros will cost 12 Euro
|
|
70
|
+
- Any amount of items costing more than the max_price will cost 0 Euro
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## Contributing
|
|
75
|
+
|
|
76
|
+
See corresponding [contributing guidelines][1].
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## License
|
|
81
|
+
|
|
82
|
+
Copyright (c) 2011-2014 [Torsten Rüger][2], [Tobias Bohwalli][3] and other [contributors][4], released under the [New BSD License][5].
|
|
83
|
+
|
|
84
|
+
[1]: https://github.com/futhr/spree-postal-service/blob/master/CONTRIBUTING.md
|
|
85
|
+
[2]: https://github.com/dancinglightning
|
|
86
|
+
[3]: https://github.com/futhr
|
|
87
|
+
[4]: https://github.com/futhr/spree-postal-service/graphs/contributors
|
|
88
|
+
[5]: https://github.com/futhr/spree-postal-service/blob/master/LICENSE.md
|
data/Rakefile
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
require 'bundler'
|
|
3
|
+
Bundler::GemHelper.install_tasks
|
|
4
|
+
Bundler.setup
|
|
5
|
+
|
|
6
|
+
require 'rspec/core/rake_task'
|
|
7
|
+
RSpec::Core::RakeTask.new
|
|
8
|
+
|
|
9
|
+
require 'spree/core/testing_support/common_rake'
|
|
10
|
+
|
|
11
|
+
desc 'Default Task'
|
|
12
|
+
task :default => [:spec]
|
|
13
|
+
|
|
14
|
+
desc 'Generates a dummy app for testing'
|
|
15
|
+
task :test_app do
|
|
16
|
+
ENV['LIB_NAME'] = 'spree_postal_service'
|
|
17
|
+
Rake::Task['common:test_app'].invoke
|
|
18
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
---
|
|
2
|
+
en:
|
|
3
|
+
price_table: Prices (space seperated)
|
|
4
|
+
weight_table: Weights (space seperated)
|
|
5
|
+
postal_service: Postal Service
|
|
6
|
+
max_item_weight: Max weight of one item
|
|
7
|
+
max_item_width: Max width of one item
|
|
8
|
+
max_item_length: Max length of one item
|
|
9
|
+
handling_fee: Handling fee
|
|
10
|
+
handling_max: "Amount, over which handling fee won't be applied"
|
|
11
|
+
min_price: Minimum total of the order
|
|
12
|
+
default_weight: Default weight
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
---
|
|
2
|
+
pt:
|
|
3
|
+
price_table: Preços (separados por espaços)
|
|
4
|
+
weight_table: Pesos (separados por espaços)
|
|
5
|
+
postal_service: Serviço Postal
|
|
6
|
+
max_item_weight: Peso máximo por item
|
|
7
|
+
max_item_width: Peso máxima por item
|
|
8
|
+
max_item_length: Comprimento máximo por item
|
|
9
|
+
handling_fee: Taxa de tratamento
|
|
10
|
+
handling_max: Valor a partir do qual a taxa de tratamento não é aplicada
|
|
11
|
+
min_price: Preço mínimo
|
|
12
|
+
default_weight: Peso por omissão
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
---
|
|
2
|
+
sv:
|
|
3
|
+
price_table: Priser (mellanrums separerade)
|
|
4
|
+
weight_table: Vikter (mellanrums separerade)
|
|
5
|
+
postal_service: Post Service
|
|
6
|
+
max_item_weight: Max vikt på ett objekt
|
|
7
|
+
max_item_width: Max bredd på ett objekt
|
|
8
|
+
max_item_length: Max längd på ett objekt
|
|
9
|
+
handling_fee: Hantering avgift
|
|
10
|
+
handling_max: "Belopp, över vilken expeditionsavgift inte skall tillämpas"
|
|
11
|
+
min_price: Minsta belopp
|
|
12
|
+
default_weight: Förvald vikt
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
class Spree::Calculator::PostalService < Spree::Calculator
|
|
2
|
+
preference :weight_table, :string, :default => '1 2 5 10 20'
|
|
3
|
+
preference :price_table, :string, :default => '6 9 12 15 18'
|
|
4
|
+
preference :max_item_weight, :decimal, :default => 18
|
|
5
|
+
preference :max_item_width, :decimal, :default => 60
|
|
6
|
+
preference :max_item_length, :decimal, :default => 120
|
|
7
|
+
preference :max_price, :decimal, :default => 120
|
|
8
|
+
preference :handling_max, :decimal, :default => 50
|
|
9
|
+
preference :handling_fee, :decimal, :default => 10
|
|
10
|
+
preference :default_weight, :decimal, :default => 1
|
|
11
|
+
|
|
12
|
+
attr_accessible :preferred_weight_table,
|
|
13
|
+
:preferred_price_table,
|
|
14
|
+
:preferred_max_item_weight,
|
|
15
|
+
:preferred_max_item_width,
|
|
16
|
+
:preferred_max_item_length,
|
|
17
|
+
:preferred_max_price,
|
|
18
|
+
:preferred_handling_max,
|
|
19
|
+
:preferred_handling_fee,
|
|
20
|
+
:preferred_default_weight
|
|
21
|
+
|
|
22
|
+
def self.description
|
|
23
|
+
I18n.t(:postal_service)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def self.register
|
|
27
|
+
super
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def item_oversized?(variant)
|
|
31
|
+
sizes = [
|
|
32
|
+
variant.width ? variant.width : 0,
|
|
33
|
+
variant.depth ? variant.depth : 0,
|
|
34
|
+
variant.height ? variant.height : 0
|
|
35
|
+
].sort.reverse
|
|
36
|
+
|
|
37
|
+
return true if sizes[0] > self.preferred_max_item_length # longest side
|
|
38
|
+
return true if sizes[0] > self.preferred_max_item_width # second longest side
|
|
39
|
+
return false
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def available?(shipment)
|
|
43
|
+
variants = shipment.line_items.map(&:variant)
|
|
44
|
+
variants.each do |variant| # determine if weight or size goes over bounds
|
|
45
|
+
return false if variant.weight && variant.weight > self.preferred_max_item_weight # 18
|
|
46
|
+
return false if item_oversized? variant
|
|
47
|
+
end
|
|
48
|
+
return true
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# as order_or_line_items we always get line items, as calculable we have Coupon, ShippingMethod or ShippingRate
|
|
52
|
+
def compute(shipment)
|
|
53
|
+
order = shipment.order
|
|
54
|
+
|
|
55
|
+
total_price, total_weight, shipping = 0, 0, 0
|
|
56
|
+
prices = self.preferred_price_table.split.map { |price| price.to_f }
|
|
57
|
+
|
|
58
|
+
order.line_items.each do |item| # determine total price and weight
|
|
59
|
+
total_weight += item.quantity * (item.variant.weight || self.preferred_default_weight)
|
|
60
|
+
total_price += item.price * item.quantity
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
return 0.0 if total_price > self.preferred_max_price
|
|
64
|
+
|
|
65
|
+
# determine handling fee
|
|
66
|
+
handling_fee = self.preferred_handling_max < total_price ? 0 : self.preferred_handling_fee
|
|
67
|
+
weights = self.preferred_weight_table.split.map { |weight| weight.to_f }
|
|
68
|
+
|
|
69
|
+
while total_weight > weights.last # in several packages if need be
|
|
70
|
+
total_weight -= weights.last
|
|
71
|
+
shipping += prices.last
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
index = weights.length - 2
|
|
75
|
+
while index >= 0
|
|
76
|
+
break if total_weight > weights[index]
|
|
77
|
+
index -= 1
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
shipping += prices[index + 1]
|
|
81
|
+
return shipping + handling_fee
|
|
82
|
+
end
|
|
83
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module SpreePostalService
|
|
2
|
+
class Engine < Rails::Engine
|
|
3
|
+
engine_name 'spree_postal_service'
|
|
4
|
+
|
|
5
|
+
config.autoload_paths += %W(#{config.root}/lib)
|
|
6
|
+
|
|
7
|
+
initializer 'spree.register.calculators' do |app|
|
|
8
|
+
require 'spree/calculator/postal_service'
|
|
9
|
+
|
|
10
|
+
app.config.spree.calculators.shipping_methods << Spree::Calculator::PostalService
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module SpreePostalService
|
|
2
|
+
|
|
3
|
+
# Returns the version of the currently loaded SpreePostalService as a <tt>Gem::Version</tt>
|
|
4
|
+
def self.version
|
|
5
|
+
Gem::Version.new VERSION::STRING
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
module VERSION
|
|
9
|
+
MAJOR = 1
|
|
10
|
+
MINOR = 1
|
|
11
|
+
TINY = 2
|
|
12
|
+
PRE = nil
|
|
13
|
+
|
|
14
|
+
STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
|
|
15
|
+
end
|
|
16
|
+
end
|
data/script/rails
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Spree::Calculator::PostalService do
|
|
4
|
+
|
|
5
|
+
let(:postal_service_calculator) { described_class.new }
|
|
6
|
+
|
|
7
|
+
describe 'return description' do
|
|
8
|
+
context 'in english' do
|
|
9
|
+
before { I18n.locale = :en }
|
|
10
|
+
specify do
|
|
11
|
+
postal_service_calculator.description.should == 'Postal Service'
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
context 'in any language' do
|
|
16
|
+
before { I18n.locale = :pt }
|
|
17
|
+
specify do
|
|
18
|
+
postal_service_calculator.description.should == I18n.t(:postal_service)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
describe ':using the default weight-price table: [1 2 5 10 20] => [6 9 12 15 18]' do
|
|
24
|
+
context '#compute:' do
|
|
25
|
+
it 'gives 15.0 when total price is 100 and weight is 10kg' do
|
|
26
|
+
create_our_package(:weight => 10.0, :price => 100.0, :quantity => 1)
|
|
27
|
+
postal_service_calculator.compute(@shipment).should == 15.0
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it 'gives 25.0 when total price is 40 and weight is 10kg' do
|
|
31
|
+
create_our_package(:weight => 10.0, :price => 40.0, :quantity => 1)
|
|
32
|
+
postal_service_calculator.compute(@shipment).should == 25.0
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it 'gives 6 when total price is 60 and weight is less than 1kg' do
|
|
36
|
+
create_our_package(:weight => 0.5, :price => 60.0, :quantity => 1)
|
|
37
|
+
postal_service_calculator.compute(@shipment).should == 6.0
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it 'gives 16 when total price is 40 and weight is less than 1kg' do
|
|
41
|
+
create_our_package(:weight => 0.5, :price => 40.0, :quantity => 1)
|
|
42
|
+
postal_service_calculator.compute(@shipment).should == 16.0
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it 'gives 30 when total price is 200 and weight is 25kg (split into two)' do
|
|
46
|
+
create_our_package(:weight => 25.0, :price => 200.0, :quantity => 1)
|
|
47
|
+
postal_service_calculator.preferred_max_price = 250
|
|
48
|
+
postal_service_calculator.compute(@shipment).should == 30.0
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it 'gives 12 when total price is 100, there are three items and their weight is unknown' do
|
|
52
|
+
order = create(:order)
|
|
53
|
+
[30.0, 40.0, 30.0].each do |price|
|
|
54
|
+
create(:line_item,
|
|
55
|
+
:price => price,
|
|
56
|
+
:quantity => 1,
|
|
57
|
+
:order => order,
|
|
58
|
+
:variant => create(:variant, :weight => nil))
|
|
59
|
+
end
|
|
60
|
+
order.line_items.reload
|
|
61
|
+
shipment = create(:shipment, :order => order)
|
|
62
|
+
|
|
63
|
+
postal_service_calculator.compute(shipment).should == 12.0
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
it 'gives 0 when total price is more than the MAX, for any number of items' do
|
|
67
|
+
create_our_package(:weight => 25.0, :price => 350.0, :quantity => 1)
|
|
68
|
+
postal_service_calculator.preferred_max_price = 300
|
|
69
|
+
postal_service_calculator.compute(@shipment).should == 0.0
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
describe 'when preferred max weight, length and width are 18 kg, 120 cm and 60 cm' do
|
|
75
|
+
context '#available?' do
|
|
76
|
+
it 'is false when item weighs more than 18kg' do
|
|
77
|
+
create_our_package(:weight => 20, :height => 70, :width => 30, :depth => 30)
|
|
78
|
+
postal_service_calculator.available?(@shipment).should be_false
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
it 'is false when item is longer than 120cm' do
|
|
82
|
+
create_our_package(:weight => 10, :height => 130, :width => 30, :depth => 30)
|
|
83
|
+
postal_service_calculator.available?(@shipment).should be_false
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
it 'is false when item is wider than 60cm' do
|
|
87
|
+
create_our_package(:weight => 10, :height => 80, :width => 70, :depth => 30)
|
|
88
|
+
postal_service_calculator.available?(@shipment).should be_false
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
context '#item_oversized?' do
|
|
93
|
+
it 'is true if the longest side is more than 120cm' do
|
|
94
|
+
create_our_package(:weight => 10, :height => 130, :width => 40, :depth => 30)
|
|
95
|
+
postal_service_calculator.item_oversized?(@variant).should be_true
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
it 'is true if the second longest side is more than 60cm' do
|
|
99
|
+
create_our_package(:weight => 10, :height => 80, :width => 70, :depth => 30)
|
|
100
|
+
postal_service_calculator.item_oversized?(@variant).should be_true
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def create_our_package(args={})
|
|
106
|
+
order = create(:order)
|
|
107
|
+
|
|
108
|
+
params = {}
|
|
109
|
+
params.merge!(:weight => args[:weight]) if args[:weight]
|
|
110
|
+
params.merge!(:height => args[:height]) if args[:height]
|
|
111
|
+
params.merge!(:width => args[:width]) if args[:width]
|
|
112
|
+
params.merge!(:depth => args[:depth]) if args[:depth]
|
|
113
|
+
@variant = create(:variant, params)
|
|
114
|
+
|
|
115
|
+
params = { :variant => @variant, :order => order }
|
|
116
|
+
params.merge!(:price => args[:price]) if args[:price]
|
|
117
|
+
params.merge!(:quantity => args[:quantity]) if args[:quantity]
|
|
118
|
+
line_item = create(:line_item, params)
|
|
119
|
+
|
|
120
|
+
order = line_item.order
|
|
121
|
+
order.line_items.reload
|
|
122
|
+
@shipment = create(:shipment, :order => order)
|
|
123
|
+
end
|
|
124
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require 'simplecov'
|
|
2
|
+
SimpleCov.start do
|
|
3
|
+
add_filter '/spec/'
|
|
4
|
+
add_filter '/lib/spree_postal_service/engine'
|
|
5
|
+
add_group 'Libraries', 'lib'
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
ENV['RAILS_ENV'] = 'test'
|
|
9
|
+
|
|
10
|
+
require File.expand_path('../dummy/config/environment.rb', __FILE__)
|
|
11
|
+
|
|
12
|
+
require 'ffaker'
|
|
13
|
+
require 'rspec/rails'
|
|
14
|
+
require 'i18n-spec'
|
|
15
|
+
|
|
16
|
+
Dir[Rails.root.join('spec/support/**/*.rb')].each {|f| require f}
|
|
17
|
+
|
|
18
|
+
require 'spree/core/testing_support/factories'
|
|
19
|
+
|
|
20
|
+
RSpec.configure do |config|
|
|
21
|
+
config.mock_with :rspec
|
|
22
|
+
config.use_transactional_fixtures = true
|
|
23
|
+
|
|
24
|
+
config.include FactoryGirl::Syntax::Methods
|
|
25
|
+
config.include Spree::Core::UrlHelpers
|
|
26
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe 'locale:' do
|
|
4
|
+
Dir.glob('config/locales/*.yml') do |locale_file|
|
|
5
|
+
context locale_file do
|
|
6
|
+
it { should be_parseable }
|
|
7
|
+
it { should have_valid_pluralization_keys }
|
|
8
|
+
it { should_not have_missing_pluralization_keys }
|
|
9
|
+
it { should have_one_top_level_namespace }
|
|
10
|
+
it { should_not have_legacy_interpolations }
|
|
11
|
+
it { should have_a_valid_locale }
|
|
12
|
+
it { should be_a_complete_translation_of 'config/locales/en.yml' }
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib/', __FILE__)
|
|
3
|
+
$:.unshift lib unless $:.include?(lib)
|
|
4
|
+
|
|
5
|
+
require 'spree_postal_service/version'
|
|
6
|
+
|
|
7
|
+
Gem::Specification.new do |s|
|
|
8
|
+
s.platform = Gem::Platform::RUBY
|
|
9
|
+
s.name = 'spree_postal_service'
|
|
10
|
+
s.version = SpreePostalService.version
|
|
11
|
+
s.summary = 'Calculate weight based charges for a Spree order'
|
|
12
|
+
s.description = s.summary
|
|
13
|
+
s.required_ruby_version = '>= 1.8.7'
|
|
14
|
+
|
|
15
|
+
s.authors = ['Torsten Rüger', 'Tobias Bohwalli']
|
|
16
|
+
s.email = 'hi@futhr.io'
|
|
17
|
+
s.homepage = 'https://github.com/futhr/spree-postal-service'
|
|
18
|
+
s.license = %q{BSD-3}
|
|
19
|
+
|
|
20
|
+
s.files = `git ls-files`.split("\n")
|
|
21
|
+
s.test_files = `git ls-files -- spec/*`.split("\n")
|
|
22
|
+
s.require_path = 'lib'
|
|
23
|
+
s.requirements << 'none'
|
|
24
|
+
|
|
25
|
+
s.has_rdoc = false
|
|
26
|
+
|
|
27
|
+
s.add_dependency 'spree_core', '~> 1.1.0'
|
|
28
|
+
|
|
29
|
+
s.add_development_dependency 'rspec', '~> 2.7.0'
|
|
30
|
+
s.add_development_dependency 'rspec-rails', '~> 2.7'
|
|
31
|
+
s.add_development_dependency 'factory_girl', '~> 2.6.3'
|
|
32
|
+
s.add_development_dependency 'sqlite3'
|
|
33
|
+
s.add_development_dependency 'simplecov'
|
|
34
|
+
s.add_development_dependency 'i18n-spec'
|
|
35
|
+
s.add_development_dependency 'ffaker'
|
|
36
|
+
s.add_development_dependency 'guard-rspec'
|
|
37
|
+
s.add_development_dependency 'pry-rails'
|
|
38
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: spree_postal_service
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.1.2
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Torsten Rüger
|
|
8
|
+
- Tobias Bohwalli
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2014-04-05 00:00:00.000000000 Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: spree_core
|
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
|
17
|
+
requirements:
|
|
18
|
+
- - ~>
|
|
19
|
+
- !ruby/object:Gem::Version
|
|
20
|
+
version: 1.1.0
|
|
21
|
+
type: :runtime
|
|
22
|
+
prerelease: false
|
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
24
|
+
requirements:
|
|
25
|
+
- - ~>
|
|
26
|
+
- !ruby/object:Gem::Version
|
|
27
|
+
version: 1.1.0
|
|
28
|
+
- !ruby/object:Gem::Dependency
|
|
29
|
+
name: rspec
|
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
|
31
|
+
requirements:
|
|
32
|
+
- - ~>
|
|
33
|
+
- !ruby/object:Gem::Version
|
|
34
|
+
version: 2.7.0
|
|
35
|
+
type: :development
|
|
36
|
+
prerelease: false
|
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
38
|
+
requirements:
|
|
39
|
+
- - ~>
|
|
40
|
+
- !ruby/object:Gem::Version
|
|
41
|
+
version: 2.7.0
|
|
42
|
+
- !ruby/object:Gem::Dependency
|
|
43
|
+
name: rspec-rails
|
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
|
45
|
+
requirements:
|
|
46
|
+
- - ~>
|
|
47
|
+
- !ruby/object:Gem::Version
|
|
48
|
+
version: '2.7'
|
|
49
|
+
type: :development
|
|
50
|
+
prerelease: false
|
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
52
|
+
requirements:
|
|
53
|
+
- - ~>
|
|
54
|
+
- !ruby/object:Gem::Version
|
|
55
|
+
version: '2.7'
|
|
56
|
+
- !ruby/object:Gem::Dependency
|
|
57
|
+
name: factory_girl
|
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
|
59
|
+
requirements:
|
|
60
|
+
- - ~>
|
|
61
|
+
- !ruby/object:Gem::Version
|
|
62
|
+
version: 2.6.3
|
|
63
|
+
type: :development
|
|
64
|
+
prerelease: false
|
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
66
|
+
requirements:
|
|
67
|
+
- - ~>
|
|
68
|
+
- !ruby/object:Gem::Version
|
|
69
|
+
version: 2.6.3
|
|
70
|
+
- !ruby/object:Gem::Dependency
|
|
71
|
+
name: sqlite3
|
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
|
73
|
+
requirements:
|
|
74
|
+
- - ! '>='
|
|
75
|
+
- !ruby/object:Gem::Version
|
|
76
|
+
version: '0'
|
|
77
|
+
type: :development
|
|
78
|
+
prerelease: false
|
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
80
|
+
requirements:
|
|
81
|
+
- - ! '>='
|
|
82
|
+
- !ruby/object:Gem::Version
|
|
83
|
+
version: '0'
|
|
84
|
+
- !ruby/object:Gem::Dependency
|
|
85
|
+
name: simplecov
|
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
|
87
|
+
requirements:
|
|
88
|
+
- - ! '>='
|
|
89
|
+
- !ruby/object:Gem::Version
|
|
90
|
+
version: '0'
|
|
91
|
+
type: :development
|
|
92
|
+
prerelease: false
|
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
94
|
+
requirements:
|
|
95
|
+
- - ! '>='
|
|
96
|
+
- !ruby/object:Gem::Version
|
|
97
|
+
version: '0'
|
|
98
|
+
- !ruby/object:Gem::Dependency
|
|
99
|
+
name: i18n-spec
|
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
|
101
|
+
requirements:
|
|
102
|
+
- - ! '>='
|
|
103
|
+
- !ruby/object:Gem::Version
|
|
104
|
+
version: '0'
|
|
105
|
+
type: :development
|
|
106
|
+
prerelease: false
|
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
108
|
+
requirements:
|
|
109
|
+
- - ! '>='
|
|
110
|
+
- !ruby/object:Gem::Version
|
|
111
|
+
version: '0'
|
|
112
|
+
- !ruby/object:Gem::Dependency
|
|
113
|
+
name: ffaker
|
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
|
115
|
+
requirements:
|
|
116
|
+
- - ! '>='
|
|
117
|
+
- !ruby/object:Gem::Version
|
|
118
|
+
version: '0'
|
|
119
|
+
type: :development
|
|
120
|
+
prerelease: false
|
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
122
|
+
requirements:
|
|
123
|
+
- - ! '>='
|
|
124
|
+
- !ruby/object:Gem::Version
|
|
125
|
+
version: '0'
|
|
126
|
+
- !ruby/object:Gem::Dependency
|
|
127
|
+
name: guard-rspec
|
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
|
129
|
+
requirements:
|
|
130
|
+
- - ! '>='
|
|
131
|
+
- !ruby/object:Gem::Version
|
|
132
|
+
version: '0'
|
|
133
|
+
type: :development
|
|
134
|
+
prerelease: false
|
|
135
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
136
|
+
requirements:
|
|
137
|
+
- - ! '>='
|
|
138
|
+
- !ruby/object:Gem::Version
|
|
139
|
+
version: '0'
|
|
140
|
+
- !ruby/object:Gem::Dependency
|
|
141
|
+
name: pry-rails
|
|
142
|
+
requirement: !ruby/object:Gem::Requirement
|
|
143
|
+
requirements:
|
|
144
|
+
- - ! '>='
|
|
145
|
+
- !ruby/object:Gem::Version
|
|
146
|
+
version: '0'
|
|
147
|
+
type: :development
|
|
148
|
+
prerelease: false
|
|
149
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
150
|
+
requirements:
|
|
151
|
+
- - ! '>='
|
|
152
|
+
- !ruby/object:Gem::Version
|
|
153
|
+
version: '0'
|
|
154
|
+
description: Calculate weight based charges for a Spree order
|
|
155
|
+
email: hi@futhr.io
|
|
156
|
+
executables: []
|
|
157
|
+
extensions: []
|
|
158
|
+
extra_rdoc_files: []
|
|
159
|
+
files:
|
|
160
|
+
- .gitignore
|
|
161
|
+
- .rspec
|
|
162
|
+
- .travis.yml
|
|
163
|
+
- CONTRIBUTING.md
|
|
164
|
+
- Gemfile
|
|
165
|
+
- Guardfile
|
|
166
|
+
- LICENSE.md
|
|
167
|
+
- README.md
|
|
168
|
+
- Rakefile
|
|
169
|
+
- config/locales/en.yml
|
|
170
|
+
- config/locales/pt.yml
|
|
171
|
+
- config/locales/sv.yml
|
|
172
|
+
- lib/spree/calculator/postal_service.rb
|
|
173
|
+
- lib/spree_postal_service.rb
|
|
174
|
+
- lib/spree_postal_service/engine.rb
|
|
175
|
+
- lib/spree_postal_service/version.rb
|
|
176
|
+
- script/rails
|
|
177
|
+
- spec/lib/postal_service_spec.rb
|
|
178
|
+
- spec/spec_helper.rb
|
|
179
|
+
- spec/translations/locale_spec.rb
|
|
180
|
+
- spree_postal_service.gemspec
|
|
181
|
+
homepage: https://github.com/futhr/spree-postal-service
|
|
182
|
+
licenses:
|
|
183
|
+
- BSD-3
|
|
184
|
+
metadata: {}
|
|
185
|
+
post_install_message:
|
|
186
|
+
rdoc_options: []
|
|
187
|
+
require_paths:
|
|
188
|
+
- lib
|
|
189
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
190
|
+
requirements:
|
|
191
|
+
- - ! '>='
|
|
192
|
+
- !ruby/object:Gem::Version
|
|
193
|
+
version: 1.8.7
|
|
194
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
195
|
+
requirements:
|
|
196
|
+
- - ! '>='
|
|
197
|
+
- !ruby/object:Gem::Version
|
|
198
|
+
version: '0'
|
|
199
|
+
requirements:
|
|
200
|
+
- none
|
|
201
|
+
rubyforge_project:
|
|
202
|
+
rubygems_version: 2.2.2
|
|
203
|
+
signing_key:
|
|
204
|
+
specification_version: 4
|
|
205
|
+
summary: Calculate weight based charges for a Spree order
|
|
206
|
+
test_files:
|
|
207
|
+
- spec/lib/postal_service_spec.rb
|
|
208
|
+
- spec/spec_helper.rb
|
|
209
|
+
- spec/translations/locale_spec.rb
|