PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.3.27
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.3.27
1.6.5 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 All 48 releases
fluent-cart / app / Http / Controllers / SettingsController.php

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

153 lines 4.3 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\App;
6 use FluentCart\Api\Helper;
7 use FluentCart\Api\Confirmation;
8 use FluentCart\Api\StoreSettings;
9 use FluentCart\Framework\Support\Arr;
10 use FluentCart\Framework\Http\Request\Request;
11 use FluentCart\App\Helpers\EditorShortCodeHelper;
12 use FluentCart\App\Http\Requests\FluentMetaRequest;
13
14 class SettingsController extends Controller
15 {
16 public function getStore(Request $request, StoreSettings $storeSettings)
17 {
18 $data = ($storeSettings->get());
19
20 $tab = $request->get('settings_name');
21 $currenttabFields = Arr::get($storeSettings->fields(), 'setting_tabs.schema.' . $tab);
22
23 if (!App::isProActive()) {
24 $data['show_email_footer'] = 'yes';
25 }
26
27 return [
28 'settings' => $data,
29 'fields' => [
30 $tab => $currenttabFields
31 ]
32 ];
33 }
34
35 public function saveStore(FluentMetaRequest $request, StoreSettings $storeSettings)
36 {
37 $storeLogo = $request->get('store_logo');
38 if($storeLogo){
39 $storeLogo = [
40 'id' => sanitize_text_field(Arr::get($storeLogo, 'id')),
41 'url' => sanitize_url(Arr::get($storeLogo, 'url')),
42 'title' => sanitize_text_field(Arr::get($storeLogo, 'title')),
43 ];
44 }else{
45 $storeLogo = '';
46 }
47 try {
48 // $data = $request->getSafe($request->sanitize());
49 // $data['store_logo'] = $storeLogo;
50 // $data = array_merge(
51 // $storeSettings->get(),
52 // $data
53 // );
54
55 $sanitizeMap = $request->sanitize();
56 $data = $request->all();
57 $sanitizedData = [];
58
59
60 foreach ($data as $key => $value) {
61 $sanitizer = Arr::get($sanitizeMap, $key);
62 if (!$sanitizer) {
63 continue;
64 }
65 $sanitizedData[$key] = call_user_func($sanitizer, $value);
66 }
67
68 $data = array_merge(
69 $storeSettings->get(),
70 $sanitizedData
71 );
72
73 // $data = Arr::get($data, 'settings', []);
74 // $frontendTheme = $request->get('settings.frontend_theme');
75 $frontendTheme = $request->get('frontend_theme');
76
77 // Check if frontendTheme is an array before using it in foreach
78 if (is_array($frontendTheme)) {
79 foreach ($frontendTheme as $key => $value) {
80 $data['frontend_theme'][$key] = sanitize_hex_color($value);
81 }
82 }
83
84 $data['require_logged_in'] = 'no';
85
86
87 $saved = $storeSettings->save($data);
88
89
90 return $this->sendSuccess([
91 'data' => $saved
92 ], 423);
93 } catch (\Exception $e) {
94 $this->sendError([
95 'message' => $e->getMessage()
96 ], 423);
97 }
98 }
99
100 public function getConfirmation()
101 {
102 $confirmations = new Confirmation();
103 return array(
104 'settings' => $confirmations->get(null, [
105 'confirmation_page_id' => (new StoreSettings())->getReceiptPageId()
106 ]),
107 'fields' => $confirmations->fields()
108 );
109 }
110
111 public function saveConfirmation(Request $request)
112 {
113 try {
114 return (new Confirmation())->save($request->settings);
115 } catch (\Exception $e) {
116 $this->sendError([
117 'message' => $e->getMessage()
118 ], 423);
119 }
120 }
121
122 public function getShortcode(): array
123 {
124 return [
125 'data' => EditorShortCodeHelper::getEmailNotificationShortcodes()
126 ];
127 }
128
129 public function getPermissions()
130 {
131 try {
132 $roles = Helper::getPermittedRoles();
133 } catch (\Exception $e) {
134 return $this->sendError([
135 'message' => $e->getMessage()
136 ], 423);
137 }
138
139 return array('roles' => $roles);
140 }
141
142 public function savePermissions(Request $request)
143 {
144 try {
145 return Helper::savePermissions($request->capability);
146 } catch (\Exception $e) {
147 $this->sendError([
148 'message' => $e->getMessage()
149 ], 423);
150 }
151 }
152 }
153