solidus_bling 1.0.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/spree/admin/accounts_controller.rb +54 -0
- data/app/helpers/solidus_bling/accounts_helper.rb +4 -0
- data/app/jobs/solidus_bling/application_job.rb +9 -0
- data/app/jobs/solidus_bling/contact_job.rb +22 -0
- data/app/jobs/solidus_bling/order_job.rb +22 -0
- data/app/jobs/solidus_bling/product_job.rb +13 -0
- data/app/models/solidus_bling/account.rb +9 -0
- data/app/models/{bling → solidus_bling}/api.rb +5 -5
- data/app/models/{bling/contato.rb → solidus_bling/contact.rb} +12 -12
- data/app/models/solidus_bling/event.rb +4 -0
- data/app/models/{bling/pedido.rb → solidus_bling/order.rb} +13 -18
- data/app/models/solidus_bling/payment_method.rb +5 -0
- data/app/models/{bling/produto.rb → solidus_bling/product.rb} +11 -8
- data/app/models/solidus_bling/seller.rb +5 -0
- data/app/models/solidus_bling/shipping_method.rb +5 -0
- data/app/subscribers/solidus_bling/subscriber.rb +32 -0
- data/app/views/spree/admin/accounts/_form.html.erb +68 -0
- data/app/views/spree/admin/accounts/edit.html.erb +2 -0
- data/app/views/spree/admin/accounts/index.html.erb +13 -0
- data/app/views/spree/admin/accounts/new.html.erb +2 -0
- data/app/views/spree/admin/accounts/show.html.erb +8 -0
- data/config/routes.rb +3 -1
- data/db/migrate/{20230906141624_create_erp_accounts.rb → 20230918141419_create_solidus_bling_accounts.rb} +4 -2
- data/db/migrate/20230918141505_add_bling_order_id_to_spree_orders.rb +5 -0
- data/db/migrate/{20230906142108_create_erp_products.rb → 20230918141700_create_solidus_bling_products.rb} +3 -3
- data/db/migrate/{20230906142806_create_erp_events.rb → 20230918142547_create_solidus_bling_events.rb} +2 -2
- data/db/migrate/20230918142742_create_solidus_bling_payment_methods.rb +13 -0
- data/db/migrate/20230918142953_create_solidus_bling_sellers.rb +11 -0
- data/db/migrate/20230918143057_create_solidus_bling_shipping_methods.rb +13 -0
- data/lib/generators/solidus_bling/install/templates/initializer.rb +0 -5
- data/lib/solidus_bling/configuration.rb +3 -1
- data/lib/solidus_bling/engine.rb +17 -4
- data/lib/solidus_bling/version.rb +1 -1
- data/lib/solidus_bling.rb +1 -0
- data/solidus_bling.gemspec +7 -0
- data/spec/helpers/solidus_bling/accounts_helper_spec.rb +17 -0
- data/spec/jobs/solidus_bling/contact_job_spec.rb +7 -0
- data/spec/jobs/solidus_bling/order_job_spec.rb +7 -0
- data/spec/jobs/solidus_bling/product_job_spec.rb +7 -0
- data/spec/models/solidus_bling/account_spec.rb +7 -0
- data/spec/models/solidus_bling/event_spec.rb +7 -0
- data/spec/models/solidus_bling/payment_method_spec.rb +7 -0
- data/spec/models/solidus_bling/product_spec.rb +7 -0
- data/spec/models/solidus_bling/seller_spec.rb +7 -0
- data/spec/models/solidus_bling/shipping_method_spec.rb +7 -0
- data/spec/requests/solidus_bling/accounts_spec.rb +7 -0
- metadata +72 -35
- data/app/jobs/application_job.rb +0 -7
- data/app/jobs/erp_contact_job.rb +0 -20
- data/app/jobs/erp_order_job.rb +0 -21
- data/app/jobs/erp_product_job.rb +0 -12
- data/app/models/erp_account.rb +0 -3
- data/app/models/erp_event.rb +0 -2
- data/app/models/erp_product.rb +0 -3
- data/app/subscribers/bling/subscriber.rb +0 -32
- data/config/initializers/solidus_bling.rb +0 -11
- data/db/migrate/20230906141728_add_erp_id_to_spree_orders.rb +0 -5
- data/spec/jobs/erp_contact_job_spec.rb +0 -5
- data/spec/jobs/erp_order_job_spec.rb +0 -5
- data/spec/jobs/erp_product_job_spec.rb +0 -5
- data/spec/models/erp_account_spec.rb +0 -5
- data/spec/models/erp_event_spec.rb +0 -5
- data/spec/models/erp_product_spec.rb +0 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 81e47bc81b103b82f681395e85e63674a0950316711770d0bbe6ca6f854eef01
|
|
4
|
+
data.tar.gz: 3983f4e929e14af2409202589016c7bb330376a2e38e0d1a33e02fcfa5620583
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 885bd2077efb3f7dc2d0b0cad3ba18e92f136c82608da254e35de9b6867ce235a587d11dfdee02d88ff086fff0e96ab19f5acf58c587ce6579b432fde861eb0b
|
|
7
|
+
data.tar.gz: 754480ad38bc954d93577623a3aaee813dead59ee10aede1afed9a5aa48c425b675f62d03a04eb934459eb5e62cb238cb78cd71ea548c88b9c2854318f023a96
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
module Admin
|
|
3
|
+
class AccountsController < ResourceController
|
|
4
|
+
def index
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def show
|
|
8
|
+
@bling_account = SolidusBling::Account.find(params[:id])
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def new
|
|
12
|
+
@bling_account = SolidusBling::Account.new
|
|
13
|
+
@payment_methods = Spree::PaymentMethod.all.pluck(:name, :id)
|
|
14
|
+
@shipping_methods = Spree::ShippingMethod.all.pluck(:name, :id)
|
|
15
|
+
@bling_account.payment_methods.build
|
|
16
|
+
@bling_account.shipping_methods.build
|
|
17
|
+
@bling_account.sellers.build
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def create
|
|
21
|
+
bling_account = SolidusBling::Account.create account_params.merge(name: "Bling")
|
|
22
|
+
redirect_to admin_accounts_path
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def edit
|
|
26
|
+
@bling_account = SolidusBling::Account.find(params[:id])
|
|
27
|
+
@payment_methods = Spree::PaymentMethod.all.pluck(:name, :id)
|
|
28
|
+
@shipping_methods = Spree::ShippingMethod.all.pluck(:name, :id)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def update
|
|
32
|
+
bling_account = SolidusBling::Account.find(params[:id])
|
|
33
|
+
bling_account.update account_params
|
|
34
|
+
redirect_to edit_admin_account_path(bling_account.id)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def delete
|
|
38
|
+
bling_account = SolidusBling::Account.find(params[:id])
|
|
39
|
+
bling_account.delete
|
|
40
|
+
redirect_to admin_accounts_path
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
private
|
|
44
|
+
|
|
45
|
+
def model_class
|
|
46
|
+
SolidusBling::Account
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def account_params
|
|
50
|
+
params.require(:account).permit(:app_name, :client_id, :client_secret, :refresh_token, :api_base_url, :external_store_id, :incoming_category_id, payment_methods_attributes: [:id, :spree_payment_method_id, :external_id], shipping_methods_attributes: [:id, :spree_shipping_method_id, :alias], sellers_attributes: [:id, :name, :external_id])
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
module SolidusBling
|
|
2
|
+
class ApplicationJob < ActiveJob::Base
|
|
3
|
+
# Automatically retry jobs that encountered a deadlock
|
|
4
|
+
# retry_on ActiveRecord::Deadlocked
|
|
5
|
+
|
|
6
|
+
# Most jobs are safe to ignore if the underlying records are no longer available
|
|
7
|
+
# discard_on ActiveJob::DeserializationError
|
|
8
|
+
end
|
|
9
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module SolidusBling
|
|
2
|
+
class ContactJob < ApplicationJob
|
|
3
|
+
queue_as :default
|
|
4
|
+
|
|
5
|
+
def perform event:, method_name:
|
|
6
|
+
bling_event = SolidusBling::Event.new
|
|
7
|
+
contact = event[:args][:contato]
|
|
8
|
+
order = event[:args][:order]
|
|
9
|
+
bling_event.internal_id = order.id
|
|
10
|
+
bling_event.name = "event.omnes_event_name"
|
|
11
|
+
bling_event.method = method_name
|
|
12
|
+
if contact.include? "error"
|
|
13
|
+
bling_event.status = 'error'
|
|
14
|
+
bling_event.message = contact["error"]["description"]
|
|
15
|
+
else
|
|
16
|
+
bling_event.status = 'success'
|
|
17
|
+
end
|
|
18
|
+
bling_event.body = order.to_json
|
|
19
|
+
bling_event.save!
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module SolidusBling
|
|
2
|
+
class OrderJob < ApplicationJob
|
|
3
|
+
queue_as :default
|
|
4
|
+
|
|
5
|
+
def perform event:, method_name:
|
|
6
|
+
bling_event = SolidusBling::Event.new
|
|
7
|
+
order = event[:order]
|
|
8
|
+
bling_event.internal_id = order.id
|
|
9
|
+
bling_event.method = method_name
|
|
10
|
+
begin
|
|
11
|
+
SolidusBling::Order.new(order).send
|
|
12
|
+
bling_event.status = 'success'
|
|
13
|
+
rescue => e
|
|
14
|
+
bling_event.status = 'error'
|
|
15
|
+
bling_event.message = e.to_json
|
|
16
|
+
ensure
|
|
17
|
+
bling_event.body = order.to_json
|
|
18
|
+
bling_event.save!
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module SolidusBling
|
|
2
|
+
class ProductJob < ApplicationJob
|
|
3
|
+
queue_as :default
|
|
4
|
+
|
|
5
|
+
def perform event:, method_name:
|
|
6
|
+
bling_event = SolidusBling::Event.new
|
|
7
|
+
products = event[:products]
|
|
8
|
+
bling_event.method = method_name
|
|
9
|
+
bling_event.body = products.to_json
|
|
10
|
+
bling_event.save!
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
module
|
|
1
|
+
module SolidusBling
|
|
2
2
|
class Api
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
@account =
|
|
4
|
+
attr_reader :account, :headers
|
|
5
|
+
def initialize account
|
|
6
|
+
@account = account
|
|
7
7
|
verify_token
|
|
8
8
|
@headers = {
|
|
9
9
|
"Content-Type": "application/json",
|
|
@@ -48,7 +48,7 @@ module Bling
|
|
|
48
48
|
private
|
|
49
49
|
|
|
50
50
|
def find_account app_name
|
|
51
|
-
account =
|
|
51
|
+
account = SolidusBling::Account.find_by(app_name: app_name)
|
|
52
52
|
raise 'Conta de aplicativo inexistente' if account.nil?
|
|
53
53
|
account
|
|
54
54
|
end
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
module
|
|
2
|
-
class
|
|
1
|
+
module SolidusBling
|
|
2
|
+
class Contact < SolidusBling::Api
|
|
3
3
|
|
|
4
4
|
attr_reader :info
|
|
5
5
|
|
|
6
|
-
def initialize order
|
|
7
|
-
super()
|
|
6
|
+
def initialize order, account
|
|
7
|
+
super(account)
|
|
8
8
|
@info = find_or_create(order)
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
def find_or_create order
|
|
12
|
-
raise "Order com CPF/CNPJ vazio" if order.
|
|
13
|
-
contato = find_by_cpf(order.
|
|
12
|
+
raise "Order com CPF/CNPJ vazio" if order.tax_id.nil?
|
|
13
|
+
contato = find_by_cpf(order.tax_id)
|
|
14
14
|
if contato.nil?
|
|
15
15
|
contato_external_id = create(order)
|
|
16
16
|
contato = {"id" => contato_external_id}
|
|
@@ -18,8 +18,8 @@ module Bling
|
|
|
18
18
|
contato
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
-
def find_by_cpf
|
|
22
|
-
req = Typhoeus.get("#{@account.api_base_url}/contatos?numeroDocumento=#{
|
|
21
|
+
def find_by_cpf tax_id
|
|
22
|
+
req = Typhoeus.get("#{@account.api_base_url}/contatos?numeroDocumento=#{tax_id.gsub(/\D/, "")}", headers: @headers)
|
|
23
23
|
json = JSON.parse(req.body)
|
|
24
24
|
response_has_error?(json)
|
|
25
25
|
user = {}
|
|
@@ -39,7 +39,7 @@ module Bling
|
|
|
39
39
|
ensure
|
|
40
40
|
json = JSON.parse(req.body)
|
|
41
41
|
response_has_error?(json)
|
|
42
|
-
Spree::Bus.publish :
|
|
42
|
+
Spree::Bus.publish :bling_contact_created, args: {order: order, contato: json}
|
|
43
43
|
return json.dig("data", "id")
|
|
44
44
|
end
|
|
45
45
|
end
|
|
@@ -47,15 +47,15 @@ module Bling
|
|
|
47
47
|
private
|
|
48
48
|
|
|
49
49
|
def tipo_pessoa doc
|
|
50
|
-
doc.length > 11 ? "J" : "F"
|
|
50
|
+
doc.gsub(/\D/, "").length > 11 ? "J" : "F"
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
def build_hash_contato order
|
|
54
54
|
{
|
|
55
55
|
"nome": order.ship_address.name,
|
|
56
56
|
"telefone": order.ship_address.phone,
|
|
57
|
-
"tipo": tipo_pessoa(order.
|
|
58
|
-
"numeroDocumento": order.
|
|
57
|
+
"tipo": tipo_pessoa(order.tax_id),
|
|
58
|
+
"numeroDocumento": order.tax_id,
|
|
59
59
|
"email": order.email,
|
|
60
60
|
"endereco": {
|
|
61
61
|
"geral": {
|
|
@@ -1,19 +1,14 @@
|
|
|
1
|
-
module
|
|
2
|
-
class
|
|
3
|
-
|
|
4
|
-
ID_LOJA_BLING = SolidusBling.config.store_id.to_i || 204601505
|
|
5
|
-
ID_VENDEDOR_BLING = SolidusBling.config.seller_id.to_i || 15596272829
|
|
6
|
-
ID_FORMA_PGTO_BLING = SolidusBling.config.payment_type_id.to_i || 4484076
|
|
7
|
-
ID_CAT_RECEITA_BLING = SolidusBling.config.category_id.to_i || 14653794318
|
|
1
|
+
module SolidusBling
|
|
2
|
+
class Order < SolidusBling::Api
|
|
8
3
|
|
|
9
4
|
def initialize order
|
|
10
|
-
super()
|
|
5
|
+
super(SolidusBling::Account.first)
|
|
11
6
|
@order = order
|
|
12
7
|
end
|
|
13
8
|
|
|
14
9
|
def send
|
|
15
10
|
if @order.present?
|
|
16
|
-
contato =
|
|
11
|
+
contato = SolidusBling::Contact.new(@order, @account)
|
|
17
12
|
hash_order = build_hash_order(@order, contato.info)
|
|
18
13
|
begin
|
|
19
14
|
attempts ||= 1
|
|
@@ -25,7 +20,7 @@ module Bling
|
|
|
25
20
|
json = JSON.parse(req.body)
|
|
26
21
|
response_has_error?(json)
|
|
27
22
|
if json.include? "data"
|
|
28
|
-
@order.
|
|
23
|
+
@order.bling_order_id = json["data"]["id"]
|
|
29
24
|
@order.save
|
|
30
25
|
end
|
|
31
26
|
end
|
|
@@ -39,14 +34,14 @@ module Bling
|
|
|
39
34
|
"numeroLoja": order.number,
|
|
40
35
|
"data": order.completed_at.strftime("%Y-%m-%d"),
|
|
41
36
|
"loja": {
|
|
42
|
-
"id":
|
|
37
|
+
"id": @account.external_store_id
|
|
43
38
|
},
|
|
44
39
|
"contato": {
|
|
45
40
|
"id": contato["id"]
|
|
46
41
|
},
|
|
47
42
|
"itens": build_array_items(order.line_items),
|
|
48
43
|
"vendedor": {
|
|
49
|
-
"id":
|
|
44
|
+
"id": @account.sellers.first.external_id
|
|
50
45
|
},
|
|
51
46
|
"transporte": build_hash_transporte(order),
|
|
52
47
|
"parcelas": build_array_parcelas(order),
|
|
@@ -59,20 +54,20 @@ module Bling
|
|
|
59
54
|
"observacoes": " Nº Pedido Loja: #{order.number}",
|
|
60
55
|
"observacoesInternas": "Pagamento: #{@parcelas}x R$ #{(order.total.to_f / @parcelas).round(2)}\nForma de envio: #{order.shipments.last.selected_shipping_rate.name}\n#{build_cupons(order.promotions)}",
|
|
61
56
|
"categoria": {
|
|
62
|
-
"id":
|
|
57
|
+
"id": @account.incoming_category_id
|
|
63
58
|
}
|
|
64
59
|
}
|
|
65
60
|
end
|
|
66
61
|
|
|
67
62
|
def build_array_items items
|
|
68
|
-
items.map do |item|
|
|
69
|
-
|
|
63
|
+
items.map do |item|
|
|
64
|
+
bling_product = SolidusBling::Product.find_by(sku: item.sku)
|
|
70
65
|
{
|
|
71
|
-
"id":
|
|
66
|
+
"id": bling_product.external_id,
|
|
72
67
|
"quantidade": item.quantity,
|
|
73
68
|
"valor": item.price.to_f,
|
|
74
69
|
"produto": {
|
|
75
|
-
"id":
|
|
70
|
+
"id": bling_product.external_id
|
|
76
71
|
}
|
|
77
72
|
}
|
|
78
73
|
end
|
|
@@ -89,7 +84,7 @@ module Bling
|
|
|
89
84
|
"dataVencimento": (order.completed_at + parcela.months).strftime("%Y-%m-%d"),
|
|
90
85
|
"valor": valor_parcela,
|
|
91
86
|
"formaPagamento": {
|
|
92
|
-
"id":
|
|
87
|
+
"id": @account.payment_methods.find_by(spree_payment_method_id: order.payments.last.payment_method_id).external_id
|
|
93
88
|
}
|
|
94
89
|
}
|
|
95
90
|
end
|
|
@@ -1,20 +1,22 @@
|
|
|
1
|
-
module
|
|
2
|
-
class
|
|
1
|
+
module SolidusBling
|
|
2
|
+
class Product < ApplicationRecord
|
|
3
|
+
belongs_to :account
|
|
3
4
|
|
|
4
|
-
def update
|
|
5
|
+
def self.update bling_account
|
|
6
|
+
bling_api = SolidusBling::Api.new(bling_account)
|
|
5
7
|
skus = Spree::Variant.pluck(:sku)
|
|
6
8
|
hash_products = {}
|
|
7
9
|
products = skus.map do |sku|
|
|
8
10
|
begin
|
|
9
11
|
attempts ||= 1
|
|
10
|
-
req = Typhoeus.get("#{
|
|
12
|
+
req = Typhoeus.get("#{bling_api.account.api_base_url}/produtos?codigo=#{sku}", headers: bling_api.headers)
|
|
11
13
|
res_json = JSON.parse(req.body)
|
|
12
14
|
p "#{sku} => #{res_json}"
|
|
13
15
|
next if res_json["data"] == []
|
|
14
16
|
product = res_json["data"].first
|
|
15
17
|
hash_products[sku] = product["id"]
|
|
16
18
|
{
|
|
17
|
-
|
|
19
|
+
account_id: bling_api.account.id,
|
|
18
20
|
sku: sku,
|
|
19
21
|
external_id: product["id"].to_s,
|
|
20
22
|
name: product["nome"]
|
|
@@ -26,8 +28,9 @@ module Bling
|
|
|
26
28
|
retry if (attempts += 1) < 5
|
|
27
29
|
end
|
|
28
30
|
end.compact.uniq
|
|
29
|
-
|
|
30
|
-
Spree::Bus.publish :
|
|
31
|
+
SolidusBling::Product.upsert_all(products, unique_by: :sku)
|
|
32
|
+
Spree::Bus.publish :bling_products_updated, products: hash_products
|
|
31
33
|
end
|
|
34
|
+
|
|
32
35
|
end
|
|
33
|
-
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
module SolidusBling
|
|
2
|
+
class Subscriber
|
|
3
|
+
include Omnes::Subscriber
|
|
4
|
+
|
|
5
|
+
handle :order_finalized,
|
|
6
|
+
with: :send_order_to_bling,
|
|
7
|
+
id: :send_order_to_bling
|
|
8
|
+
|
|
9
|
+
handle :bling_products_updated,
|
|
10
|
+
with: :products_updated,
|
|
11
|
+
id: :products_updated
|
|
12
|
+
|
|
13
|
+
handle :bling_contact_created,
|
|
14
|
+
with: :contato_created,
|
|
15
|
+
id: :contato_created
|
|
16
|
+
|
|
17
|
+
def send_order_to_bling event, debug_info = {}
|
|
18
|
+
method = __method__.to_s
|
|
19
|
+
SolidusBling::OrderJob.perform_later(event: event.payload, method_name: method)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def contato_created event, debug_info = {}
|
|
23
|
+
method = __method__.to_s
|
|
24
|
+
SolidusBling::ContactJob.perform_later(event: event.payload, method_name: method)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def products_updated event, debug_info = {}
|
|
28
|
+
method = __method__.to_s
|
|
29
|
+
SolidusBling::ProductJob.perform_later(event: event.payload, method_name: method)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
<%= form_with model: bling_account, url: form_url do |form| %>
|
|
2
|
+
<div>
|
|
3
|
+
<%= form.label :app_name, "Nome do Aplicativo: " %>
|
|
4
|
+
<%= form.text_field :app_name %>
|
|
5
|
+
</div>
|
|
6
|
+
|
|
7
|
+
<div>
|
|
8
|
+
<%= form.label :client_id, "Client ID: " %>
|
|
9
|
+
<%= form.text_field :client_id %>
|
|
10
|
+
</div>
|
|
11
|
+
|
|
12
|
+
<div>
|
|
13
|
+
<%= form.label :client_secret, "Client Secret: " %>
|
|
14
|
+
<%= form.text_field :client_secret %>
|
|
15
|
+
</div>
|
|
16
|
+
|
|
17
|
+
<div>
|
|
18
|
+
<%= form.label :refresh_token, "Refresh Token: " %>
|
|
19
|
+
<%= form.text_field :refresh_token %>
|
|
20
|
+
</div>
|
|
21
|
+
|
|
22
|
+
<div>
|
|
23
|
+
<%= form.label :api_base_url, "API URL: " %>
|
|
24
|
+
<%= form.text_field :api_base_url %>
|
|
25
|
+
</div>
|
|
26
|
+
|
|
27
|
+
<div>
|
|
28
|
+
<%= form.label :external_store_id, "ID da Loja no Bling: " %>
|
|
29
|
+
<%= form.text_field :external_store_id %>
|
|
30
|
+
</div>
|
|
31
|
+
|
|
32
|
+
<div>
|
|
33
|
+
<%= form.label :incoming_category_id, "ID da Categoria de Receita: " %>
|
|
34
|
+
<%= form.text_field :incoming_category_id %>
|
|
35
|
+
</div>
|
|
36
|
+
|
|
37
|
+
<div>
|
|
38
|
+
<% bling_account.payment_methods.each do |payment_method| %>
|
|
39
|
+
<%= form.fields_for :payment_methods do |payment_form| %>
|
|
40
|
+
<%= payment_form.select :spree_payment_method_id, @payment_methods %>
|
|
41
|
+
<%= payment_form.text_field :external_id %>
|
|
42
|
+
<% end %>
|
|
43
|
+
<% end %>
|
|
44
|
+
</div>
|
|
45
|
+
|
|
46
|
+
<div>
|
|
47
|
+
<% bling_account.shipping_methods.each do |shipping_method| %>
|
|
48
|
+
<%= form.fields_for :shipping_methods do |shipping_form| %>
|
|
49
|
+
<%= shipping_form.select :spree_shipping_method_id, @shipping_methods %>
|
|
50
|
+
<%= shipping_form.text_field :alias %>
|
|
51
|
+
<% end %>
|
|
52
|
+
<% end %>
|
|
53
|
+
</div>
|
|
54
|
+
|
|
55
|
+
<div>
|
|
56
|
+
<% bling_account.sellers.each do |seller| %>
|
|
57
|
+
<%= form.fields_for :sellers do |seller_form| %>
|
|
58
|
+
<%= seller_form.label :name, "Nome do Vendedor: " %>
|
|
59
|
+
<%= seller_form.text_field :name %>
|
|
60
|
+
|
|
61
|
+
<%= seller_form.label :external_id, "ID do Vendedor: " %>
|
|
62
|
+
<%= seller_form.text_field :external_id %>
|
|
63
|
+
<% end %>
|
|
64
|
+
<% end %>
|
|
65
|
+
</div>
|
|
66
|
+
|
|
67
|
+
<%= form.submit "Salvar" %>
|
|
68
|
+
<% end %>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<%= link_to "Criar", new_admin_account_path %>
|
|
2
|
+
<div>
|
|
3
|
+
<% @accounts.each do |account| %>
|
|
4
|
+
<div>
|
|
5
|
+
<div>
|
|
6
|
+
Nome do aplicativo:
|
|
7
|
+
<span><%= account.app_name %></span>
|
|
8
|
+
</div>
|
|
9
|
+
<%= link_to "Editar", edit_admin_account_path(account.id) %>
|
|
10
|
+
<%= link_to "Excluir", admin_account_path(account.id), method: :delete %>
|
|
11
|
+
</div>
|
|
12
|
+
<% end %>
|
|
13
|
+
</div>
|
data/config/routes.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
class
|
|
1
|
+
class CreateSolidusBlingAccounts < ActiveRecord::Migration[7.0]
|
|
2
2
|
def change
|
|
3
|
-
create_table :
|
|
3
|
+
create_table :solidus_bling_accounts do |t|
|
|
4
4
|
t.string :name
|
|
5
5
|
t.string :app_name
|
|
6
6
|
t.string :api_base_url
|
|
@@ -9,6 +9,8 @@ class CreateErpAccounts < ActiveRecord::Migration[7.0]
|
|
|
9
9
|
t.string :client_secret
|
|
10
10
|
t.string :refresh_token
|
|
11
11
|
t.string :access_token
|
|
12
|
+
t.string :external_store_id
|
|
13
|
+
t.string :incoming_category_id
|
|
12
14
|
t.datetime :token_expires_in
|
|
13
15
|
|
|
14
16
|
t.timestamps
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
class
|
|
1
|
+
class CreateSolidusBlingProducts < ActiveRecord::Migration[7.0]
|
|
2
2
|
def change
|
|
3
|
-
create_table :
|
|
3
|
+
create_table :solidus_bling_products do |t|
|
|
4
4
|
t.string :external_id, null: false, index: { unique: true }
|
|
5
5
|
t.string :name, null: false
|
|
6
6
|
t.string :sku, null: false, index: { unique: true }
|
|
7
|
-
t.
|
|
7
|
+
t.integer :account_id, null: false, index: true
|
|
8
8
|
|
|
9
9
|
t.timestamps
|
|
10
10
|
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
class
|
|
1
|
+
class CreateSolidusBlingEvents < ActiveRecord::Migration[7.0]
|
|
2
2
|
def change
|
|
3
|
-
create_table :
|
|
3
|
+
create_table :solidus_bling_events do |t|
|
|
4
4
|
t.string :internal_id
|
|
5
5
|
t.string :status
|
|
6
6
|
t.string :message
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
class CreateSolidusBlingPaymentMethods < ActiveRecord::Migration[7.0]
|
|
2
|
+
def change
|
|
3
|
+
create_table :solidus_bling_payment_methods do |t|
|
|
4
|
+
t.string :external_id
|
|
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,13 @@
|
|
|
1
|
+
class CreateSolidusBlingShippingMethods < ActiveRecord::Migration[7.0]
|
|
2
|
+
def change
|
|
3
|
+
create_table :solidus_bling_shipping_methods do |t|
|
|
4
|
+
t.string :alias
|
|
5
|
+
t.integer :account_id, null: false, index: true, index: { name: "solidus_bling_shipping_account_index" }
|
|
6
|
+
t.integer :spree_shipping_method_id, null: false, index: true, index: { name: "solidus_bling_spree_shipping_index" }
|
|
7
|
+
|
|
8
|
+
t.timestamps
|
|
9
|
+
|
|
10
|
+
t.foreign_key :spree_shipping_methods, column: :spree_shipping_method_id
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -3,9 +3,4 @@
|
|
|
3
3
|
SolidusBling.configure do |config|
|
|
4
4
|
# TODO: Remember to change this with the actual preferences you have implemented!
|
|
5
5
|
# config.sample_preference = 'sample_value'
|
|
6
|
-
config.app_name = ''
|
|
7
|
-
config.store_id = ''
|
|
8
|
-
config.seller_id = ''
|
|
9
|
-
config.payment_type_id = ''
|
|
10
|
-
config.category_id = ''
|
|
11
6
|
end
|
data/lib/solidus_bling/engine.rb
CHANGED
|
@@ -7,19 +7,32 @@ module SolidusBling
|
|
|
7
7
|
class Engine < Rails::Engine
|
|
8
8
|
include SolidusSupport::EngineExtensions
|
|
9
9
|
|
|
10
|
-
isolate_namespace
|
|
10
|
+
isolate_namespace SolidusBling
|
|
11
11
|
|
|
12
12
|
engine_name 'solidus_bling'
|
|
13
13
|
|
|
14
|
+
initializer 'solidus_bling.configure_backend' do
|
|
15
|
+
next unless ::Spree::Backend::Config.respond_to?(:menu_items)
|
|
16
|
+
|
|
17
|
+
::Spree::Backend::Config.configure do |config|
|
|
18
|
+
config.menu_items << config.class::MenuItem.new(
|
|
19
|
+
[:bling_account],
|
|
20
|
+
'exclamation',
|
|
21
|
+
url: :admin_accounts_path,
|
|
22
|
+
condition: -> { can?(:manage, Spree::Store) }
|
|
23
|
+
)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
14
27
|
# use rspec for tests
|
|
15
28
|
config.generators do |g|
|
|
16
29
|
g.test_framework :rspec
|
|
17
30
|
end
|
|
18
31
|
|
|
19
32
|
config.to_prepare do
|
|
20
|
-
Spree::Bus.register(:
|
|
21
|
-
Spree::Bus.register(:
|
|
22
|
-
|
|
33
|
+
Spree::Bus.register(:bling_products_updated)
|
|
34
|
+
Spree::Bus.register(:bling_contact_created)
|
|
35
|
+
SolidusBling::Subscriber.new.subscribe_to(Spree::Bus)
|
|
23
36
|
end
|
|
24
37
|
|
|
25
38
|
end
|
data/lib/solidus_bling.rb
CHANGED
data/solidus_bling.gemspec
CHANGED
|
@@ -31,6 +31,13 @@ Gem::Specification.new do |spec|
|
|
|
31
31
|
spec.add_dependency 'solidus_core', ['>= 2.0.0', '< 5']
|
|
32
32
|
spec.add_dependency 'solidus_support', '~> 0.5'
|
|
33
33
|
spec.add_dependency 'typhoeus'
|
|
34
|
+
spec.add_dependency 'solidus_brazilian_adaptations'
|
|
34
35
|
|
|
35
36
|
spec.add_development_dependency 'solidus_dev_support', '~> 2.7'
|
|
37
|
+
|
|
38
|
+
spec.post_install_message = <<-MESSAGE
|
|
39
|
+
To complete the installation, please run:
|
|
40
|
+
bin/rails g solidus_brazilian_adaptations:install
|
|
41
|
+
MESSAGE
|
|
42
|
+
|
|
36
43
|
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'rails_helper'
|
|
2
|
+
|
|
3
|
+
# Specs in this file have access to a helper object that includes
|
|
4
|
+
# the AccountsHelper. For example:
|
|
5
|
+
#
|
|
6
|
+
# describe AccountsHelper do
|
|
7
|
+
# describe "string concat" do
|
|
8
|
+
# it "concats two strings with spaces" do
|
|
9
|
+
# expect(helper.concat_strings("this","that")).to eq("this that")
|
|
10
|
+
# end
|
|
11
|
+
# end
|
|
12
|
+
# end
|
|
13
|
+
module SolidusBling
|
|
14
|
+
RSpec.describe AccountsHelper, type: :helper do
|
|
15
|
+
pending "add some examples to (or delete) #{__FILE__}"
|
|
16
|
+
end
|
|
17
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: solidus_bling
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 2.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- ulysses-bull
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2023-09-
|
|
11
|
+
date: 2023-09-18 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: solidus_core
|
|
@@ -58,6 +58,20 @@ dependencies:
|
|
|
58
58
|
- - ">="
|
|
59
59
|
- !ruby/object:Gem::Version
|
|
60
60
|
version: '0'
|
|
61
|
+
- !ruby/object:Gem::Dependency
|
|
62
|
+
name: solidus_brazilian_adaptations
|
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - ">="
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '0'
|
|
68
|
+
type: :runtime
|
|
69
|
+
prerelease: false
|
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - ">="
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: '0'
|
|
61
75
|
- !ruby/object:Gem::Dependency
|
|
62
76
|
name: solidus_dev_support
|
|
63
77
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -72,7 +86,7 @@ dependencies:
|
|
|
72
86
|
- - "~>"
|
|
73
87
|
- !ruby/object:Gem::Version
|
|
74
88
|
version: '2.7'
|
|
75
|
-
description:
|
|
89
|
+
description:
|
|
76
90
|
email: contato7bulloleo@gmail.com
|
|
77
91
|
executables: []
|
|
78
92
|
extensions: []
|
|
@@ -94,18 +108,27 @@ files:
|
|
|
94
108
|
- app/assets/javascripts/spree/frontend/solidus_bling.js
|
|
95
109
|
- app/assets/stylesheets/spree/backend/solidus_bling.css
|
|
96
110
|
- app/assets/stylesheets/spree/frontend/solidus_bling.css
|
|
97
|
-
- app/
|
|
98
|
-
- app/
|
|
99
|
-
- app/jobs/
|
|
100
|
-
- app/jobs/
|
|
101
|
-
- app/
|
|
102
|
-
- app/
|
|
103
|
-
- app/models/
|
|
104
|
-
- app/models/
|
|
105
|
-
- app/models/
|
|
106
|
-
- app/models/
|
|
107
|
-
- app/models/
|
|
108
|
-
- app/
|
|
111
|
+
- app/controllers/spree/admin/accounts_controller.rb
|
|
112
|
+
- app/helpers/solidus_bling/accounts_helper.rb
|
|
113
|
+
- app/jobs/solidus_bling/application_job.rb
|
|
114
|
+
- app/jobs/solidus_bling/contact_job.rb
|
|
115
|
+
- app/jobs/solidus_bling/order_job.rb
|
|
116
|
+
- app/jobs/solidus_bling/product_job.rb
|
|
117
|
+
- app/models/solidus_bling/account.rb
|
|
118
|
+
- app/models/solidus_bling/api.rb
|
|
119
|
+
- app/models/solidus_bling/contact.rb
|
|
120
|
+
- app/models/solidus_bling/event.rb
|
|
121
|
+
- app/models/solidus_bling/order.rb
|
|
122
|
+
- app/models/solidus_bling/payment_method.rb
|
|
123
|
+
- app/models/solidus_bling/product.rb
|
|
124
|
+
- app/models/solidus_bling/seller.rb
|
|
125
|
+
- app/models/solidus_bling/shipping_method.rb
|
|
126
|
+
- app/subscribers/solidus_bling/subscriber.rb
|
|
127
|
+
- app/views/spree/admin/accounts/_form.html.erb
|
|
128
|
+
- app/views/spree/admin/accounts/edit.html.erb
|
|
129
|
+
- app/views/spree/admin/accounts/index.html.erb
|
|
130
|
+
- app/views/spree/admin/accounts/new.html.erb
|
|
131
|
+
- app/views/spree/admin/accounts/show.html.erb
|
|
109
132
|
- bin/console
|
|
110
133
|
- bin/rails
|
|
111
134
|
- bin/rails-engine
|
|
@@ -113,13 +136,15 @@ files:
|
|
|
113
136
|
- bin/rake
|
|
114
137
|
- bin/sandbox
|
|
115
138
|
- bin/setup
|
|
116
|
-
- config/initializers/solidus_bling.rb
|
|
117
139
|
- config/locales/en.yml
|
|
118
140
|
- config/routes.rb
|
|
119
|
-
- db/migrate/
|
|
120
|
-
- db/migrate/
|
|
121
|
-
- db/migrate/
|
|
122
|
-
- db/migrate/
|
|
141
|
+
- db/migrate/20230918141419_create_solidus_bling_accounts.rb
|
|
142
|
+
- db/migrate/20230918141505_add_bling_order_id_to_spree_orders.rb
|
|
143
|
+
- db/migrate/20230918141700_create_solidus_bling_products.rb
|
|
144
|
+
- db/migrate/20230918142547_create_solidus_bling_events.rb
|
|
145
|
+
- db/migrate/20230918142742_create_solidus_bling_payment_methods.rb
|
|
146
|
+
- db/migrate/20230918142953_create_solidus_bling_sellers.rb
|
|
147
|
+
- db/migrate/20230918143057_create_solidus_bling_shipping_methods.rb
|
|
123
148
|
- lib/generators/solidus_bling/install/install_generator.rb
|
|
124
149
|
- lib/generators/solidus_bling/install/templates/initializer.rb
|
|
125
150
|
- lib/solidus_bling.rb
|
|
@@ -128,12 +153,17 @@ files:
|
|
|
128
153
|
- lib/solidus_bling/testing_support/factories.rb
|
|
129
154
|
- lib/solidus_bling/version.rb
|
|
130
155
|
- solidus_bling.gemspec
|
|
131
|
-
- spec/
|
|
132
|
-
- spec/jobs/
|
|
133
|
-
- spec/jobs/
|
|
134
|
-
- spec/
|
|
135
|
-
- spec/models/
|
|
136
|
-
- spec/models/
|
|
156
|
+
- spec/helpers/solidus_bling/accounts_helper_spec.rb
|
|
157
|
+
- spec/jobs/solidus_bling/contact_job_spec.rb
|
|
158
|
+
- spec/jobs/solidus_bling/order_job_spec.rb
|
|
159
|
+
- spec/jobs/solidus_bling/product_job_spec.rb
|
|
160
|
+
- spec/models/solidus_bling/account_spec.rb
|
|
161
|
+
- spec/models/solidus_bling/event_spec.rb
|
|
162
|
+
- spec/models/solidus_bling/payment_method_spec.rb
|
|
163
|
+
- spec/models/solidus_bling/product_spec.rb
|
|
164
|
+
- spec/models/solidus_bling/seller_spec.rb
|
|
165
|
+
- spec/models/solidus_bling/shipping_method_spec.rb
|
|
166
|
+
- spec/requests/solidus_bling/accounts_spec.rb
|
|
137
167
|
- spec/spec_helper.rb
|
|
138
168
|
homepage: https://github.com/ulysses-bull/solidus_bling#readme
|
|
139
169
|
licenses:
|
|
@@ -142,7 +172,9 @@ metadata:
|
|
|
142
172
|
homepage_uri: https://github.com/ulysses-bull/solidus_bling#readme
|
|
143
173
|
source_code_uri: https://github.com/ulysses-bull/solidus_bling
|
|
144
174
|
changelog_uri: https://github.com/ulysses-bull/solidus_bling/blob/master/CHANGELOG.md
|
|
145
|
-
post_install_message:
|
|
175
|
+
post_install_message: |2
|
|
176
|
+
To complete the installation, please run:
|
|
177
|
+
bin/rails g solidus_brazilian_adaptations:install
|
|
146
178
|
rdoc_options: []
|
|
147
179
|
require_paths:
|
|
148
180
|
- lib
|
|
@@ -161,14 +193,19 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
161
193
|
version: '0'
|
|
162
194
|
requirements: []
|
|
163
195
|
rubygems_version: 3.4.6
|
|
164
|
-
signing_key:
|
|
196
|
+
signing_key:
|
|
165
197
|
specification_version: 4
|
|
166
198
|
summary: Solidus extension to integrate with the Bling
|
|
167
199
|
test_files:
|
|
168
|
-
- spec/
|
|
169
|
-
- spec/jobs/
|
|
170
|
-
- spec/jobs/
|
|
171
|
-
- spec/
|
|
172
|
-
- spec/models/
|
|
173
|
-
- spec/models/
|
|
200
|
+
- spec/helpers/solidus_bling/accounts_helper_spec.rb
|
|
201
|
+
- spec/jobs/solidus_bling/contact_job_spec.rb
|
|
202
|
+
- spec/jobs/solidus_bling/order_job_spec.rb
|
|
203
|
+
- spec/jobs/solidus_bling/product_job_spec.rb
|
|
204
|
+
- spec/models/solidus_bling/account_spec.rb
|
|
205
|
+
- spec/models/solidus_bling/event_spec.rb
|
|
206
|
+
- spec/models/solidus_bling/payment_method_spec.rb
|
|
207
|
+
- spec/models/solidus_bling/product_spec.rb
|
|
208
|
+
- spec/models/solidus_bling/seller_spec.rb
|
|
209
|
+
- spec/models/solidus_bling/shipping_method_spec.rb
|
|
210
|
+
- spec/requests/solidus_bling/accounts_spec.rb
|
|
174
211
|
- spec/spec_helper.rb
|
data/app/jobs/application_job.rb
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
class ApplicationJob < ActiveJob::Base
|
|
2
|
-
# Automatically retry jobs that encountered a deadlock
|
|
3
|
-
# retry_on ActiveRecord::Deadlocked
|
|
4
|
-
|
|
5
|
-
# Most jobs are safe to ignore if the underlying records are no longer available
|
|
6
|
-
# discard_on ActiveJob::DeserializationError
|
|
7
|
-
end
|
data/app/jobs/erp_contact_job.rb
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
class ErpContactJob < ApplicationJob
|
|
2
|
-
queue_as :default
|
|
3
|
-
|
|
4
|
-
def perform event:, method_name:
|
|
5
|
-
erp_event = ErpEvent.new
|
|
6
|
-
contact = event.payload[:args][:contato]
|
|
7
|
-
order = event.payload[:args][:order]
|
|
8
|
-
erp_event.internal_id = order.id
|
|
9
|
-
erp_event.name = event.omnes_event_name
|
|
10
|
-
erp_event.method = method_name
|
|
11
|
-
if contact.include? "error"
|
|
12
|
-
erp_event.status = 'error'
|
|
13
|
-
erp_event.message = contact["error"]["description"]
|
|
14
|
-
else
|
|
15
|
-
erp_event.status = 'success'
|
|
16
|
-
end
|
|
17
|
-
erp_event.body = order.to_json
|
|
18
|
-
erp_event.save!
|
|
19
|
-
end
|
|
20
|
-
end
|
data/app/jobs/erp_order_job.rb
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
class ErpOrderJob < ApplicationJob
|
|
2
|
-
queue_as :default
|
|
3
|
-
|
|
4
|
-
def perform event:, method_name:
|
|
5
|
-
erp_event = ErpEvent.new
|
|
6
|
-
order = event.payload[:order]
|
|
7
|
-
erp_event.internal_id = order.id
|
|
8
|
-
erp_event.name = event.omnes_event_name
|
|
9
|
-
erp_event.method = method_name
|
|
10
|
-
begin
|
|
11
|
-
Bling::Pedido.new(order).send
|
|
12
|
-
erp_event.status = 'success'
|
|
13
|
-
rescue => e
|
|
14
|
-
erp_event.status = 'error'
|
|
15
|
-
erp_event.message = e.to_json
|
|
16
|
-
ensure
|
|
17
|
-
erp_event.body = order.to_json
|
|
18
|
-
erp_event.save!
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
data/app/jobs/erp_product_job.rb
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
class ErpProductJob < ApplicationJob
|
|
2
|
-
queue_as :default
|
|
3
|
-
|
|
4
|
-
def perform event:, method_name:
|
|
5
|
-
erp_event = ErpEvent.new
|
|
6
|
-
products = event.payload[:products]
|
|
7
|
-
erp_event.name = event.omnes_event_name
|
|
8
|
-
erp_event.method = method_name
|
|
9
|
-
erp_event.body = products.to_json
|
|
10
|
-
erp_event.save!
|
|
11
|
-
end
|
|
12
|
-
end
|
data/app/models/erp_account.rb
DELETED
data/app/models/erp_event.rb
DELETED
data/app/models/erp_product.rb
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
module Bling
|
|
2
|
-
class Subscriber
|
|
3
|
-
include Omnes::Subscriber
|
|
4
|
-
|
|
5
|
-
handle :order_finalized,
|
|
6
|
-
with: :send_order_to_bling,
|
|
7
|
-
id: :send_order_to_bling
|
|
8
|
-
|
|
9
|
-
handle :erp_products_updated,
|
|
10
|
-
with: :products_updated,
|
|
11
|
-
id: :products_updated
|
|
12
|
-
|
|
13
|
-
handle :erp_contato_created,
|
|
14
|
-
with: :contato_created,
|
|
15
|
-
id: :contato_created
|
|
16
|
-
|
|
17
|
-
def send_order_to_bling event
|
|
18
|
-
method = __method__.to_s
|
|
19
|
-
ErpOrderJob.perform_later(event: event, method_name: method)
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def contato_created event
|
|
23
|
-
method = __method__.to_s
|
|
24
|
-
ErpContactJob.perform_later(event: event, method_name: method)
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def products_updated event
|
|
28
|
-
method = __method__.to_s
|
|
29
|
-
ErpProductJob.perform_later(event: event, method_name: method)
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
SolidusBling.configure do |config|
|
|
4
|
-
# TODO: Remember to change this with the actual preferences you have implemented!
|
|
5
|
-
# config.sample_preference = 'sample_value'
|
|
6
|
-
config.app_name = ''
|
|
7
|
-
config.store_id = ''
|
|
8
|
-
config.seller_id = ''
|
|
9
|
-
config.payment_type_id = ''
|
|
10
|
-
config.category_id = ''
|
|
11
|
-
end
|