PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.4
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.4
1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 trunk 1.2.0 All 47 releases
fluent-cart / app / Http / Controllers / CheckoutFieldsController.php

CheckoutFieldsController.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.6.4, at app/Http/Controllers/CheckoutFieldsController.php

53 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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