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 / ShippingMethodRequest.php

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

97 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\Modules\Shipping\Http\Requests;
4
5 use FluentCart\Framework\Foundation\RequestGuard;
6 use FluentCart\Framework\Support\Arr;
7
8 class ShippingMethodRequest extends RequestGuard
9 {
10
11 public function beforeValidation()
12 {
13 $data = $this->all();
14 $data['is_enabled'] = (string)(Arr::get($data, 'is_enabled', 0)) === '1' ? 1 : 0;
15 return $data;
16 }
17
18 /**
19 * @return array
20 */
21 public function rules()
22 {
23 return [
24 'zone_id' => 'required',
25 'title' => 'required|string|maxLength:192',
26 'amount' => 'nullable',
27 'type' => 'required|string|maxLength:192',
28 'settings' => 'nullable|array',
29 'states' => 'nullable|array',
30 'is_enabled' => 'nullable|integer|in:0,1',
31 'method_id' => 'nullable|integer',
32 'meta' => 'nullable|array',
33 ];
34 }
35
36 /**
37 * @return array
38 */
39 public function messages()
40 {
41 return [
42 'zone_id.required' => esc_html__('Shipping zone is required.', 'fluent-cart'),
43 'title.required' => esc_html__('Shipping method title is required.', 'fluent-cart'),
44 'type.required' => esc_html__('Shipping method type is required.', 'fluent-cart')
45 ];
46 }
47
48 /**
49 * @return array
50 */
51 public function sanitize()
52 {
53 return [
54 'zone_id' => 'intval',
55 'title' => 'sanitize_text_field',
56 'type' => 'sanitize_text_field',
57 'amount' => 'sanitize_text_field',
58 'is_enabled' => 'sanitize_text_field',
59 'method_id' => 'intval',
60 'states' => function ($value) {
61 if (is_array($value)) {
62 return array_map('sanitize_text_field', $value);
63 }
64 return $value;
65 },
66 'settings.configure_rate' => 'sanitize_text_field',
67 'settings.class_aggregation' => 'sanitize_text_field',
68 'settings.weight_tiers' => function ($value) {
69 if (!is_array($value)) {
70 return [];
71 }
72 return array_map(function ($tier) {
73 return [
74 'min' => floatval($tier['min'] ?? 0),
75 'max' => floatval($tier['max'] ?? 0),
76 'cost' => floatval($tier['cost'] ?? 0),
77 ];
78 }, $value);
79 },
80 'meta' => function ($value) {
81 if (!is_array($value)) {
82 return [];
83 }
84
85 $sanitized = [];
86 foreach ($value as $key => $val) {
87 if (is_string($val)) {
88 $sanitized[$key] = sanitize_text_field($val);
89 }
90 }
91 return $sanitized;
92 }
93 ];
94 }
95
96 }
97