spree_zaez_correios 3.0.4 → 3.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/spree/calculator/shipping/correios_base_calculator.rb +164 -29
- data/app/models/spree/calculator/shipping/pac.rb +5 -0
- data/app/models/spree/calculator/shipping/sedex.rb +4 -0
- data/app/models/spree/calculator/shipping/sedex10.rb +4 -0
- data/lib/spree_zaez_correios.rb +1 -0
- data/spec/models/spree/calculator/shipping/correios_calculator_spec.rb +9 -9
- data/spec/models/spree/calculator/shipping/pac_spec.rb +8 -10
- data/spec/models/spree/calculator/shipping/sedex10_spec.rb +4 -6
- data/spec/models/spree/calculator/shipping/sedex_spec.rb +8 -10
- data/spec/models/spree/stock/estimator_decorator_spec.rb +13 -0
- data/spec/support/correios_shared_examples.rb +104 -67
- data/spree_zaez_correios.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b30e23fbc5293123daf61b2e4b9038b2c459407d
|
4
|
+
data.tar.gz: 4b7ecb4c78ad7c1acd6a98db07d71b90e5a4671d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d59e8761e019426b7b948d2afca952c017426a72ce8e86fc45ca29d424d38075c7558415719678da193a4ac207d4c70292a3aa6cf36d84596196e91c678607b
|
7
|
+
data.tar.gz: f20d8b11ad51361889d46c59afc537f22d0f14ca917e21f1c46fc0fdda7115ca1d69016d505f6a9846c9782eeb1e3c1412d9fd93849e1d57a670334dc7965794
|
@@ -7,51 +7,186 @@ module Spree
|
|
7
7
|
preference :declared_value, :boolean, default: false
|
8
8
|
preference :receipt_notification, :boolean, default: false
|
9
9
|
preference :receive_in_hands, :boolean, default: false
|
10
|
-
|
10
|
+
|
11
|
+
# Tamanhos maximos que um pacote pode ter para ser enviado pelos correios
|
12
|
+
# Soma maxima das dimensoes (compr. + alt. + larg.)
|
13
|
+
#
|
14
|
+
# documentacao em: http://www.correios.com.br/para-voce/precisa-de-ajuda/limites-de-dimensoes-e-de-peso
|
15
|
+
#
|
16
|
+
MAX_WIDTH = 105
|
17
|
+
MAX_DEPTH = 105
|
18
|
+
MAX_HEIGHT = 105
|
19
|
+
MAX_DIMENSIONS = 200
|
20
|
+
|
11
21
|
attr_reader :delivery_time
|
12
|
-
|
13
|
-
def compute_package(object)
|
14
|
-
return if object.nil?
|
15
|
-
order = if object.is_a?(Spree::Order) then object else object.order end
|
16
22
|
|
17
|
-
|
23
|
+
# Calculates the shipping cost
|
24
|
+
#
|
25
|
+
# Algorithm inspired in Opencart extension created by Thalles Cardoso <thallescard@gmail.com>
|
26
|
+
#
|
27
|
+
# @param package [Spree::Package]
|
28
|
+
#
|
29
|
+
# @return [Hash]
|
30
|
+
#
|
31
|
+
def compute_package package
|
32
|
+
return if package.nil?
|
33
|
+
@order = package.order
|
34
|
+
|
35
|
+
@stock_location = package.stock_location
|
36
|
+
|
37
|
+
pkg = Correios::Frete::Pacote.new
|
38
|
+
pkg_dimensions = {width: 0, height: 0, depth: 0, weight: 0}
|
39
|
+
packages = [pkg]
|
40
|
+
|
41
|
+
package.contents.each do |item|
|
42
|
+
return {} unless valid_dimensions?(item.variant)
|
43
|
+
|
44
|
+
new_width = item.variant.width + pkg_dimensions[:width]
|
45
|
+
new_height = item.variant.height + pkg_dimensions[:height]
|
46
|
+
new_depth = item.variant.depth + pkg_dimensions[:depth]
|
47
|
+
new_weight = item.variant.weight + pkg_dimensions[:weight]
|
48
|
+
|
49
|
+
if (new_width <= MAX_WIDTH and verify_max_dimensions(pkg_dimensions, item.variant, :width)) and (new_weight <= max_weight)
|
50
|
+
pkg_dimensions[:weight] += item.variant.weight
|
51
|
+
|
52
|
+
pkg_dimensions[:width] += item.variant.width
|
53
|
+
pkg_dimensions[:height] = pkg_dimensions[:height] >= item.variant.height ? pkg_dimensions[:height] : item.variant.height
|
54
|
+
pkg_dimensions[:depth] = pkg_dimensions[:depth] >= item.variant.depth ? pkg_dimensions[:depth] : item.variant.depth
|
55
|
+
elsif (new_height <= MAX_HEIGHT and verify_max_dimensions(pkg_dimensions, item.variant, :height)) and (new_weight <= max_weight)
|
56
|
+
pkg_dimensions[:weight] += item.variant.weight
|
57
|
+
|
58
|
+
pkg_dimensions[:height] += item.variant.height
|
59
|
+
pkg_dimensions[:width] = pkg_dimensions[:width] >= item.variant.width ? pkg_dimensions[:width] : item.variant.width
|
60
|
+
pkg_dimensions[:depth] = pkg_dimensions[:depth] >= item.variant.depth ? pkg_dimensions[:depth] : item.variant.depth
|
61
|
+
elsif (new_depth <= MAX_DEPTH and verify_max_dimensions(pkg_dimensions, item.variant, :depth)) and (new_weight <= max_weight)
|
62
|
+
pkg_dimensions[:weight] += item.variant.weight
|
18
63
|
|
19
|
-
|
64
|
+
pkg_dimensions[:depth] += item.variant.depth
|
65
|
+
pkg_dimensions[:height] = pkg_dimensions[:height] >= item.variant.height ? pkg_dimensions[:height] : item.variant.height
|
66
|
+
pkg_dimensions[:width] = pkg_dimensions[:width] >= item.variant.width ? pkg_dimensions[:width] : item.variant.width
|
67
|
+
else
|
68
|
+
pkg = Correios::Frete::Pacote.new
|
69
|
+
pkg_dimensions = {width: item.variant.width,
|
70
|
+
height: item.variant.height,
|
71
|
+
depth: item.variant.depth,
|
72
|
+
weight: item.variant.weight}
|
20
73
|
|
21
|
-
|
74
|
+
packages << pkg
|
75
|
+
end
|
76
|
+
package_item = Correios::Frete::PacoteItem.new(peso: item.variant.weight.to_f,
|
77
|
+
comprimento: item.variant.depth.to_f,
|
78
|
+
largura: item.variant.width.to_f,
|
79
|
+
altura: item.variant.height.to_f)
|
80
|
+
pkg.add_item(package_item)
|
81
|
+
end
|
82
|
+
|
83
|
+
value = 0
|
84
|
+
delivery_time = 0
|
85
|
+
|
86
|
+
packages.each do |pkg|
|
87
|
+
response = calculate_shipping pkg
|
22
88
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
package.add_item(package_item)
|
89
|
+
if response.is_a? Hash
|
90
|
+
value += response[:value]
|
91
|
+
delivery_time = response[:delivery_time] if response[:delivery_time] > delivery_time
|
92
|
+
else
|
93
|
+
return {}
|
94
|
+
end
|
30
95
|
end
|
31
96
|
|
97
|
+
@delivery_time = delivery_time + preferred_additional_days
|
98
|
+
cost = value + preferred_additional_value
|
99
|
+
{cost: cost, delivery_time: @delivery_time}
|
100
|
+
rescue
|
101
|
+
{}
|
102
|
+
end
|
103
|
+
|
104
|
+
# Verify if the store has contract to Correios
|
105
|
+
#
|
106
|
+
# @author Isabella Santos
|
107
|
+
#
|
108
|
+
# @return [Boolean]
|
109
|
+
#
|
110
|
+
def has_contract?
|
111
|
+
preferred_token.present? && preferred_password.present?
|
112
|
+
end
|
113
|
+
|
114
|
+
protected
|
115
|
+
|
116
|
+
# Verify if the produtct has valid dimensions for Correios
|
117
|
+
#
|
118
|
+
# @author Isabella Santos
|
119
|
+
#
|
120
|
+
# @param variant [Spree::Variant]
|
121
|
+
#
|
122
|
+
# @return [Boolean]
|
123
|
+
#
|
124
|
+
def valid_dimensions? variant
|
125
|
+
dimensions = variant.width + variant.depth + variant.height
|
126
|
+
if variant.width > MAX_WIDTH or variant.depth > MAX_DEPTH or
|
127
|
+
variant.height > MAX_HEIGHT or dimensions > MAX_DIMENSIONS or
|
128
|
+
variant.weight > max_weight
|
129
|
+
return false
|
130
|
+
end
|
131
|
+
true
|
132
|
+
end
|
133
|
+
|
134
|
+
# Verify the size of the product and the available space inside the box
|
135
|
+
#
|
136
|
+
# @author Isabella Santos
|
137
|
+
#
|
138
|
+
# @param dimensions [Hash]
|
139
|
+
# used dimensions of the box
|
140
|
+
# @param variant [Spree::Variant]
|
141
|
+
# variant of the package
|
142
|
+
# @param position [Symbol]
|
143
|
+
# position of the box
|
144
|
+
# The options are: :width, :height or :depth
|
145
|
+
#
|
146
|
+
# @return [Boolean]
|
147
|
+
#
|
148
|
+
def verify_max_dimensions(dimensions, variant, position)
|
149
|
+
case position
|
150
|
+
when :width
|
151
|
+
width = dimensions[:width] + variant.width
|
152
|
+
height = dimensions[:height] >= variant.height ? dimensions[:height] : variant.height
|
153
|
+
depth = dimensions[:depth] >= variant.depth ? dimensions[:depth] : variant.depth
|
154
|
+
when :height
|
155
|
+
height = dimensions[:height] + variant.height
|
156
|
+
depth = dimensions[:depth] >= variant.depth ? dimensions[:depth] : variant.depth
|
157
|
+
width = dimensions[:width] >= variant.width ? dimensions[:width] : variant.width
|
158
|
+
when :depth
|
159
|
+
depth = dimensions[:depth] + variant.depth
|
160
|
+
height = dimensions[:height] >= variant.height ? dimensions[:height] : variant.height
|
161
|
+
width = dimensions[:width] >= variant.width ? dimensions[:width] : variant.width
|
162
|
+
end
|
163
|
+
|
164
|
+
(width + height + depth) <= MAX_DIMENSIONS
|
165
|
+
end
|
166
|
+
|
167
|
+
# Request to Correios webservice
|
168
|
+
# the cost and delivery time
|
169
|
+
#
|
170
|
+
# @param package [Correios::Frete::Pacote]
|
171
|
+
#
|
172
|
+
# @return [Hash]
|
173
|
+
#
|
174
|
+
def calculate_shipping(package)
|
32
175
|
calculator = Correios::Frete::Calculador.new do |c|
|
33
|
-
c.cep_origem = stock_location.zipcode
|
34
|
-
c.cep_destino = order.ship_address.zipcode
|
176
|
+
c.cep_origem = @stock_location.zipcode
|
177
|
+
c.cep_destino = @order.ship_address.zipcode
|
35
178
|
c.encomenda = package
|
36
179
|
c.mao_propria = preferred_receive_in_hands
|
37
180
|
c.aviso_recebimento = preferred_receipt_notification
|
38
|
-
c.valor_declarado = order.amount.to_f if preferred_declared_value
|
39
|
-
c.codigo_empresa = preferred_token
|
40
|
-
c.senha = preferred_password
|
181
|
+
c.valor_declarado = @order.amount.to_f if preferred_declared_value
|
182
|
+
c.codigo_empresa = preferred_token if preferred_token.present?
|
183
|
+
c.senha = preferred_password if preferred_password.present?
|
41
184
|
end
|
42
185
|
|
43
186
|
webservice = calculator.calculate(shipping_method)
|
44
187
|
return false if webservice.erro?
|
45
188
|
|
46
|
-
|
47
|
-
cost = webservice.valor + preferred_additional_value
|
48
|
-
{cost: cost, delivery_time: @delivery_time}
|
49
|
-
rescue
|
50
|
-
{}
|
51
|
-
end
|
52
|
-
|
53
|
-
def has_contract?
|
54
|
-
preferred_token.present? && preferred_password.present?
|
189
|
+
{value: webservice.valor, delivery_time: webservice.prazo_entrega}
|
55
190
|
end
|
56
191
|
end
|
57
192
|
end
|
data/lib/spree_zaez_correios.rb
CHANGED
@@ -2,29 +2,29 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Spree::Calculator::Shipping::CorreiosBaseCalculator do
|
4
4
|
|
5
|
-
|
5
|
+
let(:calculator) { subject.class.new }
|
6
6
|
|
7
7
|
it 'should have preferences' do
|
8
8
|
preferences = [:token, :password, :additional_days, :additional_value, :declared_value, :receipt_notification, :receive_in_hands]
|
9
|
-
expect(
|
9
|
+
expect(calculator.preferences.keys).to eq(preferences)
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'declared value should default to false' do
|
13
|
-
expect(
|
13
|
+
expect(calculator.preferred_declared_value).to eq(false)
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'receipt notification should default to false' do
|
17
|
-
expect(
|
17
|
+
expect(calculator.preferred_receipt_notification).to eq(false)
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'receive in hands should default to false' do
|
21
|
-
expect(
|
21
|
+
expect(calculator.preferred_receive_in_hands).to eq(false)
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'should have a contract if both token and password are given' do
|
25
|
-
expect(
|
26
|
-
|
27
|
-
|
28
|
-
expect(
|
25
|
+
expect(calculator).not_to have_contract
|
26
|
+
calculator.preferred_token = 'some token'
|
27
|
+
calculator.preferred_password = 'some password'
|
28
|
+
expect(calculator).to have_contract
|
29
29
|
end
|
30
30
|
end
|
@@ -1,38 +1,36 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Spree::Calculator::Shipping::PAC do
|
4
|
-
|
5
|
-
@pac = Spree::Calculator::Shipping::PAC.new
|
6
|
-
end
|
4
|
+
let(:pac) { subject.class.new }
|
7
5
|
|
8
6
|
it_behaves_like 'correios calculator'
|
9
7
|
|
10
8
|
it 'should have a description' do
|
11
|
-
expect(
|
9
|
+
expect(pac.description).to eq('PAC')
|
12
10
|
end
|
13
11
|
|
14
12
|
context 'without a token and password' do
|
15
13
|
it 'should have a shipping method of :pac' do
|
16
|
-
expect(
|
14
|
+
expect(pac.shipping_method).to eq(:pac)
|
17
15
|
end
|
18
16
|
|
19
17
|
it 'should have a shipping code of 41106' do
|
20
|
-
expect(
|
18
|
+
expect(pac.shipping_code).to eq(41106)
|
21
19
|
end
|
22
20
|
end
|
23
21
|
|
24
22
|
context 'with a token and password' do
|
25
23
|
before do
|
26
|
-
|
27
|
-
|
24
|
+
pac.preferred_token = 'some token'
|
25
|
+
pac.preferred_password = 'some password'
|
28
26
|
end
|
29
27
|
|
30
28
|
it 'should have a shipping method of :pac_com_contrato' do
|
31
|
-
expect(
|
29
|
+
expect(pac.shipping_method).to eq(:pac_com_contrato)
|
32
30
|
end
|
33
31
|
|
34
32
|
it 'should have a shipping code of 41068' do
|
35
|
-
expect(
|
33
|
+
expect(pac.shipping_code).to eq(41068)
|
36
34
|
end
|
37
35
|
end
|
38
36
|
end
|
@@ -1,23 +1,21 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Spree::Calculator::Shipping::SEDEX10 do
|
4
|
-
|
5
|
-
@sedex10 = Spree::Calculator::Shipping::SEDEX10.new
|
6
|
-
end
|
4
|
+
let(:sedex10) { subject.class.new }
|
7
5
|
|
8
6
|
it_behaves_like 'correios calculator'
|
9
7
|
|
10
8
|
it 'should have a description' do
|
11
|
-
expect(
|
9
|
+
expect(sedex10.description).to eq('SEDEX 10')
|
12
10
|
end
|
13
11
|
|
14
12
|
context 'without a token and password' do
|
15
13
|
it 'should have a shipping method of :pac' do
|
16
|
-
expect(
|
14
|
+
expect(sedex10.shipping_method).to eq(:sedex_10)
|
17
15
|
end
|
18
16
|
|
19
17
|
it 'should have a shipping code of 40215' do
|
20
|
-
expect(
|
18
|
+
expect(sedex10.shipping_code).to eq(40215)
|
21
19
|
end
|
22
20
|
end
|
23
21
|
|
@@ -1,38 +1,36 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Spree::Calculator::Shipping::SEDEX do
|
4
|
-
|
5
|
-
@sedex = Spree::Calculator::Shipping::SEDEX.new
|
6
|
-
end
|
4
|
+
let(:sedex) { subject.class.new }
|
7
5
|
|
8
6
|
it_behaves_like 'correios calculator'
|
9
7
|
|
10
8
|
it 'should have a description' do
|
11
|
-
expect(
|
9
|
+
expect(sedex.description).to eq('SEDEX')
|
12
10
|
end
|
13
11
|
|
14
12
|
context 'without a token and password' do
|
15
13
|
it 'should have a shipping method of :pac' do
|
16
|
-
expect(
|
14
|
+
expect(sedex.shipping_method).to eq(:sedex)
|
17
15
|
end
|
18
16
|
|
19
17
|
it 'should have a shipping code of 40010' do
|
20
|
-
expect(
|
18
|
+
expect(sedex.shipping_code).to eq(40010)
|
21
19
|
end
|
22
20
|
end
|
23
21
|
|
24
22
|
context 'with a token and password' do
|
25
23
|
before do
|
26
|
-
|
27
|
-
|
24
|
+
sedex.preferred_token = 'some token'
|
25
|
+
sedex.preferred_password = 'some password'
|
28
26
|
end
|
29
27
|
|
30
28
|
it 'should have a shipping method of :pac_com_contrato' do
|
31
|
-
expect(
|
29
|
+
expect(sedex.shipping_method).to eq(:sedex_com_contrato_1)
|
32
30
|
end
|
33
31
|
|
34
32
|
it 'should have a shipping code of 40096' do
|
35
|
-
expect(
|
33
|
+
expect(sedex.shipping_code).to eq(40096)
|
36
34
|
end
|
37
35
|
end
|
38
36
|
end
|
@@ -27,6 +27,19 @@ module Spree
|
|
27
27
|
shipping_rates = subject.shipping_rates(package)
|
28
28
|
expect(shipping_rates.first.delivery_time).to eq 1
|
29
29
|
end
|
30
|
+
|
31
|
+
it 'should not create shipping rate if cost is unknow' do
|
32
|
+
allow_any_instance_of(ShippingMethod).to receive_message_chain(:calculator, :compute).and_return({})
|
33
|
+
shipping_rates = subject.shipping_rates(package)
|
34
|
+
expect(shipping_rates).to eq Array.new
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should save only cost if delivery time is not provided' do
|
38
|
+
allow_any_instance_of(ShippingMethod).to receive_message_chain(:calculator, :compute).and_return(10.0)
|
39
|
+
shipping_rate = subject.shipping_rates(package).first
|
40
|
+
expect(shipping_rate.cost).to eq 10.0
|
41
|
+
expect(shipping_rate.delivery_time).to be_nil
|
42
|
+
end
|
30
43
|
end
|
31
44
|
end
|
32
45
|
end
|
@@ -1,105 +1,142 @@
|
|
1
1
|
shared_examples_for 'correios calculator' do
|
2
2
|
|
3
|
-
|
3
|
+
let(:calculator) { subject.class.new }
|
4
4
|
|
5
5
|
context 'compute_package' do
|
6
6
|
|
7
|
-
#
|
7
|
+
# Stub the request to Correios Webservice
|
8
8
|
#
|
9
|
-
# @
|
9
|
+
# @param params [Hash]
|
10
10
|
#
|
11
|
-
def
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
return price, delivery_time
|
11
|
+
def stub_correios_request(params = {})
|
12
|
+
correios_attr = {valor: 10.0, prazo_entrega: 1}.merge!(params)
|
13
|
+
response = Correios::Frete::Servico.new(correios_attr)
|
14
|
+
allow_any_instance_of(Correios::Frete::Calculador).to receive(:calculate).and_return(response)
|
16
15
|
end
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
@shipment.inventory_units << FactoryGirl.build(:inventory_unit, variant: variant, order: @order, line_item: line_item, shipment: @shipment)
|
32
|
-
|
33
|
-
# package
|
34
|
-
@package = @shipment.to_package
|
35
|
-
@package.add @shipment.inventory_units.first
|
36
|
-
|
37
|
-
# default query
|
38
|
-
@default_query = {
|
39
|
-
nCdEmpresa: nil,
|
40
|
-
sDsSenha: nil,
|
41
|
-
sCepOrigem: '08465312',
|
42
|
-
sCepDestino: '17209420',
|
43
|
-
nVlPeso: 1,
|
44
|
-
nCdFormato: 1,
|
45
|
-
nVlComprimento: 20,
|
46
|
-
nVlAltura: 5,
|
47
|
-
nVlLargura: 15,
|
48
|
-
sCdMaoPropria: 'n',
|
49
|
-
nVlValorDeclarado: 0,
|
50
|
-
sCdAvisoRecebimento: 'n',
|
51
|
-
nCdServico: @calculator.shipping_code,
|
52
|
-
nVlDiametro: 0,
|
53
|
-
StrRetorno: 'xml'
|
54
|
-
}
|
17
|
+
let(:address) { FactoryGirl.build(:address, zipcode: '12345678') }
|
18
|
+
let(:variant) { FactoryGirl.build(:variant, weight: 1, height: 5, width: 15, depth: 20) }
|
19
|
+
let(:order) { FactoryGirl.build(:order_with_shipments, ship_address: address) }
|
20
|
+
let(:line_item) {FactoryGirl.build(:line_item, variant: variant, price: 100, order: order) }
|
21
|
+
let(:stock_location) { FactoryGirl.build(:stock_location, zipcode: '87654321') }
|
22
|
+
let(:shipment) { FactoryGirl.build(:shipment, order: order, stock_location: stock_location) }
|
23
|
+
let(:inventory_unit) { FactoryGirl.build(:inventory_unit, variant: variant, order: order, line_item: line_item, shipment: shipment) }
|
24
|
+
let(:package) do
|
25
|
+
order.line_items << line_item
|
26
|
+
shipment.inventory_units << inventory_unit
|
27
|
+
package = shipment.to_package
|
28
|
+
package.add inventory_unit
|
29
|
+
package
|
55
30
|
end
|
56
31
|
|
57
32
|
it 'should calculate shipping cost and delivery time' do
|
58
|
-
|
33
|
+
stub_correios_request
|
59
34
|
|
60
|
-
|
61
|
-
expect(
|
35
|
+
response = calculator.compute_package(package)
|
36
|
+
expect(response[:cost]).to eq(10.0)
|
37
|
+
expect(response[:delivery_time]).to eq(1)
|
62
38
|
end
|
63
39
|
|
64
40
|
it 'should possible add days to delivery time' do
|
65
|
-
|
41
|
+
stub_correios_request
|
66
42
|
|
67
|
-
|
43
|
+
calculator.preferred_additional_days = 3
|
68
44
|
|
69
|
-
|
70
|
-
expect(
|
45
|
+
response = calculator.compute_package(package)
|
46
|
+
expect(response[:delivery_time]).to eq(4)
|
71
47
|
end
|
72
48
|
|
73
49
|
it 'should possible add some value to price' do
|
74
|
-
|
50
|
+
stub_correios_request
|
75
51
|
|
76
|
-
|
52
|
+
calculator.preferred_additional_value = 10.0
|
77
53
|
|
78
|
-
|
54
|
+
response = calculator.compute_package(package)
|
55
|
+
expect(response[:cost]).to eq(20.0)
|
79
56
|
end
|
80
57
|
|
81
58
|
it 'should change price according to declared value' do
|
82
|
-
|
83
|
-
price, delivery_time = get_correios_price_and_value_for("http://ws.correios.com.br/calculador/CalcPrecoPrazo.aspx?#{query.to_query}")
|
59
|
+
stub_correios_request({valor: 15.0, valor_valor_declarado: 100.0})
|
84
60
|
|
85
|
-
|
86
|
-
|
61
|
+
calculator.preferred_declared_value = true
|
62
|
+
|
63
|
+
response = calculator.compute_package(package)
|
64
|
+
expect(response[:cost]).to eq(15.0)
|
87
65
|
end
|
88
66
|
|
89
67
|
it 'should change price according to in hands' do
|
90
|
-
|
91
|
-
|
68
|
+
stub_correios_request({valor: 17.0, valor_mao_propria: 4.0})
|
69
|
+
|
70
|
+
calculator.preferred_receive_in_hands = true
|
92
71
|
|
93
|
-
|
94
|
-
expect(
|
72
|
+
response = calculator.compute_package(package)
|
73
|
+
expect(response[:cost]).to eq(17.0)
|
95
74
|
end
|
96
75
|
|
97
76
|
it 'should change price according to receipt notification' do
|
98
|
-
|
99
|
-
|
77
|
+
stub_correios_request({valor: 21.0, valor_aviso_recebimento: 5.0})
|
78
|
+
|
79
|
+
calculator.preferred_receipt_notification = true
|
80
|
+
|
81
|
+
response = calculator.compute_package(package)
|
82
|
+
expect(response[:cost]).to eq(21.0)
|
83
|
+
end
|
84
|
+
|
85
|
+
context 'validate dimensions' do
|
86
|
+
it 'should split in 2 boxes' do
|
87
|
+
variant.weight = 0.3
|
88
|
+
variant.width = 100
|
89
|
+
variant.height = 30
|
90
|
+
variant.depth = 30
|
91
|
+
|
92
|
+
package.add FactoryGirl.build(:inventory_unit, variant: variant, order: order, line_item: line_item, shipment: shipment)
|
93
|
+
package.add FactoryGirl.build(:inventory_unit, variant: variant, order: order, line_item: line_item, shipment: shipment)
|
94
|
+
|
95
|
+
stub_correios_request
|
96
|
+
|
97
|
+
# Pacote tem 3 produtos com as dimensoes 100x30x30
|
98
|
+
# resultando em duas caixas
|
99
|
+
# Cada caixa tem o frete determinado de 10
|
100
|
+
# entao o retorno deve ser de 20
|
101
|
+
|
102
|
+
response = calculator.compute_package(package)
|
103
|
+
expect(response[:cost]).to eq(20.0)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context 'valid_dimensions?' do
|
109
|
+
let(:variant) { FactoryGirl.build(:variant, width: 50, height: 50, depth: 50, weight: 5) }
|
110
|
+
|
111
|
+
it 'valid if dimensions is permitted' do
|
112
|
+
expect(calculator.send(:valid_dimensions?, variant)).to be true
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'invalid if weight is greather than the permitted' do
|
116
|
+
variant.weight = calculator.max_weight + 1
|
117
|
+
expect(calculator.send(:valid_dimensions?, variant)).to be false
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'invalid if height is greather than 105cm' do
|
121
|
+
variant.height = 120
|
122
|
+
expect(calculator.send(:valid_dimensions?, variant)).to be false
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'invalid if width is greather than 105cm' do
|
126
|
+
variant.width = 120
|
127
|
+
expect(calculator.send(:valid_dimensions?, variant)).to be false
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'invalid if depth is greather than 105cm' do
|
131
|
+
variant.depth = 120
|
132
|
+
expect(calculator.send(:valid_dimensions?, variant)).to be false
|
133
|
+
end
|
100
134
|
|
101
|
-
|
102
|
-
|
135
|
+
it 'invalid if sum of dimensions is greather than 200cm' do
|
136
|
+
variant.height = 100
|
137
|
+
variant.width = 100
|
138
|
+
variant.depth = 100
|
139
|
+
expect(calculator.send(:valid_dimensions?, variant)).to be false
|
103
140
|
end
|
104
141
|
end
|
105
142
|
end
|
data/spree_zaez_correios.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
Gem::Specification.new do |s|
|
3
3
|
s.platform = Gem::Platform::RUBY
|
4
4
|
s.name = 'spree_zaez_correios'
|
5
|
-
s.version = '3.0.
|
5
|
+
s.version = '3.0.5'
|
6
6
|
s.summary = "Implements diverse functions in order to enable the use of services from Brazil's Correios in Spree Commerce"
|
7
7
|
s.description = s.summary
|
8
8
|
s.required_ruby_version = '>= 2.0.0'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spree_zaez_correios
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zaez Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: spree_core
|