solidus_brazilian_adaptations 1.0.0 → 1.0.1
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7797d6654515e8404898c5445c80c24907108084f3bfa40d90394eadff4128ab
|
4
|
+
data.tar.gz: 9b45e301f29cb1ac65525f6b743a9d87fea959b56be0982febdfff1736192fdd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36b1d4c5757fd115a7050cea15960888039a211b365b14633f43c0e2ec8b6f36199ef045c29aafa2f2136ff5cd947d9e3ba5a48d2fdee8876e8005e5fc24d268
|
7
|
+
data.tar.gz: 45232cb42a3380d80d15f7794bdbafe1eb285220c2a5b0668b0d5f5b571039020a28a4c737502ad97ea2d1f626ed32195979bd47f514b44c6d4532e5f37bf99a
|
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
[![CircleCI](https://circleci.com/gh/solidusio-contrib/solidus_brazilian_adaptations.svg?style=shield)](https://circleci.com/gh/solidusio-contrib/solidus_brazilian_adaptations)
|
4
4
|
[![codecov](https://codecov.io/gh/solidusio-contrib/solidus_brazilian_adaptations/branch/master/graph/badge.svg)](https://codecov.io/gh/solidusio-contrib/solidus_brazilian_adaptations)
|
5
5
|
|
6
|
-
|
6
|
+
Essa gem tem como objetivo adaptar os modelos do Solidus para se adequar aos padrões brasileiros, tais como a criação dos atributos CPF/CNPJ (tax_id) em Spree::Order, e número (number) do imóvel e bairro (district) em Spree::Address.
|
7
7
|
|
8
8
|
## Installation
|
9
9
|
|
@@ -21,36 +21,249 @@ bin/rails generate solidus_brazilian_adaptations:install
|
|
21
21
|
|
22
22
|
## Usage
|
23
23
|
|
24
|
-
|
24
|
+
### Configurações
|
25
|
+
A partir do initializer da gem é possivel configurar se será permitido efetuar compras utilizando CNPJ. Por padrão é essa opção é `true`.
|
26
|
+
|
27
|
+
### Storefront
|
28
|
+
Essa gem utiliza o starter frontend como base, então os exemplos serão feitos a partir de suas views.
|
29
|
+
|
30
|
+
Para adicionar os campos de CPF/CNPJ, número e bairro é possivel editar o form da etapa de endereço. Porém a edição é feita em duas partials diferentes:
|
31
|
+
|
32
|
+
Na partial `app/views/checkouts/_checkout_step.html.erb` o seguinte HTML referente ao **CPF/CNPJ** pode ser inserido logo abaixo ao input de e-mail:
|
25
33
|
```erb
|
26
|
-
|
34
|
+
|
27
35
|
<%= form_for order, url: update_checkout_path(order.state), html: { id: "checkout_form_#{order.state}" } do |form| %>
|
28
36
|
<% if order.state == "address" || !order.email? %>
|
29
37
|
<div class="text-input">
|
30
38
|
<%= form.label :email, 'E-Mail:' %>
|
31
39
|
<%= form.email_field :email, required: true, placeholder: 'name@example.com' %>
|
32
40
|
</div>
|
41
|
+
|
42
|
+
<!-- Adicionar -->
|
43
|
+
<% label = SolidusBrazilianAdaptations.config.allow_cnpj ? "CPF/CPNJ" : "CPF" %>
|
33
44
|
<div class="text-input" style="margin-top: 4px;">
|
34
45
|
<%= form.label :tax_id, "#{label}:" %>
|
35
46
|
<%= form.text_field :tax_id, required: true, placeholder: label %>
|
36
47
|
</div>
|
48
|
+
<!-- ********* -->
|
49
|
+
|
37
50
|
<% end %>
|
38
51
|
|
39
52
|
<%= render "checkouts/steps/#{order.state}_step", form: form, differentiator: @differentiator %>
|
40
53
|
<% end %>
|
41
54
|
```
|
42
55
|
|
43
|
-
E
|
56
|
+
E na partial `app/views/checkouts/steps/address_step/_address_inputs.html.erb` adicionar o seguinte código referente ao **número** e **bairro**, podendo ser alterada a ordem dos campos:
|
44
57
|
```erb
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
58
|
+
<!-- Adicionar -->
|
59
|
+
<div class="text-input">
|
60
|
+
<%= form.label :number, "Número:" %>
|
61
|
+
<%= form.text_field :number, required: true %>
|
62
|
+
</div>
|
63
|
+
<!-- ********* -->
|
64
|
+
|
65
|
+
<div class="text-input">
|
66
|
+
<%= form.label :address2, "#{I18n.t("spree.street_address_2")}:" %>
|
67
|
+
<%= form.text_field :address2, autocomplete: "#{address_type} address-line2" %>
|
68
|
+
</div>
|
69
|
+
|
70
|
+
<!-- Adicionar -->
|
71
|
+
<div class="text-input">
|
72
|
+
<%= form.label :district, "Bairro:" %>
|
73
|
+
<%= form.text_field :district, required: true %>
|
74
|
+
</div>
|
75
|
+
<!-- ********* -->
|
76
|
+
|
77
|
+
<div class="text-input">
|
78
|
+
<%= form.label :city, "#{I18n.t("spree.city")}:" %>
|
79
|
+
<%= form.text_field :city, required: true, autocomplete: "#{address_type} address-level2" %>
|
80
|
+
</div>
|
81
|
+
```
|
82
|
+
|
83
|
+
### Admin
|
84
|
+
|
85
|
+
Para visualizar os campos de **CPF/CNPJ**, **número** e **bairro** no painel do Admin na aba `Order/Order_Number/Customer Details` é necessário criar as seguintes views em seu projeto:
|
86
|
+
|
87
|
+
Essas novas views irão sobrescrever as padrões, localizadas na gem `solidus_backend`. Portanto, você deve ficar atento às atualizações do Solidus, pois ao sobrescrever as views as atualizações não serão aplicadas.
|
88
|
+
|
89
|
+
`app/views/spree/admin/orders/customer_details/_form.html.erb`
|
90
|
+
```erb
|
91
|
+
<fieldset data-hook="admin_customer_detail_form_fields" class="no-border-top">
|
92
|
+
|
93
|
+
<fieldset class="index no-border-bottom" data-hook="customer_guest">
|
94
|
+
<legend align="center"><%= t('spree.account') %></legend>
|
95
|
+
|
96
|
+
<div data-hook="customer_fields" class="row">
|
97
|
+
<div class="col-9">
|
98
|
+
<div class="field">
|
99
|
+
<%= f.label :email %>
|
100
|
+
<%= f.email_field :email, required: true, class: 'fullwidth' %>
|
101
|
+
</div>
|
102
|
+
|
103
|
+
<!-- Adicionado -->
|
104
|
+
<div class="field">
|
105
|
+
<%= f.label :tax_id, "CPF/CNPJ" %>
|
106
|
+
<%= f.text_field :tax_id, required: true, class: 'fullwidth' %>
|
107
|
+
</div>
|
108
|
+
<!-- ********* -->
|
109
|
+
</div>
|
110
|
+
<div class="col-3">
|
111
|
+
<div class="field">
|
112
|
+
<%= label_tag nil, t('spree.guest_checkout') %>
|
113
|
+
<ul>
|
114
|
+
<% if @order.completed? %>
|
115
|
+
<li>
|
116
|
+
<%= @order.user.nil? ? t('spree.say_yes') : t('spree.say_no') %>
|
117
|
+
</li>
|
118
|
+
<% else %>
|
119
|
+
<% guest = @order.user.nil? %>
|
120
|
+
<li>
|
121
|
+
<label>
|
122
|
+
<%= radio_button_tag :guest_checkout, true, guest %>
|
123
|
+
<%= t('spree.say_yes') %>
|
124
|
+
</label>
|
125
|
+
</li>
|
126
|
+
<li>
|
127
|
+
<label>
|
128
|
+
<%= radio_button_tag :guest_checkout, false, !guest, disabled: @order.cart? %>
|
129
|
+
<%= t('spree.say_no') %>
|
130
|
+
</label>
|
131
|
+
</li>
|
132
|
+
<%= hidden_field_tag :user_id, @order.user_id %>
|
133
|
+
<% end %>
|
134
|
+
</ul>
|
135
|
+
</div>
|
136
|
+
</div>
|
137
|
+
</div>
|
138
|
+
</fieldset>
|
139
|
+
|
140
|
+
<div class="row">
|
141
|
+
<% if Spree::Config[:order_bill_address_used] %>
|
142
|
+
<div class="col-6" data-hook="bill_address_wrapper">
|
143
|
+
<fieldset class="no-border-bottom">
|
144
|
+
<legend align="center"><%= t('spree.billing_address') %></legend>
|
145
|
+
<div class="js-billing-address">
|
146
|
+
<%= f.fields_for :bill_address do |ba_form| %>
|
147
|
+
<%= render partial: 'spree/admin/shared/address_form', locals: { f: ba_form, type: "billing" } %>
|
148
|
+
<% end %>
|
149
|
+
</div>
|
150
|
+
</fieldset>
|
151
|
+
</div>
|
152
|
+
<% end %>
|
49
153
|
|
50
|
-
<div class="
|
51
|
-
|
52
|
-
|
154
|
+
<div class="col-6" data-hook="ship_address_wrapper">
|
155
|
+
<fieldset class="no-border-bottom">
|
156
|
+
<legend align="center"><%= t('spree.shipping_address') %></legend>
|
157
|
+
<% if Spree::Config[:order_bill_address_used] %>
|
158
|
+
<div class="field">
|
159
|
+
<span data-hook="use_billing">
|
160
|
+
<label>
|
161
|
+
<%= check_box_tag 'order[use_billing]', '1', (@order.ship_address.new_record? && @order.bill_address == @order.ship_address) %>
|
162
|
+
<%= t('spree.use_billing_address') %>
|
163
|
+
</label>
|
164
|
+
</span>
|
165
|
+
</div>
|
166
|
+
<% end %>
|
167
|
+
|
168
|
+
<div class="js-shipping-address">
|
169
|
+
<%= f.fields_for :ship_address do |ba_form| %>
|
170
|
+
<%= render partial: 'spree/admin/shared/address_form', locals: { f: ba_form, type: "shipping" } %>
|
171
|
+
<% end %>
|
172
|
+
</div>
|
173
|
+
</fieldset>
|
174
|
+
</div>
|
175
|
+
</div>
|
176
|
+
|
177
|
+
<div class="clear"></div>
|
178
|
+
|
179
|
+
<div class="form-buttons filter-actions actions" data-hook="buttons">
|
180
|
+
<%= button_tag t('spree.actions.update'), class: 'btn btn-primary' %>
|
181
|
+
</div>
|
182
|
+
</fieldset>
|
183
|
+
```
|
184
|
+
`app/views/spree/admin/shared/_address_form.html.erb`
|
185
|
+
```erb
|
186
|
+
<% s_or_b = type.chars.first %>
|
187
|
+
|
188
|
+
<div id="<%= type %>" data-hook="address_fields">
|
189
|
+
<div class="field <%= "#{type}-row" %>">
|
190
|
+
<%= f.label :name %>
|
191
|
+
<%= f.text_field :name, class: 'fullwidth' %>
|
192
|
+
</div>
|
193
|
+
|
194
|
+
<% if Spree::Config[:company] %>
|
195
|
+
<div class="field <%= "#{type}-row" %>">
|
196
|
+
<%= f.label :company %>
|
197
|
+
<%= f.text_field :company, class: 'fullwidth' %>
|
198
|
+
</div>
|
199
|
+
<% end %>
|
200
|
+
|
201
|
+
<div class="field <%= "#{type}-row" %>">
|
202
|
+
<%= f.label :address1 %>
|
203
|
+
<%= f.text_field :address1, class: 'fullwidth' %>
|
204
|
+
</div>
|
205
|
+
|
206
|
+
<!-- Adicionado -->
|
207
|
+
<div class="field <%= "#{type}-row" %>">
|
208
|
+
<%= f.label :number, "Número" %>
|
209
|
+
<%= f.text_field :number, class: 'fullwidth' %>
|
210
|
+
</div>
|
211
|
+
<!-- ********** -->
|
212
|
+
|
213
|
+
<div class="field <%= "#{type}-row" %>">
|
214
|
+
<%= f.label :address2 %>
|
215
|
+
<%= f.text_field :address2, class: 'fullwidth' %>
|
216
|
+
</div>
|
217
|
+
|
218
|
+
<!-- Adicionado -->
|
219
|
+
<div class="field <%= "#{type}-row" %>">
|
220
|
+
<%= f.label :district, "Bairro" %>
|
221
|
+
<%= f.text_field :district, class: 'fullwidth' %>
|
222
|
+
</div>
|
223
|
+
<!-- ********** -->
|
224
|
+
|
225
|
+
<div class="field <%= "#{type}-row" %>">
|
226
|
+
<%= f.label :city %>
|
227
|
+
<%= f.text_field :city, class: 'fullwidth' %>
|
228
|
+
</div>
|
229
|
+
|
230
|
+
<div class="field <%= "#{type}-row" %>">
|
231
|
+
<%= f.label :zipcode %>
|
232
|
+
<%= f.text_field :zipcode, class: 'fullwidth' %>
|
233
|
+
</div>
|
234
|
+
|
235
|
+
<div class="field <%= "#{type}-row" %>">
|
236
|
+
<%= f.label :country_id, Spree::Country.model_name.human %>
|
237
|
+
<span id="<%= s_or_b %>country">
|
238
|
+
<%= f.collection_select :country_id, available_countries, :id, :name, {}, {class: 'custom-select fullwidth js-country_id'} %>
|
239
|
+
</span>
|
240
|
+
</div>
|
241
|
+
|
242
|
+
<div class="field <%= "#{type}-row" %>">
|
243
|
+
<%= f.label :state_id, Spree::State.model_name.human %>
|
244
|
+
<span id="<%= s_or_b %>state">
|
245
|
+
<%= f.hidden_field :state_name, value: nil %>
|
246
|
+
<% states = f.object.country.try(:states).nil? ? [] : f.object.country.states %>
|
247
|
+
<%= f.text_field :state_name,
|
248
|
+
style: "display: #{states.empty? ? 'block' : 'none' };",
|
249
|
+
disabled: !states.empty?, class: 'fullwidth state_name js-state_name' %>
|
250
|
+
<%= f.hidden_field :state_id, value: nil %>
|
251
|
+
<%= f.collection_select :state_id,
|
252
|
+
states.sort,
|
253
|
+
:id, :name,
|
254
|
+
{ include_blank: true },
|
255
|
+
{ class: 'custom-select fullwidth js-state_id',
|
256
|
+
style: "display: #{states.empty? ? 'none' : 'block' };",
|
257
|
+
disabled: states.empty? } %>
|
258
|
+
</span>
|
259
|
+
</div>
|
260
|
+
|
261
|
+
<div class="field <%= "#{type}-row" %>">
|
262
|
+
<%= f.label :phone %>
|
263
|
+
<%= f.phone_field :phone, class: 'fullwidth' %>
|
264
|
+
</div>
|
53
265
|
</div>
|
266
|
+
|
54
267
|
```
|
55
268
|
|
56
269
|
## Development
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class AddNumberDistrictToAddresses < ActiveRecord::Migration[7.0]
|
2
2
|
def change
|
3
|
-
add_column :spree_addresses, :number, :string
|
4
|
-
add_column :spree_addresses, :district, :string
|
3
|
+
add_column :spree_addresses, :number, :string, if_not_exists: true
|
4
|
+
add_column :spree_addresses, :district, :string, if_not_exists: true
|
5
5
|
end
|
6
6
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solidus_brazilian_adaptations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ulysses-bull
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-09-
|
11
|
+
date: 2023-09-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: solidus_core
|