| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\App\Http\Requests; |
| 4 |
|
| 5 |
use FluentCart\Framework\Foundation\RequestGuard; |
| 6 |
|
| 7 |
class OrderRequest extends RequestGuard |
| 8 |
{ |
| 9 |
|
| 10 |
/** |
| 11 |
* @return array |
| 12 |
*/ |
| 13 |
public function rules(): array |
| 14 |
{ |
| 15 |
return [ |
| 16 |
'status' => 'nullable|sanitizeText|maxLength:50', |
| 17 |
'invoice_no' => 'nullable|sanitizeText|maxLength:100', |
| 18 |
'fulfillment_type' => 'nullable|sanitizeText|maxLength:50', |
| 19 |
'type' => 'nullable|sanitizeText|maxLength:50', |
| 20 |
'payment_method' => 'nullable|sanitizeText|maxLength:50', |
| 21 |
'payment_method_title' => 'nullable|sanitizeText|maxLength:50', |
| 22 |
'payment_status' => 'nullable|sanitizeText|maxLength:50', |
| 23 |
'currency' => 'nullable|sanitizeText|maxLength:10', |
| 24 |
'subtotal' => 'numeric', |
| 25 |
'discount_tax' => 'numeric', |
| 26 |
'manual_discount_total' => 'numeric', |
| 27 |
'coupon_discount_total' => 'numeric', |
| 28 |
'shipping_tax' => 'numeric', |
| 29 |
'shipping_total' => 'numeric', |
| 30 |
'tax_total' => 'numeric', |
| 31 |
'total_amount' => 'numeric', |
| 32 |
'rate' => 'numeric', |
| 33 |
'note' => 'nullable|sanitizeTextArea|maxLength:5000', |
| 34 |
'uuid' => 'nullable|sanitizeText|maxLength:100', |
| 35 |
'ip_address' => 'nullable|sanitizeText|maxLength:100', |
| 36 |
'completed_at' => 'nullable|sanitizeText|maxLength:100', |
| 37 |
'refunded_at' => 'nullable|sanitizeText|maxLength:100', |
| 38 |
'customer_id' => 'required|numeric', |
| 39 |
'user_tz' => 'nullable|sanitizeText|maxLength:50', |
| 40 |
|
| 41 |
'order_items' => 'required|array', |
| 42 |
"order_items.*.id" => 'numeric|min:1', |
| 43 |
"order_items.*.order_id" => 'numeric|min:1', |
| 44 |
"order_items.*.post_id" => 'numeric|min:1', |
| 45 |
"order_items.*.variation_id" => 'numeric|min:1', |
| 46 |
"order_items.*.object_id" => 'numeric|min:1', |
| 47 |
"order_items.*.fulfillment_type" => 'nullable|sanitizeText', |
| 48 |
"order_items.*.payment_type" => 'nullable|sanitizeText|maxLength:100', |
| 49 |
"order_items.*.quantity" => 'numeric|min:1', |
| 50 |
"order_items.*.post_title" => 'nullable|sanitizeText|maxLength:255', |
| 51 |
"order_items.*.title" => 'nullable|sanitizeText|maxLength:255', |
| 52 |
"order_items.*.price" => 'numeric', |
| 53 |
"order_items.*.unit_price" => 'numeric', |
| 54 |
"order_items.*.shipping_charge" => 'nullable|numeric', |
| 55 |
"order_items.*.item_cost" => 'numeric', |
| 56 |
"order_items.*.item_total" => 'numeric', |
| 57 |
"order_items.*.tax_amount" => 'numeric', |
| 58 |
"order_items.*.discount_total" => 'numeric', |
| 59 |
"order_items.*.total" => 'numeric', |
| 60 |
"order_items.*.line_total" => 'numeric', |
| 61 |
"order_items.*.cart_index" => 'nullable|numeric', |
| 62 |
"order_items.*.rate" => 'nullable|numeric', |
| 63 |
"order_items.*.line_meta" => 'nullable|array', |
| 64 |
"order_items.*.other_info" => 'nullable|array', |
| 65 |
|
| 66 |
"discount.type" => 'nullable|sanitizeText|maxLength:100', |
| 67 |
"discount.value" => 'nullable|numeric', |
| 68 |
"discount.label" => 'nullable|sanitizeText|maxLength:100', |
| 69 |
"discount.reason" => 'nullable|sanitizeText|maxLength:100', |
| 70 |
"discount.action" => 'nullable|sanitizeText|maxLength:100', |
| 71 |
|
| 72 |
'shipping' => 'nullable|array', |
| 73 |
"shipping.*.type" => 'nullable|sanitizeText|maxLength:100', |
| 74 |
"shipping.*.rate_name" => 'nullable|sanitizeText|maxLength:100', |
| 75 |
"shipping.*.custom_price" => 'nullable|numeric', |
| 76 |
|
| 77 |
'deletedItems' => 'nullable|array', |
| 78 |
|
| 79 |
'applied_coupon' => 'nullable|array', |
| 80 |
"applied_coupon.*.id" => 'nullable|numeric|min:1', |
| 81 |
"applied_coupon.*.order_id" => 'nullable|numeric|min:1', |
| 82 |
"applied_coupon.*.coupon_id" => 'required|numeric|min:1', |
| 83 |
//"applied_coupon.*.title" => 'required|string|max:100', |
| 84 |
"applied_coupon.*.code" => 'required|sanitizeText|maxLength:100', |
| 85 |
//"applied_coupon.*.status" => 'required|string|max:100', |
| 86 |
//"applied_coupon.*.type" => 'required|string|max:100', |
| 87 |
"applied_coupon.*.amount" => 'nullable|numeric', |
| 88 |
"applied_coupon.*.discounted_amount" => 'required|numeric', |
| 89 |
"applied_coupon.*.discount" => 'nullable|numeric', |
| 90 |
"applied_coupon.*.stackable" => 'required|numeric', |
| 91 |
"applied_coupon.*.priority" => 'nullable|numeric', |
| 92 |
"applied_coupon.*.max_uses" => 'nullable|numeric', |
| 93 |
"applied_coupon.*.use_count" => 'nullable|numeric', |
| 94 |
"applied_coupon.*.max_per_customer" => 'nullable|numeric|min:1', |
| 95 |
"applied_coupon.*.min_purchase_amount" => 'nullable|numeric', |
| 96 |
"applied_coupon.*.max_discount_amount" => 'nullable|numeric', |
| 97 |
"applied_coupon.*.notes" => 'nullable|sanitizeTextArea|maxLength:100', |
| 98 |
'trigger' => 'nullable|string', |
| 99 |
]; |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
/** |
| 104 |
* @return array |
| 105 |
*/ |
| 106 |
public function messages(): array |
| 107 |
{ |
| 108 |
return [ |
| 109 |
'customer_id.required' => esc_html__('Customer selection is required', 'fluent-cart'), |
| 110 |
'order_items.required' => esc_html__('Item selection is required', 'fluent-cart'), |
| 111 |
]; |
| 112 |
} |
| 113 |
|
| 114 |
|
| 115 |
/** |
| 116 |
* @return array |
| 117 |
*/ |
| 118 |
public function sanitize() |
| 119 |
{ |
| 120 |
return [ |
| 121 |
'id' => 'intval', |
| 122 |
'status' => 'sanitize_text_field', |
| 123 |
'invoice_no' => 'sanitize_text_field', |
| 124 |
'fulfillment_type' => 'sanitize_text_field', |
| 125 |
'type' => 'sanitize_text_field', |
| 126 |
'customer_id' => 'intval', |
| 127 |
'payment_method' => 'sanitize_text_field', |
| 128 |
'payment_method_title' => 'sanitize_text_field', |
| 129 |
'payment_status' => 'sanitize_text_field', |
| 130 |
'currency' => 'sanitize_text_field', |
| 131 |
'subtotal' => 'floatval', |
| 132 |
'discount_tax' => 'floatval', |
| 133 |
'manual_discount_total' => 'floatval', |
| 134 |
'coupon_discount_total' => 'floatval', |
| 135 |
'shipping_tax' => 'floatval', |
| 136 |
'shipping_total' => 'floatval', |
| 137 |
'tax_total' => 'floatval', |
| 138 |
'total_amount' => 'floatval', |
| 139 |
'rate' => 'sanitize_text_field', |
| 140 |
'note' => 'sanitize_text_field', |
| 141 |
'uuid' => 'sanitize_text_field', |
| 142 |
'ip_address' => 'sanitize_text_field', |
| 143 |
'billing_address_id' => 'intval', |
| 144 |
'shipping_address_id' => 'intval', |
| 145 |
'completed_at' => 'sanitize_text_field', |
| 146 |
'refunded_at' => 'sanitize_text_field', |
| 147 |
'user_tz' => 'sanitize_text_field', |
| 148 |
|
| 149 |
"order_items.*.id" => 'intval', |
| 150 |
"order_items.*.order_id" => 'intval', |
| 151 |
"order_items.*.post_id" => 'intval', |
| 152 |
"order_items.*.object_id" => 'intval', |
| 153 |
"order_items.*.payment_type" => 'sanitize_text_field', |
| 154 |
"order_items.*.quantity" => 'intval', |
| 155 |
"order_items.*.post_title" => 'sanitize_text_field', |
| 156 |
"order_items.*.title" => 'sanitize_text_field', |
| 157 |
"order_items.*.shipping_charge" => 'intval', |
| 158 |
"order_items.*.price" => 'floatval', |
| 159 |
"order_items.*.unit_price" => 'floatval', |
| 160 |
"order_items.*.item_cost" => 'floatval', |
| 161 |
"order_items.*.item_total" => 'floatval', |
| 162 |
"order_items.*.tax_amount" => 'floatval', |
| 163 |
"order_items.*.discount_total" => 'floatval', |
| 164 |
"order_items.*.total" => 'floatval', |
| 165 |
"order_items.*.line_total" => 'floatval', |
| 166 |
"order_items.*.cart_index" => 'intval', |
| 167 |
"order_items.*.rate" => 'floatval', |
| 168 |
"order_items.*.line_meta" => 'sanitize_text_field', |
| 169 |
"order_items.*.other_info" => function ($value) { |
| 170 |
return is_array($value) ? $value : []; |
| 171 |
}, |
| 172 |
|
| 173 |
"discount.type" => 'sanitize_text_field', |
| 174 |
"discount.value" => 'floatval', |
| 175 |
"discount.label" => 'sanitize_text_field', |
| 176 |
"discount.reason" => 'sanitize_text_field', |
| 177 |
"discount.action" => 'sanitize_text_field', |
| 178 |
|
| 179 |
"shipping.*.type" => 'sanitize_text_field', |
| 180 |
"shipping.*.rate_name" => 'sanitize_text_field', |
| 181 |
"shipping.*.custom_price" => 'floatval', |
| 182 |
|
| 183 |
"deletedItems" => function ($value) { |
| 184 |
return is_array($value) ? $value : []; |
| 185 |
}, |
| 186 |
|
| 187 |
"applied_coupon.*.id" => 'intval', |
| 188 |
"applied_coupon.*.order_id" => 'intval', |
| 189 |
"applied_coupon.*.coupon_id" => 'intval', |
| 190 |
"applied_coupon.*.title" => 'sanitize_text_field', |
| 191 |
"applied_coupon.*.discount" => 'intval', |
| 192 |
"applied_coupon.*.code" => 'sanitize_text_field', |
| 193 |
"applied_coupon.*.status" => 'sanitize_text_field', |
| 194 |
"applied_coupon.*.type" => 'sanitize_text_field', |
| 195 |
"applied_coupon.*.amount" => 'intval', |
| 196 |
"applied_coupon.*.discounted_amount" => 'intval', |
| 197 |
"applied_coupon.*.stackable" => 'intval', |
| 198 |
"applied_coupon.*.priority" => 'intval', |
| 199 |
"applied_coupon.*.max_uses" => 'intval', |
| 200 |
"applied_coupon.*.use_count" => 'intval', |
| 201 |
"applied_coupon.*.max_per_customer" => 'intval', |
| 202 |
"applied_coupon.*.min_purchase_amount" => 'intval', |
| 203 |
"applied_coupon.*.max_discount_amount" => 'intval', |
| 204 |
"applied_coupon.*.notes" => 'sanitize_text_field', |
| 205 |
'trigger' => 'sanitize_text_field', |
| 206 |
]; |
| 207 |
|
| 208 |
} |
| 209 |
} |
| 210 |
|