solidus_me 0.0.1 → 1.0.0
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: '08b92393f89a8c0168ce3b490511a57c24f853dc30939b01b8a3ad97327ea6dc'
|
4
|
+
data.tar.gz: 14573225cef0c766503628bebe3a3e401871e99753eec8a29264cd260de7d0cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e8e1d41bf706515f0a64ab27384d110f314d8850e17d1faacd8d1a3f4ee65a5fbd8e78d0c2c3055734be650b93e2f7faa02d157a7a503bcef1628fb33889faa
|
7
|
+
data.tar.gz: 74822208f6c3714f1b336fffb3538458254df1ae434371e561787b0ee32844324b9c86d76e504d258c55e39d630ee8b19c5e66405af5d338b6f1124bc856fd9b
|
@@ -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