solidus_me 1.0.0 → 1.0.2

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: '08b92393f89a8c0168ce3b490511a57c24f853dc30939b01b8a3ad97327ea6dc'
4
- data.tar.gz: 14573225cef0c766503628bebe3a3e401871e99753eec8a29264cd260de7d0cd
3
+ metadata.gz: a89d704cbb3a8a4e5608af1df273b2648995285572c086093e98b7054cb9e9ce
4
+ data.tar.gz: f98e49c3cde1bcf4f85bd9d2469afd96ab6c01f0b0eb736a890f6ad343e517c5
5
5
  SHA512:
6
- metadata.gz: 5e8e1d41bf706515f0a64ab27384d110f314d8850e17d1faacd8d1a3f4ee65a5fbd8e78d0c2c3055734be650b93e2f7faa02d157a7a503bcef1628fb33889faa
7
- data.tar.gz: 74822208f6c3714f1b336fffb3538458254df1ae434371e561787b0ee32844324b9c86d76e504d258c55e39d630ee8b19c5e66405af5d338b6f1124bc856fd9b
6
+ metadata.gz: 14c383bea7b2378d33a728c3282038c3bae7088da2433d8f23a613970bd61ad48c7a486428270c0dbff8ae6aa3668813a61d74fd50b86be6dd5df56da99a1917
7
+ data.tar.gz: 8a10c4ef91bf67556fb337008db1dec890eee8a9090bcf7aed963096881e7d03d83f19ac32bc2f107c0be9aff361317cd4e80d089a2d8acd296f197d1055318a
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  [![CircleCI](https://circleci.com/gh/solidusio-contrib/solidus_me.svg?style=shield)](https://circleci.com/gh/solidusio-contrib/solidus_me)
4
4
  [![codecov](https://codecov.io/gh/solidusio-contrib/solidus_me/branch/master/graph/badge.svg)](https://codecov.io/gh/solidusio-contrib/solidus_me)
5
5
 
6
- <!-- Explain what your extension does. -->
6
+ Gem para cotar empresas e valores de entrega junto à Api do Melhor Envio.
7
7
 
8
8
  ## Installation
9
9
 
@@ -18,10 +18,35 @@ Bundle your dependencies and run the installation generator:
18
18
  ```shell
19
19
  bin/rails generate solidus_me:install
20
20
  ```
21
+ Adicionar no arquivo `/config/initilizers/spree.rb`
22
+
23
+ ```ruby
24
+ Spree.config do |config|
25
+ ---
26
+ config.stock.estimator_class = "SolidusMe::ShippingEstimator"
27
+ ---
28
+ end
29
+ ```
30
+
31
+ No painel do admin será adiconado o item do `Melhor Envio` no menu lateral. Nesta página deverão ser preenchidos os seguintes campos para autenticação do aplicativo:
32
+
33
+ ```text
34
+ CEP de origem:
35
+ Client ID:
36
+ Client Secret:
37
+ ```
38
+ Após salvar, o link completo para autenticação do aplicativo ficará disponível abaixo. Uma vez autorizado, são gerados os `refresh_token` e `access_token`, e o sistema estará pronto para cotação dos fretes junto ao Melhor Envio.
39
+
40
+ Por padrão, os serviços de entrega são os `SEDEX`, `PAC` e `MiniEnvios` dos CORREIOS. Porém, os serviços podem ser customizados de acordo com a necessidade. Basta adicioná-los aos `preferences` da `Spree::Store`:
41
+
42
+ ```ruby
43
+ # Por exemplo
44
+ Spree::Store.first.update(preferences: { melhor_envio: { services: ["SEDEX", "PAC", "Mini Envios", ".Com", ".Package"] } })
45
+ ```
21
46
 
22
47
  ## Usage
23
48
 
24
- <!-- Explain how to use your extension once it's been installed. -->
49
+
25
50
 
26
51
  ## Development
27
52
 
@@ -7,10 +7,7 @@ module Spree
7
7
  end
8
8
 
9
9
  def update
10
- @me_preferences[:postal_code_from] = params[:postal_code_from]
11
- @me_preferences[:client_id] = params[:client_id]
12
- @me_preferences[:client_secret] = params[:client_secret]
13
- @me_preferences[:refresh_token] = params[:refresh_token]
10
+ @me_preferences = preferences_params
14
11
  Spree::Store.first.update(preferences: { melhor_envio: @me_preferences })
15
12
  redirect_to admin_melhor_envio_index_path
16
13
  end
@@ -21,7 +18,7 @@ module Spree
21
18
  client_id: @me_preferences[:client_id],
22
19
  client_secret: @me_preferences[:client_secret],
23
20
  code: code,
24
- redirect_url: admin_melhor_envio_authorize_url
21
+ redirect_url: @me_preferences[:redirect_url]
25
22
  ).json
26
23
  @me_preferences[:access_token] = authorize_json["access_token"]
27
24
  @me_preferences[:refresh_token] = authorize_json["refresh_token"]
@@ -36,6 +33,11 @@ module Spree
36
33
  @me_preferences = Spree::Store.first.preferences[:melhor_envio]
37
34
  end
38
35
 
36
+ def preferences_params
37
+ hash_preferences = params.permit(:postal_code_from, :services, :client_id, :client_secret, :redirect_url, :state, :access_token, :refresh_token, :token_expires_in)
38
+ hash_preferences[:services] = hash_preferences[:services].split(" ")
39
+ hash_preferences
40
+ end
39
41
  end
40
42
  end
41
43
  end
@@ -43,7 +43,7 @@ module SolidusMe
43
43
  price: 15.00,
44
44
  service_name: "",
45
45
  carrier_name: "Frete padrão",
46
- delivery_range: { min: 5, max: 5 }
46
+ delivery_range: { "min" => 5, "max" => 5 }
47
47
  })
48
48
  ]
