spree_zaez_tnt_mercurio 3.0.5 → 3.0.6
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
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9cc60f9d84ddfc41bcd742b737788c07ddfc7637
|
4
|
+
data.tar.gz: 96a93ecb203ce23196c214a28963999aa3379b78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06fe17363a5fdaabfb44b7858c919ccb75094e74993e7c5e20983c11a6fb4191eedd56c5f208f914cc735c0d0955e31e7cb28f74538403271fde39a1f8f0a9e9
|
7
|
+
data.tar.gz: 836fcbcc1c6695b2f3a207cd89a859f1cb507921cc5f652d97c6b743b4b7c75d06f0005eb2ac4397b5f876864c7d18ca3464ec32354aac26b8d1ad4fa36b6565
|
@@ -39,8 +39,39 @@ module Spree
|
|
39
39
|
|
40
40
|
cost = response[:calcula_frete_response][:out][:vl_total_frete].to_f + Spree::TntMercurioConfig.additional_value
|
41
41
|
{cost: cost, delivery_time: @delivery_time}
|
42
|
+
rescue
|
43
|
+
try_calculate_from_orders(zipcode_to, object.weight)
|
44
|
+
end
|
45
|
+
|
46
|
+
# Tenta buscar um pedido feito para o mesmo CEP de entrega e
|
47
|
+
# que tenha um peso parecido (diferenca de 1kg para mais ou menos)
|
48
|
+
# para recuperar o valor do frete e o tempo de entrega
|
49
|
+
def try_calculate_from_orders(zipcode, weight)
|
50
|
+
shipping_type = "Spree::Calculator::Shipping::TntMercurio#{shipping_method}"
|
51
|
+
calculator = Spree::Calculator.find_by(type: shipping_type, calculable_type: 'Spree::ShippingMethod')
|
52
|
+
return {} if calculator.nil?
|
53
|
+
shipping_method_id = calculator.calculable_id
|
54
|
+
|
55
|
+
shipping_rates_id = Spree::ShippingRate.joins(:shipping_method).joins(shipment: :order).
|
56
|
+
joins('INNER JOIN spree_addresses ON spree_addresses.id = spree_orders.ship_address_id').
|
57
|
+
where(shipping_method_id: shipping_method_id, spree_addresses: { zipcode: zipcode }).
|
58
|
+
group('spree_shipping_rates.id').pluck(:id)
|
59
|
+
|
60
|
+
init_value = weight - 1
|
61
|
+
final_value = weight + 1
|
62
|
+
|
63
|
+
shipping_rates_id.each do |id|
|
64
|
+
shipping_rate = Spree::ShippingRate.find(id)
|
65
|
+
weight = shipping_rate.shipment.to_package.weight
|
66
|
+
|
67
|
+
if weight.between?(init_value, final_value)
|
68
|
+
return { cost: shipping_rate.cost.to_f, delivery_time: shipping_rate.delivery_time }
|
69
|
+
end
|
70
|
+
end
|
71
|
+
{}
|
42
72
|
rescue
|
43
73
|
{}
|
44
74
|
end
|
75
|
+
|
45
76
|
end
|
46
77
|
end
|
@@ -6,4 +6,12 @@ FactoryGirl.define do
|
|
6
6
|
ship_address
|
7
7
|
end
|
8
8
|
|
9
|
+
factory :shipping_rate, class: Spree::ShippingRate do
|
10
|
+
selected 1
|
11
|
+
cost 10
|
12
|
+
delivery_time 3
|
13
|
+
association :shipping_method, factory: :shipping_method
|
14
|
+
association :shipment, factory: :shipment
|
15
|
+
end
|
16
|
+
|
9
17
|
end
|
@@ -156,4 +156,53 @@ shared_examples_for 'tnt calculator' do
|
|
156
156
|
end
|
157
157
|
end
|
158
158
|
|
159
|
+
context 'using information of previuos order' do
|
160
|
+
|
161
|
+
let(:previous_order) { create(:shipped_order) }
|
162
|
+
let(:shipping_method) { create(:shipping_method, name: 'TNT') }
|
163
|
+
let!(:shipping_calculator) { create(:calculator,
|
164
|
+
calculable: shipping_method,
|
165
|
+
type: "Spree::Calculator::Shipping::TntMercurio#{calculator.shipping_method}") }
|
166
|
+
|
167
|
+
before do
|
168
|
+
create(:shipping_rate, shipment: previous_order.shipments.first, cost: 15,
|
169
|
+
delivery_time: 5, shipping_method: shipping_method, selected: 1)
|
170
|
+
|
171
|
+
# New Order
|
172
|
+
user = create(:user, authentication_token: '12345678900')
|
173
|
+
@new_order = create(:order, line_items: previous_order.line_items,
|
174
|
+
ship_address: previous_order.ship_address, user: user)
|
175
|
+
stock_location = create(:stock_location, zipcode: '08465312')
|
176
|
+
shipment = create(:shipment, order: @new_order, stock_location: stock_location)
|
177
|
+
@new_package = shipment.to_package
|
178
|
+
|
179
|
+
@new_params = {in0: {login: 'teste@email.com',
|
180
|
+
senha: 'password',
|
181
|
+
nr_identif_cliente_rem: '1234678900000',
|
182
|
+
nr_inscricao_estadual_remetente: '344028650118',
|
183
|
+
nr_identif_cliente_dest: '12345678900',
|
184
|
+
tp_situacao_tributaria_remetente: 'CO',
|
185
|
+
tp_pessoa_remetente: 'J',
|
186
|
+
tp_pessoa_destinatario: 'F',
|
187
|
+
tp_situacao_tributaria_destinatario: 'NC',
|
188
|
+
cep_origem: '08465312',
|
189
|
+
cep_destino: @new_order.ship_address.zipcode,
|
190
|
+
vl_mercadoria: @new_order.total.to_s,
|
191
|
+
ps_real: @new_package.weight.to_s,
|
192
|
+
tp_servico: calculator.shipping_method,
|
193
|
+
tp_frete: 'C',
|
194
|
+
cd_divisao_cliente: 1}}
|
195
|
+
end
|
196
|
+
|
197
|
+
it 'should use information of previous orders when request to TNT fails' do
|
198
|
+
fixture = File.read('spec/fixtures/calcula_frete/error_response.xml')
|
199
|
+
savon.expects(:calcula_frete).with(message: @new_params).returns(fixture)
|
200
|
+
response = calculator.compute_package(@new_package)
|
201
|
+
|
202
|
+
expect(response[:cost]).to eq 15
|
203
|
+
expect(response[:delivery_time]).to eq 5
|
204
|
+
end
|
205
|
+
|
206
|
+
end
|
207
|
+
|
159
208
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -24,6 +24,7 @@ Capybara.javascript_driver = :poltergeist
|
|
24
24
|
# Requires supporting ruby files with custom matchers and macros, etc,
|
25
25
|
# in spec/support/ and its subdirectories.
|
26
26
|
Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require f }
|
27
|
+
Dir[File.join(File.dirname(__FILE__), 'shared_examples/**/*.rb')].each { |f| require f }
|
27
28
|
|
28
29
|
# Requires factories and other useful helpers defined in spree_core.
|
29
30
|
require 'spree/testing_support/authorization_helpers'
|
@@ -2,7 +2,7 @@
|
|
2
2
|
Gem::Specification.new do |s|
|
3
3
|
s.platform = Gem::Platform::RUBY
|
4
4
|
s.name = 'spree_zaez_tnt_mercurio'
|
5
|
-
s.version = '3.0.
|
5
|
+
s.version = '3.0.6'
|
6
6
|
s.summary = 'Implements diverse functions in order to enable the use of services from TNT Mercúrio in Spree Commerce'
|
7
7
|
s.description = 'Implements diverse functions in order to enable the use of services from TNT Mercúrio in Spree Commerce'
|
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_tnt_mercurio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zaez Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-09-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: spree_core
|