Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Listen to all customer address configuration #373

Merged
merged 7 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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', false) && 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', false) === 'opt')
indykoning marked this conversation as resolved.
Show resolved Hide resolved
<option value=""></option>
@endif
@foreach(explode(';', Rapidez::config('customer/address/prefix_options', '')) as $prefix)
<option value="{{ $prefix }}">
{{ __($prefix) }}
indykoning marked this conversation as resolved.
Show resolved Hide resolved
</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', false) && 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', false) === 'opt')
indykoning marked this conversation as resolved.
Show resolved Hide resolved
<option value=""></option>
@endif
@foreach(explode(';', Rapidez::config('customer/address/suffix_options', '')) as $suffix)
<option value="{{ $suffix }}">
{{ __($suffix) }}
indykoning marked this conversation as resolved.
Show resolved Hide resolved
</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/prefix_show', 'opt') : 'opt',
Jade-GG marked this conversation as resolved.
Show resolved Hide resolved
'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'),
];
}
}
Loading