49
49
  end
@@ -11,6 +11,8 @@ module StorePreferences
11
11
  services: ["SEDEX", "PAC", "Mini Envios"],
12
12
  client_id: nil,
13
13
  client_secret: nil,
14
+ redirect_url: nil,
15
+ state: nil,
14
16
  access_token: nil,
15
17
  refresh_token: nil,
16
18
  token_expires_in: DateTime.now.to_s
@@ -7,8 +7,9 @@
7
7
  </div>
8
8
 
9
9
  <div style="margin-top: 10px;">
10
+ <%= form.hidden_field :services, value: @me_preferences[:services] %>
10
11
  <span>Serviços Disponíveis: <%= @me_preferences[:services]&.join(", ") %></span>
11
- </div>
12
+ </div>
12
13
 
13
14
  <div style="margin-top: 10px;">
14
15
  <%= form.label :client_id, "Client ID: " %>
@@ -20,6 +21,16 @@
20
21
  <%= form.text_field :client_secret, value: @me_preferences[:client_secret] %>
21
22
  </div>
22
23
 
24
+ <div style="margin-top: 10px;">
25
+ <%= form.label :redirect_url, "Redirect URL: " %>
26
+ <%= form.text_field :redirect_url, value: @me_preferences[:redirect_url] %>
27
+ </div>
28
+
29
+ <div style="margin-top: 10px;">
30
+ <%= form.label :state, "State: " %>
31
+ <%= form.text_field :state, value: @me_preferences[:state] %>
32
+ </div>
33
+
23
34
  <div style="margin-top: 10px;">
24
35
  <%= form.label :access_token, "Access Token: " %>
25
36
  <%= form.text_field :access_token, value: @me_preferences[:access_token] %>
@@ -31,6 +42,7 @@
31
42
  </div>
32
43
 
33
44
  <div style="margin-top: 10px;">
45
+ <%= form.hidden_field :token_expires_in, value: @me_preferences[:token_expires_in] %>
34
46
  <span>Expiração do token: <%= @me_preferences[:token_expires_in] %></span>
35
47
  </div>
36
48
 
@@ -38,8 +50,8 @@
38
50
  <% end %>
39
51
 
40
52
  <div>
41
- <input value="https://www.melhorenvio.com.br/oauth/authorize?client_id=<%= @me_preferences[:client_id] %>&redirect_uri=<%= admin_melhor_envio_authorize_url %>&response_type=code&state=melhor_envio&scope=shipping-calculate">
42
- <a target="_blank" class="" href="https://www.melhorenvio.com.br/oauth/authorize?client_id=<%= @me_preferences[:client_id] %>&redirect_uri=<%= admin_melhor_envio_authorize_url %>&response_type=code&state=melhor_envio&scope=shipping-calculate">
53
+ <input value="https://www.melhorenvio.com.br/oauth/authorize?client_id=<%= @me_preferences[:client_id] %>&redirect_uri=<%= @me_preferences[:redirect_url] %>&response_type=code&state=<%= @me_preferences[:state] %>&scope=shipping-calculate">
54
+ <a target="_blank" class="" href="https://www.melhorenvio.com.br/oauth/authorize?client_id=<%= @me_preferences[:client_id] %>&redirect_uri=<%= @me_preferences[:redirect_url] %>&response_type=code&state=<%= @me_preferences[:state] %>&scope=shipping-calculate">
43
55
  <svg style="width: 24px; height: 24px;" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
44
56
  <path stroke-linecap="round" stroke-linejoin="round" d="M13.5 6H5.25A2.25 2.25 0 003 8.25v10.5A2.25 2.25 0 005.25 21h10.5A2.25 2.25 0 0018 18.75V10.5m-10.5 6L21 3m0 0h-5.25M21 3v5.25"></path></svg>
45
57
  </a>
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidusMe
4
- VERSION = '1.0.0'
4
+ VERSION = '1.0.2'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus_me
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hamilton Tumenas Borges
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-11-06 00:00:00.000000000 Z
11
+ date: 2023-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: solidus_core
@@ -106,7 +106,6 @@ files:
106
106
  - config/locales/pt-BR.yml
107
107
  - config/routes.rb
108
108
  - db/migrate/20231103133348_add_preferences_to_spree_store.rb
109
- - db/migrate/20231103175330_add_delivery_time_to_spree_shipping_rate.rb
110
109
  - lib/generators/solidus_me/install/install_generator.rb
111
110
  - lib/generators/solidus_me/install/templates/initializer.rb
112
111
  - lib/solidus_me.rb
@@ -1,6 +0,0 @@
1
- class AddDeliveryTimeToSpreeShippingRate < ActiveRecord::Migration[7.0]
2
- def change
3
- add_column :spree_shipping_rates, :min_delivery_time, :integer, if_not_exists: true
4
- add_column :spree_shipping_rates, :max_delivery_time, :integer, if_not_exists: true
5
- end
6
- end