Skip to content

Commit

Permalink
Implemented customer address prefix, suffix, vat_id and fax (#373)
Browse files Browse the repository at this point in the history
  • Loading branch information
indykoning authored Nov 7, 2023
1 parent 1862894 commit d75cb0c
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 5 deletions.
2 changes: 1 addition & 1 deletion config/rapidez/frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
'notifications',
'checkout_steps',
'flushable_localstorage_keys',
'customer_fields_show',
'show_customer_address_fields',
],

// The checkout steps which are used to name the steps
Expand Down
4 changes: 3 additions & 1 deletion resources/js/components/Checkout/Checkout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,9 @@ export default {
}
const optionalFields = Object.keys(
Object.fromEntries(Object.entries(window.config.customer_fields_show).filter(([key, value]) => !value || value === 'opt')),
Object.fromEntries(
Object.entries(window.config.show_customer_address_fields).filter(([key, value]) => !value || value === 'opt'),
),
)
Object.entries(this.checkout.shipping_address).forEach(([key, val]) => {
if (!val && !['region_id', 'customer_address_id', 'same_as_billing'].concat(optionalFields).includes(key)) {
Expand Down
50 changes: 49 additions & 1 deletion resources/views/checkout/partials/address.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,25 @@
</div>

<div class="contents" v-if="!$root.loggedIn || !checkout.{{ $type }}_address.customer_address_id">
@if(Rapidez::config('customer/address/prefix_show', '') && strlen(Rapidez::config('customer/address/prefix_options', '')))
<div class="col-span-12">
<x-rapidez::select
name="{{ $type }}_prefix"
label="Prefix"
v-model="checkout.{{ $type }}_address.prefix"
:required="Rapidez::config('customer/address/prefix_show', 'opt') == 'req'"
>
@if(Rapidez::config('customer/address/prefix_show', '') === 'opt')
<option value=""></option>
@endif
@foreach(explode(';', Rapidez::config('customer/address/prefix_options', '')) as $prefix)
<option value="{{ $prefix }}">
@lang($prefix)
</option>
@endforeach
</x-rapidez::select>
</div>
@endif
<div class="col-span-12 {{ Rapidez::config('customer/address/middlename_show', 0) ? 'sm:col-span-4' : 'sm:col-span-6' }}">
<x-rapidez::input
label="Firstname"
Expand All @@ -41,6 +60,25 @@
required
/>
</div>
@if(Rapidez::config('customer/address/suffix_show', '') && strlen(Rapidez::config('customer/address/suffix_options', '')))
<div class="col-span-12">
<x-rapidez::select
name="{{ $type }}_suffix"
label="Suffix"
v-model="checkout.{{ $type }}_address.suffix"
:required="Rapidez::config('customer/address/suffix_show', 'opt') == 'req'"
>
@if(Rapidez::config('customer/address/suffix_show', '') === 'opt')
<option value=""></option>
@endif
@foreach(explode(';', Rapidez::config('customer/address/suffix_options', '')) as $suffix)
<option value="{{ $suffix }}">
@lang($suffix)
</option>
@endforeach
</x-rapidez::select>
</div>
@endif
<div class="col-span-6 sm:col-span-3">
<x-rapidez::input
name="{{ $type }}_postcode"
Expand Down Expand Up @@ -102,8 +140,18 @@
/>
</div>
@endif
@if(Rapidez::config('customer/address/company_show', 'opt'))
@if(Rapidez::config('customer/address/fax_show', false))
<div class="col-span-12 sm:col-span-6">
<x-rapidez::input
name="{{ $type }}_fax"
label="Fax"
v-model.lazy="checkout.{{ $type }}_address.fax"
:required="Rapidez::config('customer/address/fax_show', false) === 'req'"
/>
</div>
@endif
@if(Rapidez::config('customer/address/company_show', 'opt'))
<div class="col-span-12 sm:col-span-6 sm:col-start-1">
<x-rapidez::input
name="{{ $type }}_company"
label="Company"
Expand Down
8 changes: 6 additions & 2 deletions src/Http/ViewComposers/ConfigComposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,19 @@ public function compose(View $view)
Config::set('frontend.translations', __('rapidez::frontend'));
Config::set('frontend.recaptcha', Rapidez::config('recaptcha_frontend/type_recaptcha_v3/public_key', null, true));
Config::set('frontend.searchable', array_merge($searchableAttributes, config('rapidez.indexer.searchable')));
Config::set('frontend.customer_fields_show', $this->getCustomerFields());
Config::set('frontend.show_customer_address_fields', $this->getCustomerAddressFields());
Config::set('frontend.grid_per_page', Rapidez::config('catalog/frontend/grid_per_page', 12));
Config::set('frontend.grid_per_page_values', explode(',', Rapidez::config('catalog/frontend/grid_per_page_values', '12,24,36')));
}

public function getCustomerFields()
public function getCustomerAddressFields()
{
return [
'prefix' => strlen(Rapidez::config('customer/address/prefix_options', '')) ? Rapidez::config('customer/address/prefix_show', 'opt') : 'opt',
'firstname' => 'req',
'middlename' => Rapidez::config('customer/address/middlename_show', 0) ? 'opt' : false,
'lastname' => 'req',
'suffix' => strlen(Rapidez::config('customer/address/suffix_options', '')) ? Rapidez::config('customer/address/suffix_show', 'opt') : 'opt',
'postcode' => 'req',
'housenumber' => Rapidez::config('customer/address/street_lines', 3) >= 2 ? 'req' : false,
'addition' => Rapidez::config('customer/address/street_lines', 3) >= 3 ? 'opt' : false,
Expand All @@ -58,6 +60,8 @@ public function getCustomerFields()
'country_id' => 'req',
'telephone' => Rapidez::config('customer/address/telephone_show', 'req'),
'company' => Rapidez::config('customer/address/company_show', 'opt'),
'vat_id' => Rapidez::config('customer/address/taxvat_show', 'opt'),
'fax' => Rapidez::config('customer/address/fax_show', 'opt'),
];
}
}

0 comments on commit d75cb0c

Please sign in to comment.