solidus_me 0.0.1 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/solidus_me/preferences.rb +1 -1
- data/app/models/solidus_me/shipping_estimator.rb +24 -13
- data/lib/solidus_me/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36950d790364e7b63398fb6eafa4e6ffb8d31dc947340ed0114bcf6a49c81fca
|
4
|
+
data.tar.gz: bf86fa63fee12d03d35d4964074ca16b61e0bfc827118894f14716ab6524bb0a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0bc720b9d98e6c8ac03c65a24d9dc7cbf0f8ea8080b8c033f28cd4fb1eff26c9a71a39933aa51c62a5acff6da073d86eabffe58436a395b979b9a5cefee344d
|
7
|
+
data.tar.gz: df19fc08bd975d79617686938b16c1b3bcb75c67c04c2df37551ec9c2699d8b8196ab93b536725f31f35543dbe372a21465fdb395b14cb60147c63853c3f7d0a
|
@@ -9,7 +9,7 @@ module SolidusMe
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def check
|
12
|
-
|
12
|
+
return if @preferences[:client_id].nil? || @preferences[:client_secret].nil? || @preferences[:refresh_token].nil?
|
13
13
|
return if (@preferences[:token_expires_in]&.to_datetime - 1.day) > DateTime.now
|
14
14
|
refresh
|
15
15
|
end
|
@@ -12,7 +12,7 @@ module SolidusMe
|
|
12
12
|
shipping_rates = melhor_envio_rates.map do |melhor_envio_rate|
|
13
13
|
build_shipping_rate(melhor_envio_rate, package)
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
unless shipping_rates.empty?
|
17
17
|
default_shipping_rate = Spree::Config.shipping_rate_selector_class.new(shipping_rates).find_default
|
18
18
|
default_shipping_rate.selected = true
|
@@ -24,18 +24,29 @@ module SolidusMe
|
|
24
24
|
private
|
25
25
|
|
26
26
|
def get_rates_from_melhor_envio(package)
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
27
|
+
begin
|
28
|
+
weight = package.contents.map {|content| content.weight }.sum
|
29
|
+
price = package.contents.map {|content| content.price }.sum
|
30
|
+
zipcode = package.order.ship_address.zipcode
|
31
|
+
services = @preferences[:services] || ["SEDEX", "PAC", "Mini Envios", ".Package", ".Com"]
|
32
|
+
|
33
|
+
rates = @me_client.rates(
|
34
|
+
from: @preferences[:postal_code_from],
|
35
|
+
to: zipcode,
|
36
|
+
weight_kg: (weight/1000),
|
37
|
+
contents_value_brl: price
|
38
|
+
)
|
39
|
+
rates.select { |rate| rate.price > 0 && services.include?(rate.service_name) }
|
40
|
+
rescue
|
41
|
+
[
|
42
|
+
OpenStruct.new({
|
43
|
+
price: 15.00,
|
44
|
+
service_name: "",
|
45
|
+
carrier_name: "Frete padrão",
|
46
|
+
delivery_range: { "min" => 5, "max" => 5 }
|
47
|
+
})
|
48
|
+
]
|
49
|
+
end
|
39
50
|
end
|
40
51
|
|
41
52
|
def build_shipping_rate(melhor_envio_rate, package)
|
data/lib/solidus_me/version.rb
CHANGED