| @@ -3,8 +3,9 @@ | ||
| 3 | 3 | namespace FluentCart\App\Http\Requests; |
| 4 | 4 | |
| 5 | 5 | use FluentCart\App\Models\ShippingClass; |
| 6 | 6 | use FluentCart\App\Services\DateTime\DateTime; |
| 7 | +use FluentCart\App\Http\Rules\RequiredWhenRule; | |
| 7 | 8 | use FluentCart\Framework\Foundation\RequestGuard; |
| 8 | 9 | use FluentCart\Framework\Support\Arr; |
| 9 | 10 | |
| 10 | 11 | class ProductRequest extends RequestGuard |
| @@ -275,13 +276,43 @@ | ||
| 275 | 276 | 'variants.*.other_info.description' => 'nullable|sanitizeTextArea|maxLength:255', |
| 276 | 277 | 'variants.*.other_info.payment_type' => 'required|sanitizeText|in:onetime,subscription', |
| 277 | 278 | 'variants.*.other_info.times' => 'nullable|sanitizeText|maxLength:50', |
| 278 | 279 | 'variants.*.other_info.trial_days' => 'nullable|sanitizeText|maxLength:365', |
| 279 | - 'variants.*.other_info.repeat_interval' => 'required_if:variants.*.other_info.payment_type,subscription|sanitizeText|maxLength:100', | |
| 280 | + 'variants.*.other_info.repeat_interval' => [ | |
| 281 | + RequiredWhenRule::make( | |
| 282 | + 'variants.*.other_info.payment_type', | |
| 283 | + 'subscription', | |
| 284 | + esc_html__('Interval is required.', 'fluent-cart') | |
| 285 | + ), | |
| 286 | + 'sanitizeText', | |
| 287 | + 'maxLength:100', | |
| 288 | + ], | |
| 280 | 289 | 'variants.*.other_info.billing_summary' => 'nullable|sanitizeTextArea|maxLength:255', |
| 281 | - 'variants.*.other_info.manage_setup_fee' => 'required_if:variants.*.other_info.payment_type,subscription|sanitizeText|maxLength:100', | |
| 282 | - 'variants.*.other_info.signup_fee' => 'required_if:variants.*.other_info.manage_setup_fee,yes', | |
| 283 | - 'variants.*.other_info.signup_fee_name' => 'required_if:variants.*.other_info.manage_setup_fee,yes|sanitizeText|maxLength:100', | |
| 290 | + 'variants.*.other_info.manage_setup_fee' => [ | |
| 291 | + RequiredWhenRule::make( | |
| 292 | + 'variants.*.other_info.payment_type', | |
| 293 | + 'subscription', | |
| 294 | + esc_html__('Setup Fee option is required.', 'fluent-cart') | |
| 295 | + ), | |
| 296 | + 'sanitizeText', | |
| 297 | + 'maxLength:100', | |
| 298 | + ], | |
| 299 | + 'variants.*.other_info.signup_fee' => [ | |
| 300 | + RequiredWhenRule::make( | |
| 301 | + 'variants.*.other_info.manage_setup_fee', | |
| 302 | + 'yes', | |
| 303 | + esc_html__('Setup Fee Amount is required.', 'fluent-cart') | |
| 304 | + ), | |
| 305 | + ], | |
| 306 | + 'variants.*.other_info.signup_fee_name' => [ | |
| 307 | + RequiredWhenRule::make( | |
| 308 | + 'variants.*.other_info.manage_setup_fee', | |
| 309 | + 'yes', | |
| 310 | + esc_html__('Setup Fee Name is required.', 'fluent-cart') | |
| 311 | + ), | |
| 312 | + 'sanitizeText', | |
| 313 | + 'maxLength:100', | |
| 314 | + ], | |
| 284 | 315 | ]; |
| 285 | 316 | $rules = array_merge($rules, $variantsOtherInfoRules); |
| 286 | 317 | |
| 287 | 318 | } |
| @@ -340,11 +371,8 @@ | ||
| 340 | 371 | 'variants.*.item_cost.required_if' => esc_html__('Item cost is required.', 'fluent-cart'), |
| 341 | 372 | 'variants.*.other_info.description.max' => esc_html__('Description may not be greater than 255 characters.', 'fluent-cart'), |
| 342 | 373 | 'variants.*.other_info.payment_type.required' => esc_html__('Payment Type is required.', 'fluent-cart'), |
| 343 | 374 | 'variants.*.other_info.times.required_if' => esc_html__('Times is required.', 'fluent-cart'), |
| 344 | - 'variants.*.other_info.repeat_interval.required_if' => esc_html__('Interval is required.', 'fluent-cart'), | |
| 345 | - 'variants.*.other_info.signup_fee.required_if' => esc_html__('Setup Fee Amount is required.', 'fluent-cart'), | |
| 346 | - 'variants.*.other_info.signup_fee_name.required_if' => esc_html__('Setup Fee Name is required.', 'fluent-cart'), | |
| 347 | 375 | ]; |
| 348 | 376 | |
| 349 | 377 | $messages = array_merge($messages, $otherInfoMessages); |
| 350 | 378 | } |