| 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 |
|