solidus_tiny 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +7 -0
  2. data/.circleci/config.yml +53 -0
  3. data/.gem_release.yml +5 -0
  4. data/.github/stale.yml +1 -0
  5. data/.github_changelog_generator +2 -0
  6. data/.gitignore +21 -0
  7. data/.rspec +2 -0
  8. data/.rubocop.yml +5 -0
  9. data/CHANGELOG.md +3 -0
  10. data/Gemfile +48 -0
  11. data/LICENSE +26 -0
  12. data/README.md +73 -0
  13. data/Rakefile +7 -0
  14. data/app/controllers/spree/admin/orders/solidus_tiny/sellers_controller.rb +38 -0
  15. data/app/controllers/spree/admin/solidus_tiny/accounts_controller.rb +82 -0
  16. data/app/controllers/spree/admin/solidus_tiny/orders_controller.rb +20 -0
  17. data/app/jobs/solidus_tiny/application_job.rb +9 -0
  18. data/app/jobs/solidus_tiny/order_job.rb +10 -0
  19. data/app/jobs/solidus_tiny/upsert_sellers_job.rb +9 -0
  20. data/app/models/solidus_tiny/account.rb +8 -0
  21. data/app/models/solidus_tiny/event.rb +4 -0
  22. data/app/models/solidus_tiny/order.rb +129 -0
  23. data/app/models/solidus_tiny/payment_method.rb +4 -0
  24. data/app/models/solidus_tiny/seller.rb +44 -0
  25. data/app/models/solidus_tiny/shipping_method.rb +10 -0
  26. data/app/models/spree/permission_sets/tiny_seller_update.rb +9 -0
  27. data/app/subscribers/solidus_tiny/subscriber.rb +12 -0
  28. data/app/views/spree/admin/orders/solidus_tiny/sellers/edit.html.erb +19 -0
  29. data/app/views/spree/admin/shared/_order_submenu.html.erb +67 -0
  30. data/app/views/spree/admin/shared/_order_summary.html.erb +75 -0
  31. data/app/views/spree/admin/solidus_tiny/accounts/_form.html.erb +110 -0
  32. data/app/views/spree/admin/solidus_tiny/accounts/edit.html.erb +3 -0
  33. data/app/views/spree/admin/solidus_tiny/accounts/index.html.erb +54 -0
  34. data/app/views/spree/admin/solidus_tiny/accounts/new.html.erb +3 -0
  35. data/bin/console +17 -0
  36. data/bin/rails +7 -0
  37. data/bin/rails-engine +13 -0
  38. data/bin/rails-sandbox +16 -0
  39. data/bin/rake +7 -0
  40. data/bin/sandbox +76 -0
  41. data/bin/setup +8 -0
  42. data/config/locales/en.yml +5 -0
  43. data/config/locales/pt-BR.yml +5 -0
  44. data/config/routes.rb +17 -0
  45. data/db/migrate/20240506185512_create_solidus_tiny_accounts.rb +11 -0
  46. data/db/migrate/20240507111938_create_solidus_tiny_sellers.rb +15 -0
  47. data/db/migrate/20240507112822_add_solidus_tiny_seller_id_to_orders.rb +5 -0
  48. data/db/migrate/20240507114823_create_solidus_tiny_shipping_methods.rb +15 -0
  49. data/db/migrate/20240507121424_create_solidus_tiny_payment_methods.rb +13 -0
  50. data/db/migrate/20240507181649_add_tiny_order_id_to_spree_orders.rb +5 -0
  51. data/db/migrate/20240507190528_create_solidus_tiny_events.rb +13 -0
  52. data/lib/generators/solidus_tiny/install/install_generator.rb +31 -0
  53. data/lib/generators/solidus_tiny/install/templates/initializer.rb +4 -0
  54. data/lib/solidus_tiny/configuration.rb +18 -0
  55. data/lib/solidus_tiny/engine.rb +38 -0
  56. data/lib/solidus_tiny/testing_support/factories.rb +4 -0
  57. data/lib/solidus_tiny/version.rb +5 -0
  58. data/lib/solidus_tiny.rb +7 -0
  59. data/solidus_tiny.gemspec +36 -0
  60. metadata +182 -0
