PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.3.20
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.3.20
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 / CustomerAddressRequest.php

CustomerAddressRequest.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.3.20, at app/Http/Requests/CustomerAddressRequest.php

87 lines 3.1 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;
4
5 use FluentCart\App\App;
6 use FluentCart\Framework\Foundation\RequestGuard;
7 use FluentCart\Framework\Support\Arr;
8
9 class CustomerAddressRequest extends RequestGuard
10 {
11 public function beforeValidation()
12 {
13 $data = $this->all();
14 $data['status'] = Arr::get($data, 'status', 'active');
15 $data['is_primary'] = Arr::get($data, 'is_primary', 0);
16 return $data;
17 }
18
19 /**
20 * @return array
21 */
22 public function rules()
23 {
24 $validationRules = App::localization()->getValidationRule($this->all(), null, [
25 'country' => 'required|sanitizeText'
26 ]);
27
28 return array_merge($validationRules, [
29 'label' => 'nullable|sanitizeText|maxLength:15',
30 'name' => 'required|sanitizeText|maxLength:255',
31 'email' => 'required|sanitizeText|email|maxLength:255',
32 'address_1' => 'required|sanitizeText',
33 'address_2' => 'nullable|sanitizeText',
34 'city' => 'required|sanitizeText|maxLength:255',
35 'is_primary' => 'nullable|numeric',
36 'company_name' => 'nullable|sanitizeText|maxLength:255',
37 ]);
38 }
39
40 /**
41 * @return array
42 */
43 public function messages()
44 {
45 return [
46 'name.required' => esc_html__('Name field is required.', 'fluent-cart'),
47 'email.required' => esc_html__('Email field is required.', 'fluent-cart'),
48 'email.email' => esc_html__('Email must be a valid email address.', 'fluent-cart'),
49 'address_1.required' => esc_html__('Street Address field is required.', 'fluent-cart'),
50 'city.required' => esc_html__('City field is required.', 'fluent-cart'),
51 'postcode.required' => esc_html__('Postcode field is required.', 'fluent-cart'),
52 'country.required' => esc_html__('Country field is required.', 'fluent-cart'),
53 'state.required' => esc_html__('State field is required.', 'fluent-cart'),
54 'label.max' => esc_html__('Label may not be greater than 15 characters.', 'fluent-cart')
55 ];
56 }
57
58 /**
59 * @return array
60 */
61 public function sanitize()
62 {
63 return [
64 'label' => 'sanitize_text_field',
65 'type' => 'sanitize_text_field',
66 'status' => 'sanitize_text_field',
67 'name' => 'sanitize_text_field',
68 'address_1' => 'sanitize_text_field',
69 'address_2' => 'sanitize_text_field',
70 'city' => 'sanitize_text_field',
71 'state' => 'sanitize_text_field',
72 'phone' => 'sanitize_text_field',
73 'postcode' => 'sanitize_text_field',
74 'country' => 'sanitize_text_field',
75 'email' => function ($value) {
76 if(empty($value)) {
77 return '';
78 }
79
80 return sanitize_email($value);
81 },
82 'is_primary' => 'intval',
83 'company_name' => 'sanitize_text_field',
84 ];
85 }
86 }
87