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 / Modules / Shipping / Http / Requests / ShippingClassRequest.php

ShippingClassRequest.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.6.4, at app/Modules/Shipping/Http/Requests/ShippingClassRequest.php

60 lines 1.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\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