@@ -0,0 +1,19 @@
1
+ <%= render partial: 'spree/admin/shared/order_tabs', locals: { current: 'Vendedor' } %>
2
+
3
+ <% admin_breadcrumb("Vendedor") %>
4
+
5
+ <div data-order-number="<%= @order.number %>">
6
+ <div>
7
+ <fieldset class="no-border-bottom">
8
+ <legend>Vendedor</legend>
9
+ <%= form_with model: @order, url: admin_orders_solidus_tiny_update_seller_path(@order) do |form| %>
10
+ <%= form.select :seller_id, @sellers.pluck(:name, :id), { selected: @order.solidus_tiny_seller_id || @sellers.default&.id }, class:"custom-select fullwidth" %>
11
+ <div class="form-buttons filter-actions actions" data-hook="buttons">
12
+ <%= form.submit t('spree.actions.update'), class: 'btn btn-primary mt-4' %>
13
+ </div>
14
+ <% end %>
15
+ </fieldset>
16
+ </div>
17
+
18
+ <%= render partial: 'spree/shared/error_messages', locals: { target: @order } %>
19
+ </div>
@@ -0,0 +1,67 @@
1
+ <nav>
2
+ <ul class="tabs" data-hook="admin_order_tabs">
3
+ <% if (@order.shipments.count == 0 || @order.shipped_shipments.count == 0) %>
4
+ <li class="<%= "active" if current == "Cart" %>" data-hook='admin_order_tabs_order_details'>
5
+ <%= link_to t('spree.cart'), spree.cart_admin_order_url(@order) %>
6
+ </li>
7
+ <% end %>
8
+
9
+ <% if checkout_steps.include?("address") %>
10
+ <li class="<%= "active" if (current == "Customer Details") %>" data-hook='admin_order_tabs_customer_details'>
11
+ <% if can?(:update, @order) %>
12
+ <%= link_to t('spree.customer'), spree.edit_admin_order_customer_url(@order) %>
13
+ <% else %>
14
+ <%= link_to t('spree.customer'), spree.admin_order_customer_url(@order) %>
15
+ <% end %>
16
+ </li>
17
+ <% end %>
18
+
19
+ <li class="<%= "active" if current == "Vendedor" %>" data-hook='admin_order_tabs_order_details'>
20
+ <%= link_to "Vendedor", admin_orders_solidus_tiny_seller_path(@order) %>
21
+ </li>
22
+
23
+ <li class="<%= "active" if current == "Shipments" %>" data-hook='admin_order_tabs_order_details'>
24
+ <%= link_to plural_resource_name(Spree::Shipment), spree.edit_admin_order_url(@order) %>
25
+ </li>
26
+
27
+ <% if can? :show, Spree::Adjustment %>
28
+ <li class="<%= "active" if current == "Adjustments" %>" data-hook='admin_order_tabs_adjustments'>
29
+ <%= link_to plural_resource_name(Spree::Adjustment), spree.admin_order_adjustments_url(@order) %>
30
+ </li>
31
+ <% end %>
32
+
33
+ <% if can?(:show, Spree::Payment) %>
34
+ <li class="<%= "active" if current == "Payments" %>" data-hook='admin_order_tabs_payments'>
35
+ <%= link_to plural_resource_name(Spree::Payment), spree.admin_order_payments_url(@order) %>
36
+ </li>
37
+ <% end %>
38
+
39
+ <% if !@order.completed? && can?(:update, @order) %>
40
+ <li class="<%= "active" if current == "Confirm" %>" data-hook='admin_order_tabs_confirm'>
41
+ <%= link_to t('spree.confirm'), spree.confirm_admin_order_url(@order) %>
42
+ </li>
43
+ <% end %>
44
+
45
+ <% if can? :show, Spree::ReturnAuthorization %>
46
+ <% if @order.completed? %>
47
+ <li class="tab <%= "active" if current == "Return Authorizations" %>" data-hook='admin_order_tabs_return_authorizations'>
48
+ <%= link_to t('spree.admin.tab.rma'), spree.admin_order_return_authorizations_url(@order) %>
49
+ </li>
50
+ <% end %>
51
+ <% end %>
52
+
53
+ <% if can? :show, Spree::CustomerReturn %>
54
+ <% if @order.completed? %>
55
+ <li class="<%= "active" if current == "Customer Returns" %>" data-hook='admin_order_tabs_customer_returns'>
56
+ <%= link_to plural_resource_name(Spree::CustomerReturn), spree.admin_order_customer_returns_url(@order) %>
57
+ </li>
58
+ <% end %>
59
+ <% end %>
60
+
61
+ <% if can?(:manage, Spree::OrderCancellations) && @order.inventory_units.cancelable.present? %>
62
+ <li class="<%= "active" if current == "Cancel Inventory" %>" data-hook='admin_order_tabs_cancel_inventory'>
63
+ <%= link_to t('spree.cancel_inventory'), spree.admin_order_cancellations_path(@order) %>
64
+ </li>
65
+ <% end %>
66
+ </ul>
67
+ </nav>
@@ -0,0 +1,75 @@
1
+
2
+ <header id="order_tab_summary" data-hook>
3
+ <dl class="additional-info">
4
+ <dt class="order-state" id="order_status" data-hook><%= t('spree.status') %>:</dt>
5
+ <dd class="order-state">
6
+ <span class="pill pill-<%= @order.state %>">
7
+ <%= t(@order.state, scope: 'spree.order_state') %>
8
+ </span>
9
+
10
+ <% if @order.user.present? %>
11
+ <dt data-hook='admin_order_user_link'><%= t('spree.user') %>:</dt>
12
+ <dd id='order_user_link'><%= link_to @order.user.email, spree.edit_admin_user_path(@order.user) %></dd>
13
+ <% end %>
14
+
15
+ <dt data-hook='admin_order_tab_subtotal_title'><%= Spree::Order.human_attribute_name(:item_total) %>:</dt>
16
+ <dd id='item_total'><%= @order.display_item_total.to_html %></dd>
17
+
18
+ <% if checkout_steps.include?("delivery") %>
19
+ <dt class="order-shipment_total <%= "hidden" if @order.ship_total.zero? %>" data-hook='admin_order_tab_ship_total_title'><%= Spree::Order.human_attribute_name(:shipment_total) %>:</dt>
20
+ <dd class="order-shipment_total <%= "hidden" if @order.ship_total.zero? %>" id='ship_total'><%= @order.display_ship_total.to_html %></dd>
21
+ <% end %>
22
+
23
+ <dt class="order-included_tax_total <%= "hidden" if @order.included_tax_total.zero? %>" data-hook='admin_order_tab_included_tax_title'><%= Spree::Order.human_attribute_name(:included_tax_total) %>:</dt>
24
+ <dd class="order-included_tax_total <%= "hidden" if @order.included_tax_total.zero? %>" id='included_tax_total'><%= @order.display_included_tax_total.to_html %></dd>
25
+
26
+ <dt class="order-additional_tax_total <%= "hidden" if @order.additional_tax_total.zero? %>" data-hook='admin_order_tab_additional_tax_title'><%= Spree::Order.human_attribute_name(:additional_tax_total) %>:</dt>
27
+ <dd class="order-additional_tax_total <%= "hidden" if @order.additional_tax_total.zero? %>" id='additional_tax_total'><%= @order.display_additional_tax_total.to_html %></dd>
28
+
29
+ <dt data-hook='admin_order_tab_total_title'><%= Spree::Order.human_attribute_name(:total) %>:</dt>
30
+ <dd id='order_total'><%= @order.display_total.to_html %></dd>
31
+
32
+ <% if @order.shipment_state %>
33
+ <dt class="order-shipment_state"><%= Spree::Shipment.model_name.human %>: </dt>
34
+ <dd class="order-shipment_state" id='shipment_status'>
35
+ <span class="pill pill-<%= @order.shipment_state %>">
36
+ <%= t(@order.shipment_state, scope: 'spree.shipment_states') %>
37
+ </span>
38
+ </dd>
39
+ <% end %>
40
+
41
+ <% if @order.payment_state %>
42
+ <dt class="order-payment_state"><%= Spree::Payment.model_name.human %>: </dt>
43
+ <dd class="order-payment_state" id='payment_status'>
44
+ <span class="pill pill-<%= @order.payment_state %>">
45
+ <%= t(@order.payment_state, scope: 'spree.payment_states') %>
46
+ </span>
47
+ </dd>
48
+ <% end %>
49
+
50
+ <% if @order.completed? %>
51
+ <dt data-hook='admin_order_tab_date_completed_title'><%= Spree::Order.human_attribute_name(:completed_at) %>:</dt>
52
+ <dd id='date_complete'><%= pretty_time(@order.completed_at) %></dd>
53
+ <% end %>
54
+
55
+ <% if @order.approved? %>
56
+ <dt><%= Spree::Order.human_attribute_name(:approver) %></dt>
57
+ <dd><%= @order.approver.try(:email) || @order.approver_name %></dd>
58
+ <dt><%= Spree::Order.human_attribute_name(:approved_at) %></dt>
59
+ <dd><%= pretty_time(@order.approved_at) %></dd>
60
+ <% end %>
61
+
62
+ <% if @order.canceled? && @order.canceler && @order.canceled_at %>
63
+ <dt><%= Spree::Order.human_attribute_name(:canceler) %></dt>
64
+ <dd><%= @order.canceler.email %></dd>
65
+ <dt><%= Spree::Order.human_attribute_name(:canceled_at) %></dt>
66
+ <dd><%= pretty_time(@order.canceled_at) %></dd>
67
+ <% end %>
68
+
69
+ <% if @order.solidus_tiny_seller_id %>
70
+ <dt data-hook='admin_order_tab_seller_title'>Vendedor:</dt>
71
+ <dd id='seller'><%= ::SolidusTiny::Seller.find_by(id: @order.solidus_tiny_seller_id).name %></dd>
72
+ <% end %>
73
+ </dl>
74
+
75
+ </header>
@@ -0,0 +1,110 @@
1
+ <%= form_with model: tiny_account, url: form_url do |form| %>
2
+ <fieldset class="no-border-top">
3
+ <legend>
4
+ Dados da Conta
5
+ </legend>
6
+ <div class="row">
7
+ <div class="col-12">
8
+ <%= form.field_container :api_key do %>
9
+ <%= form.label :api_key, "API Key", class: 'required' %>
10
+ <%= form.text_field :api_key, required: true, class: 'fullwidth' %>
11
+ <%= form.error_message_on :api_key %>
12
+ <% end %>
13
+ </div>
14
+ <div class="col-md-6 col-12">
15
+ <%= form.field_container :stock_location do %>
16
+ <%= form.label :stock_location, "Depósito", class: 'required' %>
17
+ <%= form.text_field :stock_location, required: true, class: 'fullwidth' %>
18
+ <%= form.error_message_on :stock_location %>
19
+ <% end %>
20
+ </div>
21
+ <div class="col-md-6 col-12">
22
+ <%= form.field_container :operation_id do %>
23
+ <%= form.label :operation_id, "ID Natureza de Operação", class: 'required' %>
24
+ <%= form.text_field :operation_id, required: true, class: 'fullwidth' %>
25
+ <%= form.error_message_on :operation_id %>
26
+ <% end %>
27
+ </div>
28
+ </div>
29
+ </fieldset>
30
+
31
+ <fieldset id="payment_methods" class="no-border-top">
32
+ <legend>
33
+ Métodos de Pagamento
34
+ </legend>
35
+ <%= form.fields_for :payment_methods do |payment_form| %>
36
+ <div class="row">
37
+ <div class="col-12 col-md-6">
38
+ <div class="field">
39
+ <%= payment_form.label :spree_payment_method_id, "Método de Pagamento", class: 'required' %>
40
+ <%= payment_form.select :spree_payment_method_id, @payment_methods, {}, { class: "custom-select fullwidth" } %>
41
+ </div>
42
+ </div>
43
+ <div class="col-12 col-md-6">
44
+ <div class="field">
45
+ <%= payment_form.label :alias, "Nome da Forma de Pagamento", class: 'required' %>
46
+ <%= payment_form.text_field :alias, required: true, class:"fullwidth" %>
47
+ </div>
48
+ </div>
49
+ </div>
50
+ <% end %>
51
+ </fieldset>
52
+
53
+ <fieldset class="no-border-top">
54
+ <legend>
55
+ Métodos de Envio
56
+ </legend>
57
+ <%= form.fields_for :shipping_methods do |ship_form| %>
58
+ <div class="row">
59
+ <div class="col-12 col-md-3">
60
+ <div class="field">
61
+ <%= ship_form.label :spree_shipping_method_id, "Método de Envio", class: 'required' %>
62
+ <%= ship_form.select :spree_shipping_method_id, @shipping_methods, {}, { class: "custom-select fullwidth" } %>
63
+ </div>
64
+ </div>
65
+ <div class="col-12 col-md-3">
66
+ <div class="field">
67
+ <%= ship_form.label :name, "Nome da Logística", class: 'required' %>
68
+ <%= ship_form.text_field :name, required: true, class:"fullwidth" %>
69
+ </div>
70
+ </div>
71
+ <div class="col-12 col-md-3">
72
+ <div class="field">
73
+ <%= ship_form.label :service, "Serviço", class: 'required' %>
74
+ <%= ship_form.text_field :service, required: true, class:"fullwidth" %>
75
+ </div>
76
+ </div>
77
+ <div class="col-12 col-md-3">
78
+ <div class="field">
79
+ <%= ship_form.label :company, "Nome Transportadora", class: 'required' %>
80
+ <%= ship_form.text_field :company, required: true, class:"fullwidth" %>
81
+ </div>
82
+ </div>
83
+ </div>
84
+ <% end %>
85
+ </fieldset>
86
+
87
+ <% if @sellers %>
88
+ <fieldset class="no-border-top text-center">
89
+ <legend>
90
+ Vendedor padrão
91
+ </legend>
92
+ <div class="field">
93
+ <%= form.label "default_seller[id]", "Vendedor Padrão", class: '' %>
94
+ <%= form.select "default_seller[id]", @sellers, {selected: ::SolidusTiny::Seller.default&.id, include_blank: true }, { class: "custom-select fullwidth" } %>
95
+ </div>
96
+ </fieldset>
97
+ <% end %>
98
+
99
+ <div class="form-buttons filter-actions actions" data-hook="buttons">
100
+ <%= form.submit "Salvar", class: 'btn btn-primary' %>
101
+ <% if params["action"] == 'edit' %>
102
+ <%= link_to "Excluir", admin_solidus_tiny_account_path(tiny_account.id), method: :delete, data: { confirm: "Tem certeza que deseja excluir a conta?"}, class: 'button' %>
103
+ <% end %>
104
+ </div>
105
+ <% end %>
106
+
107
+
108
+ <script>
109
+
110
+ </script>
@@ -0,0 +1,3 @@
1
+ <% admin_breadcrumb("Tiny") %>
2
+
3
+ <%= render "form", tiny_account: @tiny_account, form_url: admin_solidus_tiny_account_path(@tiny_account.id) %>
@@ -0,0 +1,54 @@
1
+
2
+ <% admin_layout "full-width" %>
3
+
4
+ <% admin_breadcrumb("Tiny") %>
5
+
6
+ <% content_for :page_actions do %>
7
+ <% if SolidusTiny::Account.count < 1 %>
8
+ <li>
9
+ <%= link_to "Nova Conta", new_admin_solidus_tiny_account_path, class: 'btn btn-primary' %>
10
+ </li>
11
+ <% end %>
12
+ <% end %>
13
+
14
+ <div class="content-wrapper">
15
+ <% @accounts.each do |account| %>
16
+
17
+ <fieldset class="no-border-top">
18
+ <legend>
19
+ Dados da Conta
20
+ </legend>
21
+ <div class="row">
22
+
23
+ <div class="col-12">
24
+ <div class="field">
25
+ <%= label_tag :api_key, "API Key" %>
26
+ <%= text_field_tag :api_key, account.api_key, class:"fullwidth", disabled: true %>
27
+ </div>
28
+ </div>
29
+ <div class="col-md-6 col-12">
30
+ <div class="field">
31
+ <%= label_tag :stock_location, "Depósito" %>
32
+ <%= text_field_tag :stock_location, account.stock_location, class:"fullwidth", disabled: true %>
33
+ </div>
34
+ </div>
35
+ <div class="col-md-6 col-12">
36
+ <div class="field">
37
+ <%= label_tag :operation_id, "ID Natureza de Operação" %>
38
+ <%= text_field_tag :operation_id, account.operation_id, class:"fullwidth", disabled: true %>
39
+ </div>
40
+ </div>
41
+
42
+ </div>
43
+ <div class="field">
44
+ <%= button_to "Atualizar vendedores", upsert_sellers_admin_solidus_tiny_accounts_path %>
45
+ </div>
46
+ </fieldset>
47
+
48
+ <div class="form-buttons filter-actions actions" data-hook="buttons">
49
+ <%= link_to "Editar", edit_admin_solidus_tiny_account_path(account.id), class: 'btn btn-primary' %>
50
+ <%= link_to "Excluir", admin_solidus_tiny_account_path(account.id), method: :delete, data: { confirm: "Tem certeza que deseja excluir a conta?"}, class: 'button' %>
51
+ </div>
52
+ <% end %>
53
+ </div>
54
+
@@ -0,0 +1,3 @@
1
+ <% admin_breadcrumb("Conta Tiny") %>
2
+
3
+ <%= render "form", tiny_account: @tiny_account, form_url: admin_solidus_tiny_accounts_path %>
data/bin/console ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # frozen_string_literal: true
4
+
5
+ require "bundler/setup"
6
+ require "solidus_tiny"
7
+
8
+ # You can add fixtures and/or initialization code here to make experimenting
9
+ # with your gem easier. You can also use a different console, if you like.
10
+ $LOAD_PATH.unshift(*Dir["#{__dir__}/../app/*"])
11
+
12
+ # (If you use this, don't forget to add pry to your Gemfile!)
13
+ # require "pry"
14
+ # Pry.start
15
+
16
+ require "irb"
17
+ IRB.start(__FILE__)
data/bin/rails ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ if %w[g generate].include? ARGV.first
4
+ exec "#{__dir__}/rails-engine", *ARGV
5
+ else
6
+ exec "#{__dir__}/rails-sandbox", *ARGV
7
+ end
data/bin/rails-engine ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails gems
3
+ # installed from the root of your application.
4
+
5
+ ENGINE_ROOT = File.expand_path('..', __dir__)
6
+ ENGINE_PATH = File.expand_path('../lib/solidus_tiny/engine', __dir__)
7
+
8
+ # Set up gems listed in the Gemfile.
9
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
10
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
11
+
12
+ require 'rails/all'
13
+ require 'rails/engine/commands'
data/bin/rails-sandbox ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ app_root = 'sandbox'
4
+
5
+ unless File.exist? "#{app_root}/bin/rails"
6
+ warn 'Creating the sandbox app...'
7
+ Dir.chdir "#{__dir__}/.." do
8
+ system "#{__dir__}/sandbox" or begin
9
+ warn 'Automatic creation of the sandbox app failed'
10
+ exit 1
11
+ end
12
+ end
13
+ end
14
+
15
+ Dir.chdir app_root
16
+ exec 'bin/rails', *ARGV
data/bin/rake ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "rubygems"
5
+ require "bundler/setup"
6
+
7
+ load Gem.bin_path("rake", "rake")
data/bin/sandbox ADDED
@@ -0,0 +1,76 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -e
4
+ test -z "${DEBUG+empty_string}" || set -x
5
+
6
+ test "$DB" = "sqlite" && export DB="sqlite3"
7
+
8
+ if [ -z "$PAYMENT_METHOD" ]
9
+ then
10
+ PAYMENT_METHOD="none"
11
+ fi
12
+
13
+ if [ -z "$SOLIDUS_BRANCH" ]
14
+ then
15
+ echo "~~> Use 'export SOLIDUS_BRANCH=[main|v4.0|...]' to control the Solidus branch"
16
+ SOLIDUS_BRANCH="main"
17
+ fi
18
+ echo "~~> Using branch $SOLIDUS_BRANCH of solidus"
19
+
20
+ extension_name="solidus_tiny"
21
+
22
+ # Stay away from the bundler env of the containing extension.
23
+ function unbundled {
24
+ ruby -rbundler -e'
25
+ Bundler.with_unbundled_env {system *ARGV}' -- \
26
+ env BUNDLE_SUPPRESS_INSTALL_USING_MESSAGES=true $@
27
+ }
28
+
29
+ echo "~~~> Removing the old sandbox"
30
+ rm -rf ./sandbox
31
+
32
+ echo "~~~> Creating a pristine Rails app"
33
+ rails new sandbox \
34
+ --database="${DB:-sqlite3}" \
35
+ --skip-git \
36
+ --skip-keeps \
37
+ --skip-rc \
38
+ --skip-bootsnap \
39
+ --skip-test
40
+
41
+ if [ ! -d "sandbox" ]; then
42
+ echo 'sandbox rails application failed'
43
+ exit 1
44
+ fi
45
+
46
+ echo "~~~> Adding solidus (with i18n) to the Gemfile"
47
+ cd ./sandbox
48
+ cat <<RUBY >> Gemfile
49
+ gem 'solidus', github: 'solidusio/solidus', branch: '$SOLIDUS_BRANCH'
50
+ gem 'rails-i18n'
51
+ gem 'solidus_i18n'
52
+ gem 'solidus_auth_devise'
53
+
54
+ gem '$extension_name', path: '..'
55
+
56
+ group :test, :development do
57
+ platforms :mri do
58
+ gem 'pry-byebug'
59
+ end
60
+ end
61
+ RUBY
62
+
63
+ unbundled bundle install --gemfile Gemfile
64
+
65
+ unbundled bundle exec rake db:drop db:create
66
+
67
+ unbundled bundle exec rails generate solidus:install \
68
+ --auto-accept \
69
+ $@
70
+
71
+ unbundled bundle exec rails generate solidus:auth:install --auto-run-migrations
72
+ unbundled bundle exec rails generate ${extension_name}:install --auto-run-migrations
73
+
74
+ echo
75
+ echo "🚀 Sandbox app successfully created for $extension_name!"
76
+ echo "🧪 This app is intended for test purposes."
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ gem install bundler --conservative
7
+ bundle update
8
+ bin/rake clobber
@@ -0,0 +1,5 @@
1
+ # Sample localization file for English. Add more files in this directory for other locales.
2
+ # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
+
4
+ en:
5
+ hello: Hello world
@@ -0,0 +1,5 @@
1
+ pt-BR:
2
+ spree:
3
+ admin:
4
+ tab:
5
+ tiny_account: "Tiny"
data/config/routes.rb ADDED
@@ -0,0 +1,17 @@
1
+ Spree::Core::Engine.routes.draw do
2
+ namespace :admin do
3
+ namespace :orders do
4
+ namespace :solidus_tiny do
5
+ get "/:order_number/sellers", controller: "sellers", action: "edit", as: :seller
6
+ patch "/:order_number/sellers", controller: "sellers", action: "update", as: :update_seller
7
+ end
8
+ end
9
+
10
+ namespace :solidus_tiny do
11
+ resources :accounts do
12
+ post "upsert_sellers", on: :collection
13
+ end
14
+ resources :orders, only: [:update]
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ class CreateSolidusTinyAccounts < ActiveRecord::Migration[7.0]
2
+ def change
3
+ create_table :solidus_tiny_accounts do |t|
4
+ t.string :api_key
5
+ t.string :stock_location
6
+ t.string :operation_id
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ class CreateSolidusTinySellers < ActiveRecord::Migration[7.0]
2
+ def change
3
+ create_table :solidus_tiny_sellers do |t|
4
+ t.string :name
5
+ t.string :external_id
6
+ t.integer :account_id, null: false, index: true
7
+ t.boolean :default, default: false
8
+ t.boolean :active, default: true
9
+
10
+ t.timestamps
11
+ end
12
+
13
+ add_index :solidus_tiny_sellers, :external_id, unique: true
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ class AddSolidusTinySellerIdToOrders < ActiveRecord::Migration[7.0]
2
+ def change
3
+ add_reference :spree_orders, :solidus_tiny_seller, foreign_key: true
4
+ end
5
+ end
@@ -0,0 +1,15 @@
1
+ class CreateSolidusTinyShippingMethods < ActiveRecord::Migration[7.0]
2
+ def change
3
+ create_table :solidus_tiny_shipping_methods do |t|
4
+ t.string :name
5
+ t.string :service
6
+ t.string :company
7
+ t.integer :account_id, null: false, index: { name: "solidus_tiny_shipping_account_index" }
8
+ t.integer :spree_shipping_method_id, null: false, index: { name: "solidus_tiny_spree_shipping_index" }
9
+
10
+ t.timestamps
11
+
12
+ t.foreign_key :spree_shipping_methods, column: :spree_shipping_method_id
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ class CreateSolidusTinyPaymentMethods < ActiveRecord::Migration[7.0]
2
+ def change
3
+ create_table :solidus_tiny_payment_methods do |t|
4
+ t.string :alias
5
+ t.integer :account_id, null: false, index: true
6
+ t.integer :spree_payment_method_id, null: false, index: true
7
+
8
+ t.timestamps
9
+
10
+ t.foreign_key :spree_payment_methods, column: :spree_payment_method_id
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ class AddTinyOrderIdToSpreeOrders < ActiveRecord::Migration[7.0]
2
+ def change
3
+ add_column :spree_orders, :tiny_order_id, :string, default: nil, if_not_exists: true
4
+ end
5
+ end
@@ -0,0 +1,13 @@
1
+ class CreateSolidusTinyEvents < ActiveRecord::Migration[7.0]
2
+ def change
3
+ create_table :solidus_tiny_events do |t|
4
+ t.string :internal_id
5
+ t.string :status
6
+ t.string :message
7
+ t.string :body
8
+ t.string :event
9
+
10
+ t.timestamps
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SolidusTiny
4
+ module Generators
5
+ class InstallGenerator < Rails::Generators::Base
6
+ class_option :auto_run_migrations, type: :boolean, default: false
7
+ source_root File.expand_path('templates', __dir__)
8
+
9
+ def self.exit_on_failure?
10
+ true
11
+ end
12
+
13
+ def copy_initializer
14
+ template 'initializer.rb', 'config/initializers/solidus_tiny.rb'
15
+ end
16
+
17
+ def add_migrations
18
+ run 'bin/rails railties:install:migrations FROM=solidus_tiny'
19
+ end
20
+
21
+ def run_migrations
22
+ run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]')) # rubocop:disable Layout/LineLength
23
+ if run_migrations
24
+ run 'bin/rails db:migrate'
25
+ else
26
+ puts 'Skipping bin/rails db:migrate, don\'t forget to run it!' # rubocop:disable Rails/Output
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ SolidusTiny.configure do |config|
4
+ end