| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\App\Modules\Shipping\Http\Requests; |
| 4 |
|
| 5 |
use FluentCart\Framework\Foundation\RequestGuard; |
| 6 |
use FluentCart\Framework\Support\Arr; |
| 7 |
|
| 8 |
class ShippingClassRequest extends RequestGuard |
| 9 |
{ |
| 10 |
|
| 11 |
public function beforeValidation() |
| 12 |
{ |
| 13 |
$data = $this->all(); |
| 14 |
|
| 15 |
$data['per_item'] = (string)(Arr::get($data, 'per_item', 0)) === '1' ? 1 : 0; |
| 16 |
return $data; |
| 17 |
} |
| 18 |
|
| 19 |
/** |
| 20 |
* @return array |
| 21 |
*/ |
| 22 |
public function rules() |
| 23 |
{ |
| 24 |
return [ |
| 25 |
'name' => 'required|string|maxLength:192', |
| 26 |
'description' => 'nullable|string|maxLength:500', |
| 27 |
'cost' => 'required|numeric|min:0', |
| 28 |
'type' => 'required|string|in:fixed,percentage', |
| 29 |
'per_item' => 'nullable|integer|in:0,1', |
| 30 |
]; |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* @return array |
| 35 |
*/ |
| 36 |
public function messages() |
| 37 |
{ |
| 38 |
return [ |
| 39 |
'name.required' => esc_html__('Shipping class name is required.', 'fluent-cart'), |
| 40 |
'cost.required' => esc_html__('Shipping class cost is required.', 'fluent-cart'), |
| 41 |
'type.required' => esc_html__('Shipping class type is required.', 'fluent-cart') |
| 42 |
]; |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* @return array |
| 47 |
*/ |
| 48 |
public function sanitize() |
| 49 |
{ |
| 50 |
return [ |
| 51 |
'name' => 'sanitize_text_field', |
| 52 |
'description' => 'sanitize_textarea_field', |
| 53 |
'cost' => 'sanitize_text_field', |
| 54 |
'type' => 'sanitize_text_field', |
| 55 |
'per_item' => 'intval' |
| 56 |
]; |
| 57 |
} |
| 58 |
|
| 59 |
} |
| 60 |
|