| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\App\Http\Controllers; |
| 4 |
|
| 5 |
use FluentCart\App\Services\Renderer\CheckoutFieldsSchema; |
| 6 |
use FluentCart\Framework\Http\Request\Request; |
| 7 |
use FluentCart\Framework\Support\Arr; |
| 8 |
|
| 9 |
class CheckoutFieldsController extends Controller |
| 10 |
{ |
| 11 |
|
| 12 |
public function getFields() |
| 13 |
{ |
| 14 |
return [ |
| 15 |
'fields' => CheckoutFieldsSchema::getFieldsSchemaConfig(), |
| 16 |
'settings' => CheckoutFieldsSchema::getFieldsSettings(), |
| 17 |
]; |
| 18 |
} |
| 19 |
|
| 20 |
public function saveFields(Request $request) |
| 21 |
{ |
| 22 |
$settings = $request->get('settings', []); |
| 23 |
$prevSettings = CheckoutFieldsSchema::getFieldsSettings(); |
| 24 |
|
| 25 |
$settings = Arr::only($settings, array_keys($prevSettings)); |
| 26 |
|
| 27 |
$isFirstNameEnabled = Arr::get($settings, 'basic_info.first_name.enabled', 'no') === 'yes'; |
| 28 |
$isLastNameEnabled = Arr::get($settings, 'basic_info.last_name.enabled', 'no') === 'yes'; |
| 29 |
//if any of first_name and last_name is enabled, we won't show full name |
| 30 |
if ($isFirstNameEnabled || $isLastNameEnabled) { |
| 31 |
Arr::set($settings, 'basic_info.full_name.enabled', 'no'); |
| 32 |
Arr::set($settings, 'basic_info.full_name.required', 'no'); |
| 33 |
} else { |
| 34 |
//else forcefully enable full_name |
| 35 |
Arr::set($settings, 'basic_info.full_name.enabled', 'yes'); |
| 36 |
Arr::set($settings, 'basic_info.full_name.required', 'yes'); |
| 37 |
} |
| 38 |
|
| 39 |
if ($isFirstNameEnabled) { |
| 40 |
Arr::set($settings, 'basic_info.first_name.required', 'yes'); |
| 41 |
} else if ($isLastNameEnabled) { |
| 42 |
Arr::set($settings, 'basic_info.last_name.required', 'yes'); |
| 43 |
} |
| 44 |
|
| 45 |
fluent_cart_update_option('_fc_checkout_fields', $settings); |
| 46 |
|
| 47 |
return [ |
| 48 |
'message' => __('Checkout fields has been updated successfully.', 'fluent-cart'), |
| 49 |
]; |
| 50 |
} |
| 51 |
|
| 52 |
} |
| 53 |
|