PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.3.21
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.3.21
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 / Requests / FrontendRequests / CustomerRequests / CustomerProfileRequest.php

CustomerProfileRequest.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.3.21, at app/Http/Requests/FrontendRequests/CustomerRequests/CustomerProfileRequest.php

118 lines 4.5 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\Requests\FrontendRequests\CustomerRequests;
4
5 use FluentCart\Framework\Foundation\RequestGuard;
6 use FluentCart\Framework\Support\Arr;
7
8 class CustomerProfileRequest extends RequestGuard
9 {
10
11 public function beforeValidation()
12 {
13 $data = $this->all();
14 if (empty(Arr::get($data, 'status'))) {
15 $data['status'] = 'active';
16 }
17 if (empty(Arr::get($data, 'is_primary'))) {
18 $data['is_primary'] = 0;
19 }
20 return $data;
21 }
22
23 /**
24 * @return array
25 */
26 public function rules()
27 {
28
29 return [
30 'label' => 'nullable|sanitizeText|maxLength:15',
31 'name' => 'required|sanitizeText|maxLength:255',
32 'address_1' => 'nullable|sanitizeTextArea',
33 'address_2' => 'nullable|sanitizeTextArea',
34 'city' => 'nullable|sanitizeText|maxLength:255',
35 'state' => 'nullable|sanitizeText|maxLength:255',
36 'postcode' => 'required|sanitizeText',
37 'country' => 'required|sanitizeText',
38 'first_name' => 'sanitizeText|maxLength:255',
39 'last_name' => 'sanitizeText|maxLength:255',
40 'email' => 'required|email',
41 'current_password' => 'sanitizeText|nullable',
42 'new_password' => 'sanitizeText|nullable',
43 'confirm_new_password' => 'sanitizeText|nullable',
44 'company_name' => 'nullable|sanitizeText|maxLength:255',
45 ];
46 }
47
48 /**
49 * @return array
50 */
51 public function messages()
52 {
53 return [
54 'name.required' => esc_html__('Name field is required.', 'fluent-cart'),
55 'address_1.required' => esc_html__('Street Address is required.', 'fluent-cart'),
56 'city.required' => esc_html__('City field is required.', 'fluent-cart'),
57 'postcode.required' => esc_html__('Postcode field is required.', 'fluent-cart'),
58 'country.required' => esc_html__('Country field is required.', 'fluent-cart'),
59 'email.required' => esc_html__('Email field is required.', 'fluent-cart')
60 ];
61 }
62
63 /**
64 * @return array
65 */
66 public function sanitize()
67 {
68 return [
69 'label' => 'sanitize_text_field',
70 'type' => 'sanitize_text_field',
71 'name' => 'sanitize_text_field',
72 'first_name' => 'sanitize_text_field',
73 'last_name' => 'sanitize_text_field',
74 'new_password' => '',
75 'current_password' => '',
76 'confirm_new_password' => '',
77 'address_1' => 'sanitize_text_field',
78 'address_2' => 'sanitize_text_field',
79 'city' => 'sanitize_text_field',
80 'state' => 'sanitize_text_field',
81 'phone' => 'sanitize_text_field',
82 'postcode' => 'sanitize_text_field',
83 'country' => 'sanitize_text_field',
84 'email' => function ($value) {
85 if(empty($value)) {
86 return '';
87 }
88
89 return sanitize_email($value);
90 },
91 'status' => 'sanitize_text_field',
92 'userId' => 'sanitize_text_field',
93 'customerId' => 'sanitize_text_field',
94 'company_name' => 'sanitize_text_field',
95
96 'address.type' => 'sanitize_text_field',
97 'address.name' => 'sanitize_text_field',
98 'address.address_1' => 'sanitize_text_field',
99 'address.address_2' => 'sanitize_text_field',
100 'address.city' => 'sanitize_text_field',
101 'address.state' => 'sanitize_text_field',
102 'address.phone' => 'sanitize_text_field',
103 'address.postcode' => 'sanitize_text_field',
104 'address.country' => 'sanitize_text_field',
105 'address.email' => function ($value) {
106 if(empty($value)) {
107 return '';
108 }
109
110 return sanitize_email($value);
111 },
112 'address.is_primary' => 'sanitize_text_field',
113 'address.status' => 'sanitize_text_field',
114 'address.company_name' => 'sanitize_text_field',
115 ];
116 }
117 }
118