solidus_me 1.0.1 → 1.0.3

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: 36950d790364e7b63398fb6eafa4e6ffb8d31dc947340ed0114bcf6a49c81fca
4
- data.tar.gz: bf86fa63fee12d03d35d4964074ca16b61e0bfc827118894f14716ab6524bb0a
3
+ metadata.gz: 99922e6f7427808c33c7d153ac2003bd4542bbbdaceecfd35d18098894459258
4
+ data.tar.gz: 645f6bcb96aa4c92d31ce87d96e37ed84395c2f9657415b2c874ca338ec7f2d5
5
5
  SHA512:
6
- metadata.gz: f0bc720b9d98e6c8ac03c65a24d9dc7cbf0f8ea8080b8c033f28cd4fb1eff26c9a71a39933aa51c62a5acff6da073d86eabffe58436a395b979b9a5cefee344d
7
- data.tar.gz: df19fc08bd975d79617686938b16c1b3bcb75c67c04c2df37551ec9c2699d8b8196ab93b536725f31f35543dbe372a21465fdb395b14cb60147c63853c3f7d0a
6
+ metadata.gz: a87cffabde251c0cfc6319853b72e089bb98dd31e242506c14e9f6be41d95bff55bed304724ef03ae7d58ce8267faa4eff24c6c5f756d1192b8088397931bc31
7
+ data.tar.gz: 05ae50b4f505c42bd35c75bdd86a53be276eba2fb385abc8f71a488ea4c8ea4363abb4053a976f9286ca2abb2789cb066410779e3a92a13ff8aed935d9f4646b
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.to_h
40
+ end
39
41
  end
40
42
  end
41
43
  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.1'
4
+ VERSION = '1.0.3'
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.1
4
+ version: 1.0.3
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