| @@ -2,8 +2,9 @@ | ||
| 2 | 2 | |
| 3 | 3 | namespace FluentCart\App\Http\Requests; |
| 4 | 4 | |
| 5 | 5 | use FluentCart\App\App; |
| 6 | +use FluentCart\App\Services\Renderer\CheckoutFieldsSchema; | |
| 6 | 7 | use FluentCart\Framework\Foundation\RequestGuard; |
| 7 | 8 | use FluentCart\Framework\Support\Arr; |
| 8 | 9 | |
| 9 | 10 | class CustomerAddressRequest extends RequestGuard |
| @@ -24,9 +25,9 @@ | ||
| 24 | 25 | $validationRules = App::localization()->getValidationRule($this->all(), null, [ |
| 25 | 26 | 'country' => 'required|sanitizeText' |
| 26 | 27 | ]); |
| 27 | 28 | |
| 28 | - return array_merge($validationRules, [ | |
| 29 | + $rules = array_merge($validationRules, [ | |
| 29 | 30 | 'label' => 'nullable|sanitizeText|maxLength:15', |
| 30 | 31 | 'name' => 'required|sanitizeText|maxLength:255', |
| 31 | 32 | 'email' => 'required|sanitizeText|email|maxLength:255', |
| 32 | 33 | 'address_1' => 'required|sanitizeText', |
| @@ -33,9 +34,27 @@ | ||
| 33 | 34 | 'address_2' => 'nullable|sanitizeText', |
| 34 | 35 | 'city' => 'required|sanitizeText|maxLength:255', |
| 35 | 36 | 'is_primary' => 'nullable|numeric', |
| 36 | 37 | 'company_name' => 'nullable|sanitizeText|maxLength:255', |
| 38 | + 'vat_number' => 'nullable|sanitizeText|maxLength:255', | |
| 39 | + 'legal_registration_id' => 'nullable|sanitizeText|maxLength:255', | |
| 37 | 40 | ]); |
| 41 | + | |
| 42 | + if (Arr::get($this->all(), 'type') === 'billing') { | |
| 43 | + if (CheckoutFieldsSchema::isCompanyNameEnabled() && CheckoutFieldsSchema::isCompanyNameRequired()) { | |
| 44 | + $rules['company_name'] = 'required|sanitizeText|maxLength:255'; | |
| 45 | + } | |
| 46 | + | |
| 47 | + if (CheckoutFieldsSchema::isVatNumberEnabled() && CheckoutFieldsSchema::isVatNumberRequired()) { | |
| 48 | + $rules['vat_number'] = 'required|sanitizeText|maxLength:255'; | |
| 49 | + } | |
| 50 | + | |
| 51 | + if (CheckoutFieldsSchema::isLegalRegistrationIdEnabled() && CheckoutFieldsSchema::isLegalRegistrationIdRequired()) { | |
| 52 | + $rules['legal_registration_id'] = 'required|sanitizeText|maxLength:255'; | |
| 53 | + } | |
| 54 | + } | |
| 55 | + | |
| 56 | + return $rules; | |
| 38 | 57 | } |
| 39 | 58 | |
| 40 | 59 | /** |
| 41 | 60 | * @return array |
| @@ -50,9 +69,12 @@ | ||
| 50 | 69 | 'city.required' => esc_html__('City field is required.', 'fluent-cart'), |
| 51 | 70 | 'postcode.required' => esc_html__('Postcode field is required.', 'fluent-cart'), |
| 52 | 71 | 'country.required' => esc_html__('Country field is required.', 'fluent-cart'), |
| 53 | 72 | 'state.required' => esc_html__('State field is required.', 'fluent-cart'), |
| 54 | - 'label.max' => esc_html__('Label may not be greater than 15 characters.', 'fluent-cart') | |
| 73 | + 'label.max' => esc_html__('Label may not be greater than 15 characters.', 'fluent-cart'), | |
| 74 | + 'company_name.required' => esc_html__('Company Name field is required.', 'fluent-cart'), | |
| 75 | + 'vat_number.required' => esc_html__('VAT/GST/Tax Number field is required.', 'fluent-cart'), | |
| 76 | + 'legal_registration_id.required' => esc_html__('Legal Registration ID field is required.', 'fluent-cart'), | |
| 55 | 77 | ]; |
| 56 | 78 | } |
| 57 | 79 | |
| 58 | 80 | /** |
| @@ -80,7 +102,9 @@ | ||
| 80 | 102 | return sanitize_email($value); |
| 81 | 103 | }, |
| 82 | 104 | 'is_primary' => 'intval', |
| 83 | 105 | 'company_name' => 'sanitize_text_field', |
| 106 | + 'vat_number' => 'sanitize_text_field', | |
| 107 | + 'legal_registration_id' => 'sanitize_text_field', | |
| 84 | 108 | ]; |
| 85 | 109 | } |
| 86 | 110 | } |