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 / Requests / FrontendRequests / CustomerRequests / CustomerProfileRequest.php

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

143 lines 6.0 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\App\Services\Renderer\CheckoutFieldsSchema;
6 use FluentCart\Framework\Foundation\RequestGuard;
7 use FluentCart\Framework\Support\Arr;
8
9 class CustomerProfileRequest extends RequestGuard
10 {
11
12 public function beforeValidation()
13 {
14 $data = $this->all();
15 if (empty(Arr::get($data, 'status'))) {
16 $data['status'] = 'active';
17 }
18 if (empty(Arr::get($data, 'is_primary'))) {
19 $data['is_primary'] = 0;
20 }
21 return $data;
22 }
23
24 /**
25 * @return array
26 */
27 public function rules()
28 {
29 $rules = [
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 'vat_number' => 'nullable|sanitizeText|maxLength:255',
46 'legal_registration_id' => 'nullable|sanitizeText|maxLength:255',
47 ];
48
49 if (Arr::get($this->all(), 'type') === 'billing') {
50 if (CheckoutFieldsSchema::isCompanyNameEnabled() && CheckoutFieldsSchema::isCompanyNameRequired()) {
51 $rules['company_name'] = 'required|sanitizeText|maxLength:255';
52 }
53
54 if (CheckoutFieldsSchema::isVatNumberEnabled() && CheckoutFieldsSchema::isVatNumberRequired()) {
55 $rules['vat_number'] = 'required|sanitizeText|maxLength:255';
56 }
57
58 if (CheckoutFieldsSchema::isLegalRegistrationIdEnabled() && CheckoutFieldsSchema::isLegalRegistrationIdRequired()) {
59 $rules['legal_registration_id'] = 'required|sanitizeText|maxLength:255';
60 }
61 }
62
63 return $rules;
64 }
65
66 /**
67 * @return array
68 */
69 public function messages()
70 {
71 return [
72 'name.required' => esc_html__('Name field is required.', 'fluent-cart'),
73 'address_1.required' => esc_html__('Street Address is required.', 'fluent-cart'),
74 'city.required' => esc_html__('City field is required.', 'fluent-cart'),
75 'postcode.required' => esc_html__('Postcode field is required.', 'fluent-cart'),
76 'country.required' => esc_html__('Country field is required.', 'fluent-cart'),
77 'email.required' => esc_html__('Email field is required.', 'fluent-cart'),
78 'company_name.required' => esc_html__('Company Name field is required.', 'fluent-cart'),
79 'vat_number.required' => esc_html__('VAT/GST/Tax Number field is required.', 'fluent-cart'),
80 'legal_registration_id.required' => esc_html__('Legal Registration ID field is required.', 'fluent-cart')
81 ];
82 }
83
84 /**
85 * @return array
86 */
87 public function sanitize()
88 {
89 return [
90 'label' => 'sanitize_text_field',
91 'type' => 'sanitize_text_field',
92 'name' => 'sanitize_text_field',
93 'first_name' => 'sanitize_text_field',
94 'last_name' => 'sanitize_text_field',
95 'new_password' => '',
96 'current_password' => '',
97 'confirm_new_password' => '',
98 'address_1' => 'sanitize_text_field',
99 'address_2' => 'sanitize_text_field',
100 'city' => 'sanitize_text_field',
101 'state' => 'sanitize_text_field',
102 'phone' => 'sanitize_text_field',
103 'postcode' => 'sanitize_text_field',
104 'country' => 'sanitize_text_field',
105 'email' => function ($value) {
106 if(empty($value)) {
107 return '';
108 }
109
110 return sanitize_email($value);
111 },
112 'status' => 'sanitize_text_field',
113 'userId' => 'sanitize_text_field',
114 'customerId' => 'sanitize_text_field',
115 'company_name' => 'sanitize_text_field',
116 'vat_number' => 'sanitize_text_field',
117 'legal_registration_id' => 'sanitize_text_field',
118
119 'address.type' => 'sanitize_text_field',
120 'address.name' => 'sanitize_text_field',
121 'address.address_1' => 'sanitize_text_field',
122 'address.address_2' => 'sanitize_text_field',
123 'address.city' => 'sanitize_text_field',
124 'address.state' => 'sanitize_text_field',
125 'address.phone' => 'sanitize_text_field',
126 'address.postcode' => 'sanitize_text_field',
127 'address.country' => 'sanitize_text_field',
128 'address.email' => function ($value) {
129 if(empty($value)) {
130 return '';
131 }
132
133 return sanitize_email($value);
134 },
135 'address.is_primary' => 'sanitize_text_field',
136 'address.status' => 'sanitize_text_field',
137 'address.company_name' => 'sanitize_text_field',
138 'address.vat_number' => 'sanitize_text_field',
139 'address.legal_registration_id' => 'sanitize_text_field',
140 ];
141 }
142 }
143