| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\App\Http\Requests\FrontendRequests; |
| 4 |
|
| 5 |
use FluentCart\Framework\Foundation\RequestGuard; |
| 6 |
|
| 7 |
class CouponRequest extends RequestGuard |
| 8 |
{ |
| 9 |
|
| 10 |
/** |
| 11 |
* @return array |
| 12 |
*/ |
| 13 |
public function rules(): array |
| 14 |
{ |
| 15 |
return [ |
| 16 |
'order_uuid' => 'nullable|sanitizeText|maxLength:100', |
| 17 |
'id' => 'nullable|numeric', |
| 18 |
'coupon_code' => 'required|sanitizeText', |
| 19 |
'order_items' => 'required|array', |
| 20 |
"order_items.*.id" => 'numeric|min:1', |
| 21 |
"order_items.*.order_id" => 'numeric|min:1', |
| 22 |
"order_items.*.post_id" => 'numeric|min:1', |
| 23 |
"order_items.*.variation_id" => 'numeric|min:1', |
| 24 |
"order_items.*.type" => 'nullable|sanitizeText|maxLength:100', |
| 25 |
"order_items.*.quantity" => 'numeric|min:1', |
| 26 |
"order_items.*.title" => 'nullable|sanitizeText|maxLength:100', |
| 27 |
"order_items.*.price" => 'numeric', |
| 28 |
"order_items.*.unit_price" => 'numeric', |
| 29 |
"order_items.*.item_cost" => 'numeric', |
| 30 |
"order_items.*.item_total" => 'numeric', |
| 31 |
"order_items.*.tax_amount" => 'numeric', |
| 32 |
"order_items.*.discount_total" => 'numeric', |
| 33 |
"order_items.*.total" => 'numeric', |
| 34 |
"order_items.*.line_total" => 'numeric', |
| 35 |
"order_items.*.cart_index" => 'nullable|numeric', |
| 36 |
"order_items.*.rate" => 'nullable|numeric', |
| 37 |
"order_items.*.line_meta" => 'nullable|sanitizeTextArea', |
| 38 |
"order_items.*.other_info" => 'nullable|array', |
| 39 |
'applied_coupons' => 'nullable|array', |
| 40 |
|
| 41 |
'customer_email' => 'nullable|sanitizeText|email', |
| 42 |
|
| 43 |
]; |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* @return array |
| 48 |
*/ |
| 49 |
public function messages(): array |
| 50 |
{ |
| 51 |
return [ |
| 52 |
'coupon_code.required' => esc_html__('Coupon code is required', 'fluent-cart'), |
| 53 |
'order_items.required' => esc_html__('Item selection is required', 'fluent-cart'), |
| 54 |
]; |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* @return array |
| 59 |
*/ |
| 60 |
public function sanitize(): array |
| 61 |
{ |
| 62 |
return [ |
| 63 |
'order_uuid' => 'sanitize_text_field', |
| 64 |
'id' => 'intval', |
| 65 |
'coupon_code' => 'sanitize_text_field', |
| 66 |
"order_items.*.id" => 'intval', |
| 67 |
"order_items.*.order_id" => 'intval', |
| 68 |
"order_items.*.post_id" => 'intval', |
| 69 |
"order_items.*.variation_id" => 'intval', |
| 70 |
"order_items.*.type" => 'sanitize_text_field', |
| 71 |
"order_items.*.quantity" => 'intval', |
| 72 |
"order_items.*.title" => 'sanitize_text_field', |
| 73 |
"order_items.*.price" => 'floatval', |
| 74 |
"order_items.*.unit_price" => 'floatval', |
| 75 |
"order_items.*.item_cost" => 'floatval', |
| 76 |
"order_items.*.item_total" => 'floatval', |
| 77 |
"order_items.*.tax_amount" => 'floatval', |
| 78 |
"order_items.*.discount_total" => 'floatval', |
| 79 |
"order_items.*.total" => 'floatval', |
| 80 |
"order_items.*.line_total" => 'floatval', |
| 81 |
"order_items.*.cart_index" => 'intval', |
| 82 |
"order_items.*.rate" => 'floatval', |
| 83 |
"order_items.*.line_meta" => 'sanitize_text_field', |
| 84 |
"order_items.*.other_info" => 'sanitize_text_field', |
| 85 |
'applied_coupons.*' => 'intval', |
| 86 |
|
| 87 |
'customer_email' => function ($value) { |
| 88 |
if(empty($value)) { |
| 89 |
return ''; |
| 90 |
} |
| 91 |
|
| 92 |
return sanitize_email($value); |
| 93 |
}, |
| 94 |
]; |
| 95 |
} |
| 96 |
} |
| 97 |
|