├── src
├── Resources
│ ├── views
│ │ ├── scripts.blade.php
│ │ ├── profile
│ │ │ ├── index.blade.php
│ │ │ └── person-type.blade.php
│ │ └── signup
│ │ │ └── person-type.blade.php
│ └── lang
│ │ └── pt_BR.json
├── Providers
│ ├── BrazilCustomerServiceProvider.php
│ └── EventServiceProvider.php
├── Listeners
│ ├── VerifyUserDataListenerCheckout.php
│ ├── VerifyUserDataListener.php
│ └── CustomerAddCustomAttributesListener.php
├── Database
│ └── Migrations
│ │ └── 2020_04_18_201548_add_br_columns_to_customer_table.php
├── Helper
│ └── Helper.php
└── Config
│ └── system.php
├── composer.json
└── README.md
/src/Resources/views/scripts.blade.php:
--------------------------------------------------------------------------------
1 | @push('scripts')
2 |
3 | @endpush
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "cagartner/bagisto-brazilcustomer",
3 | "license": "MIT",
4 | "authors": [
5 | {
6 | "name": "Carlos Gartner",
7 | "email": "contato@carlosgartner.com.br"
8 | }
9 | ],
10 | "require": {
11 | },
12 | "autoload": {
13 | "psr-4": {
14 | "Cagartner\\BrazilCustomer\\": "src/"
15 | }
16 | },
17 | "extra": {
18 | "laravel": {
19 | "providers": [
20 | "Cagartner\\BrazilCustomer\\Providers\\BrazilCustomerServiceProvider"
21 | ]
22 | }
23 | },
24 | "minimum-stability": "dev"
25 | }
26 |
--------------------------------------------------------------------------------
/src/Providers/BrazilCustomerServiceProvider.php:
--------------------------------------------------------------------------------
1 | mergeConfigFrom(
21 | dirname(__DIR__) . '/Config/system.php', 'core'
22 | );
23 |
24 | $this->app->register(EventServiceProvider::class);
25 |
26 | $this->loadViewsFrom(__DIR__ . '/../Resources/views', 'brcustomer');
27 |
28 | $this->loadJSONTranslationsFrom(__DIR__ . '/../Resources/lang');
29 |
30 | $this->loadMigrationsFrom(__DIR__ .'/../Database/Migrations');
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/Listeners/VerifyUserDataListenerCheckout.php:
--------------------------------------------------------------------------------
1 | customer = $customer;
21 | }
22 |
23 | public function handle()
24 | {
25 | $customer = auth()->guard('customer')->user();
26 |
27 | if ($customer == null || !$customer->person_type || !$customer->document) {
28 | Session()->flash('error', trans('You registration need to be completed, please update you register before buy.'));
29 | return redirect()->route('customer.profile.edit');
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/Listeners/VerifyUserDataListener.php:
--------------------------------------------------------------------------------
1 | customer = $customer;
21 | }
22 |
23 | public function handle()
24 | {
25 | $customer = auth()->guard('customer')->user();
26 |
27 | if ($customer != null and (!$customer->person_type || !$customer->document)) {
28 | Session()->flash('error', trans('You registration need to be completed, please update you register before buy.'));
29 | }
30 | }
31 | }
32 | // echo '';
--------------------------------------------------------------------------------
/src/Resources/lang/pt_BR.json:
--------------------------------------------------------------------------------
1 | {
2 | "Brazilian Customer Attributes": "Campos Brasileiros",
3 | "Enabled Person Types": "Tipo de Pessoas Habilitadas",
4 | "Person": "Física",
5 | "Person Type": "Tipo de Pessoa",
6 | "Company": "Jurídica",
7 | "Company Name": "Razão Social",
8 | "Fantasy Name": "Nome Fantasia",
9 | "Select the types of person enabled in the store": "Selecione os tipos de pessoa habilitadas na loja",
10 | "Person configurations": "Configurações de Pessoa Física",
11 | "Enable General Register?": "Habilitar RG?",
12 | "Company configurations": "Configurações de Pessoa Jurídica",
13 | "Enable State Register?": "Habilitar Inscrição Estadual?",
14 | "Enable Fantasy Name?": "Habilitar Nome Fantasia?",
15 | "General Register": "RG",
16 | "State Register": "Inscrição Estadual",
17 | "Document Person": "CPF",
18 | "Document Company": "CNPJ",
19 | "Exempt": "Isento",
20 | "You registration need to be completed, please update you register before buy.": "Seu cadastro precisa ser completado, por favor atualize seu cadastro antes de comprar."
21 | }
--------------------------------------------------------------------------------
/src/Resources/views/profile/index.blade.php:
--------------------------------------------------------------------------------
1 |
2 | | {{ __('Person Type') }} |
3 | {{ __(ucfirst($customer->person_type)) }} |
4 |
5 |
6 |
7 | |
8 | @if($customer->person_type === 'person')
9 | {{ __('Document Person') }}
10 | @else
11 | {{ __('Document Company') }}
12 | @endif
13 | |
14 | {{ $customer->document }} |
15 |
16 |
17 | @if($customer->company_name)
18 |
19 | | {{ __('Company Name') }} |
20 | {{ $customer->company_name }} |
21 |
22 | @endif
23 |
24 | @if($customer->fantasy_name)
25 |
26 | | {{ __('Fantasy Name') }} |
27 | {{ $customer->fantasy_name }} |
28 |
29 | @endif
30 |
31 | @if($customer->state_register)
32 |
33 | | {{ __('State Register') }} |
34 | {{ $customer->state_register }} |
35 |
36 | @endif
37 |
38 | @if($customer->general_register)
39 |
40 | | {{ __('General Register') }} |
41 | {{ $customer->general_register }} |
42 |
43 | @endif
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/src/Database/Migrations/2020_04_18_201548_add_br_columns_to_customer_table.php:
--------------------------------------------------------------------------------
1 | enum('person_type', ['person', 'company'])->default('person');
18 | $table->string('document', 20)->nullable();
19 | $table->string('state_register', 50)->nullable();
20 | $table->string('company_name')->nullable();
21 | $table->string('fantasy_name')->nullable();
22 | $table->string('general_register')->nullable();
23 | });
24 | }
25 |
26 | /**
27 | * Reverse the migrations.
28 | *
29 | * @return void
30 | */
31 | public function down()
32 | {
33 | Schema::table('customers', function (Blueprint $table) {
34 | $table->dropColumn(['person_type', 'document', 'state_register', 'fantasy_name', 'general_register']);
35 | });
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/Listeners/CustomerAddCustomAttributesListener.php:
--------------------------------------------------------------------------------
1 | request = $request;
21 | }
22 |
23 | /**
24 | * Handle the event.
25 | *
26 | * @param object $event
27 | * @return void
28 | */
29 | public function handle(\Webkul\Customer\Models\Customer $customer)
30 | {
31 | $save = false;
32 | if ($this->request->has('person_type')) {
33 | $customer->person_type = $this->request->get('person_type');
34 | $save = true;
35 | }
36 |
37 | if ($this->request->has('document')) {
38 | $document = \Cagartner\BrazilCustomer\Helper\Helper::clearDocumentString($this->request->get('document'));
39 | $customer->document = $document;
40 | $save = true;
41 | }
42 |
43 | if ($this->request->has('state_register')) {
44 | $customer->state_register = $this->request->get('state_register');
45 | $save = true;
46 | }
47 |
48 | if ($this->request->has('company_name')) {
49 | $customer->company_name = $this->request->get('company_name');
50 | $save = true;
51 | }
52 |
53 | if ($this->request->has('fantasy_name')) {
54 | $customer->fantasy_name = $this->request->get('fantasy_name');
55 | $save = true;
56 | }
57 |
58 | if ($this->request->has('general_register')) {
59 | $customer->general_register = $this->request->get('general_register');
60 | $save = true;
61 | }
62 |
63 | if ($save) {
64 | $customer->save();
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/src/Helper/Helper.php:
--------------------------------------------------------------------------------
1 |
6 | */
7 |
8 | namespace Cagartner\BrazilCustomer\Helper;
9 |
10 | /**
11 | * Class Helper
12 | * @package Cagartner\BrazilCustomer\Helper
13 | */
14 | class Helper
15 | {
16 | /**
17 | * Config path for Person Type
18 | */
19 | const CONFIG_PERSON_TYPE = 'customer.settings.brcustomer.person_type';
20 | /**
21 | * Config path for Show General Register
22 | */
23 | const CONFIG_SHOW_GENERAL_REGISTER = 'customer.settings.brcustomer_person.show_general_register';
24 | /**
25 | * Config path for Show State Register
26 | */
27 | const CONFIG_SHOW_STATE_REGISTER = 'customer.settings.brcustomer_company.show_state_register';
28 | /**
29 | * Config path for Show Fantasy Name
30 | */
31 | const CONFIG_SHOW_FANTASY_NAME = 'customer.settings.brcustomer_company.show_fantasy_name';
32 |
33 | /**
34 | * @return mixed
35 | */
36 | public static function getPersonType()
37 | {
38 | return core()->getConfigData(self::CONFIG_PERSON_TYPE);
39 | }
40 |
41 | /**
42 | * @return mixed
43 | */
44 | public static function isShowGeneralRegister()
45 | {
46 | return core()->getConfigData(self::CONFIG_SHOW_GENERAL_REGISTER);
47 | }
48 |
49 | /**
50 | * @return mixed
51 | */
52 | public static function isShowStateRegister()
53 | {
54 | return core()->getConfigData(self::CONFIG_SHOW_STATE_REGISTER);
55 | }
56 |
57 | /**
58 | * @return mixed
59 | */
60 | public static function isShowFantasyName()
61 | {
62 | return core()->getConfigData(self::CONFIG_SHOW_FANTASY_NAME);
63 | }
64 |
65 | /**
66 | * Clean all special characters from BrCustomer document field
67 | *
68 | * @param string $value
69 | * @return string
70 | */
71 | public static function clearDocumentString(string $value): string
72 | {
73 | $value = preg_replace('/[^0-9]/', '', $value);
74 | return $value;
75 | }
76 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Laravel eCommerce Brazil Customer
2 |
3 | Módulo criado para adicionar campos de Pessoa Física e Jurídica requeridos pela maioria de métodos de pagamentos do mercado brasileiro.
4 |
5 | **Campos adicionados:**
6 | * person_type enum(person,company) - Tipo de Pessoa
7 | * person - Física
8 | * company - Jurídica
9 | * document - CPF/CNPJ (Muda os labels de acordo com o Tipo de Pessoa selecionado)
10 | * state_register - Inscrição Estadual (Apenas para PJ)
11 | * company_name - Razão Social (Apenas para PJ)
12 | * fantasy_name - Nome Fantasia (Apenas para PJ)
13 | * general_register - RG
14 |
15 | ## Instalação
16 |
17 | 1- Run `composer require cagartner/bagisto-brazilcustomer` in your bagisto project
18 |
19 | 3- Rodar `php artisan migrate` adicionar os novos campos na tabela dos clientes.
20 |
21 | ## Configurações
22 |
23 | Para configurar seu módulo acesse: Admin > Configurar > Cliente > Campos Brasileiros.
24 |
25 | Configurações disponíveis:
26 |
27 | * **Tipo de Pessoas Habilitadas**: Você pode escolher habilitar Pessoa Física, Jurídica ou os dois na sua loja.
28 | * **Habilitar RG?**: Você habilita ou esconde o campo de RG na sua loja.
29 | * **Habilitar Inscrição Estadual?**:Você habilita ou esconde o campo de Inscrição Estadual na sua loja
30 | * **Habilitar Nome Fantasia?**:Você habilita ou esconde o campo de Nome Fantasia na sua loja
31 |
32 | ## Me pague uma cerveja:
33 |
34 | Se gostou do trabalho e quiser me pagar uma cerveja, pode me fazer uma doação pelo PicPay: @cagartner
35 |
36 | ## Conheça outros Packages para Bagisto
37 |
38 | * [Bagisto - Pagseguro](https://github.com/cagartner/bagisto-pagseguro)
39 | * [Bagisto - PicPay](https://github.com/cagartner/bagisto-picpay)
40 | * [Bagisto - Correios](https://github.com/cagartner/bagisto-correios)
41 |
42 | ## Conheça a comunidade Brasileira de Bagisto
43 | - [Portal Oficial](https://bagisto.com.br)
44 | - [Grupo do WhatsApp](https://chat.whatsapp.com/HpMKEoxf5neIfnpUlHGmaO)
45 | - [Grupo do Facebook](https://www.facebook.com/groups/2552301808420521)
46 | - [Grupo do Telegram](https://t.me/bagistobrasil)
47 | - [Twitter](http://twitter.com/bagistobr)
48 |
49 |
--------------------------------------------------------------------------------
/src/Config/system.php:
--------------------------------------------------------------------------------
1 | 'customer.settings.brcustomer',
5 | 'name' => 'Brazilian Customer Attributes',
6 | 'sort' => 100,
7 | 'fields' => [
8 | [
9 | 'name' => 'person_type',
10 | 'title' => 'Enabled Person Types',
11 | 'type' => 'multiselect',
12 | 'validation' => 'required',
13 | 'channel_based' => true,
14 | 'locale_based' => true,
15 | 'options' => [
16 | [
17 | 'title' => 'Person',
18 | 'value' => 'person'
19 | ], [
20 | 'title' => 'Company',
21 | 'value' => 'company'
22 | ],
23 | ],
24 | 'info' => 'Select the types of person enabled in the store'
25 | ]
26 | ]
27 | ], [
28 | 'key' => 'customer.settings.brcustomer_person',
29 | 'name' => 'Person configurations',
30 | 'sort' => 110,
31 | 'fields' => [
32 | [
33 | 'name' => 'show_general_register',
34 | 'title' => 'Enable General Register?',
35 | 'type' => 'boolean',
36 | 'channel_based' => true,
37 | 'locale_based' => true,
38 | ],
39 | ]
40 | ], [
41 | 'key' => 'customer.settings.brcustomer_company',
42 | 'name' => 'Company configurations',
43 | 'sort' => 120,
44 | 'fields' => [
45 | [
46 | 'name' => 'show_state_register',
47 | 'title' => 'Enable State Register?',
48 | 'type' => 'boolean',
49 | 'channel_based' => true,
50 | 'locale_based' => true,
51 | ],
52 | [
53 | 'name' => 'show_fantasy_name',
54 | 'title' => 'Enable Fantasy Name?',
55 | 'type' => 'boolean',
56 | 'channel_based' => true,
57 | 'locale_based' => true,
58 | ],
59 | ]
60 | ]
61 | ];
--------------------------------------------------------------------------------
/src/Providers/EventServiceProvider.php:
--------------------------------------------------------------------------------
1 | addTemplate('brcustomer::signup.person-type');
29 | });
30 |
31 | Event::listen('bagisto.shop.customers.account.profile.edit_form_controls.before', function($viewRenderEventManager) {
32 | $viewRenderEventManager->addTemplate('brcustomer::profile.person-type');
33 | });
34 |
35 | Event::listen('bagisto.shop.customers.account.profile.view.table.before', function($viewRenderEventManager) {
36 | $viewRenderEventManager->addTemplate('brcustomer::profile.index');
37 | });
38 |
39 | // Admin
40 | Event::listen('bagisto.admin.customers.create.before', function($viewRenderEventManager) {
41 | $viewRenderEventManager->addTemplate('brcustomer::signup.person-type');
42 | });
43 |
44 | Event::listen('bagisto.admin.customer.edit.form.before', function($viewRenderEventManager) {
45 | $viewRenderEventManager->addTemplate('brcustomer::profile.person-type');
46 | });
47 |
48 |
49 | // Update user info with news attributes
50 | Event::listen('customer.registration.after', CustomerAddCustomAttributesListener::class);
51 | Event::listen('customer.update.after', CustomerAddCustomAttributesListener::class);
52 |
53 | // Verify if the client have the new inputs informed
54 | Event::listen('customer.after.login', VerifyUserDataListener::class);
55 | Event::listen('checkout.load.index', VerifyUserDataListenerCheckout::class);
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/Resources/views/signup/person-type.blade.php:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 | @extends('brcustomer::scripts')
12 |
13 | @push('scripts')
14 |
140 |
141 |
187 | @endpush
188 |
189 |
190 |
191 |
192 |
193 |
194 |
--------------------------------------------------------------------------------
/src/Resources/views/profile/person-type.blade.php:
--------------------------------------------------------------------------------
1 | person_type;
8 | ?>
9 |
10 |
11 | @extends('brcustomer::scripts')
12 |
13 | @push('scripts')
14 |
143 |
144 |
190 | @endpush
191 |
192 |
193 |
194 |
195 |
196 |
197 |
--------------------------------------------------------------------------------