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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7554f46caa80ea5d72b15434c605a0cb56a64fc13085aba8437c6efc85389adb
4
- data.tar.gz: e1c8dd18ed9266935f045c95d86cf37c79bc902fbca4689a8bbcdb3850c9d7de
3
+ metadata.gz: '08b92393f89a8c0168ce3b490511a57c24f853dc30939b01b8a3ad97327ea6dc'
4
+ data.tar.gz: 14573225cef0c766503628bebe3a3e401871e99753eec8a29264cd260de7d0cd
5
5
  SHA512:
6
- metadata.gz: e22ca3b5438ffdc5f6689c0e20358275f0f864ccaa3a60c7caa99094e6c27a1b9ec1c0748df5caca81e678b22e61859a6e76c65fab838ddd027343f0a1ad115a
7
- data.tar.gz: 896110bc1a55edf29b52df1b4811892453965644cc410ddc5574b97245817827703f586803e6b4fd23ddec6763d415868cf98183cdf06a5c80bbb1a345304f09
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
- raise "Client ID, Client Secret and Refresh Token must be filled in." if @preferences[:client_id].nil? || @preferences[:client_secret].nil? || @preferences[:refresh_token].nil?
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
- weight = package.contents.map {|content| content.weight }.sum
28
- price = package.contents.map {|content| content.price }.sum
29
- zipcode = package.order.ship_address.zipcode
30
- services = @preferences[:services] || ["SEDEX", "PAC", "Mini Envios", ".Package", ".Com"]
31
-
32
- rates = @me_client.rates(
33
- from: @preferences[:postal_code_from],
34
- to: zipcode,
35
- weight_kg: (weight/1000),
36
- contents_value_brl: price
37
- )
38
- rates.select { |rate| rate.price > 0 && services.include?(rate.service_name) }
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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidusMe
4
- VERSION = '0.0.1'
4
+ VERSION = '1.0.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus_me
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hamilton Tumenas Borges