| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\App\Http\Requests; |
| 4 |
|
| 5 |
use FluentCart\Framework\Foundation\RequestGuard; |
| 6 |
use FluentCart\Framework\Support\Arr; |
| 7 |
use FluentCart\App\Services\Permission\PermissionManager; |
| 8 |
|
| 9 |
class FluentMetaRequest extends RequestGuard |
| 10 |
{ |
| 11 |
|
| 12 |
/** |
| 13 |
* @return array |
| 14 |
*/ |
| 15 |
public function rules() |
| 16 |
{ |
| 17 |
|
| 18 |
|
| 19 |
$rulesMap = [ |
| 20 |
'store_setup' => [ |
| 21 |
'store_name' => 'required|sanitizeText|maxLength:200', |
| 22 |
'store_country' => 'required|sanitizeText|maxLength:200', |
| 23 |
'seller_vat_id' => 'nullable|sanitizeText|maxLength:50', |
| 24 |
'seller_tax_id' => 'nullable|sanitizeText|maxLength:50', |
| 25 |
] |
| 26 |
]; |
| 27 |
|
| 28 |
$rules = Arr::get($rulesMap, $this->get('settings_name'), []); |
| 29 |
// $rules = [ |
| 30 |
// 'object_id' => 'integer|min:1', |
| 31 |
// 'object_type' => 'nullable|sanitizeText|max:50', |
| 32 |
// 'meta_key' => 'nullable|sanitizeText|max:50', |
| 33 |
// 'meta_value' => 'nullable|sanitizeText', |
| 34 |
// 'store_name' => 'required|sanitizeText|max:200', |
| 35 |
// 'store_country' => 'required|sanitizeText|max:200', |
| 36 |
// ]; |
| 37 |
return apply_filters('fluent_cart/store_settings/rules', $rules); |
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
/** |
| 42 |
* @return array |
| 43 |
*/ |
| 44 |
public function messages(): array |
| 45 |
{ |
| 46 |
return [ |
| 47 |
'store_name.required' => esc_html__('Store name is required.', 'fluent-cart'), |
| 48 |
'store_country.required' => esc_html__('Store country is required.', 'fluent-cart'), |
| 49 |
]; |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
/** |
| 54 |
* @return array |
| 55 |
*/ |
| 56 |
public function sanitize(): array |
| 57 |
{ |
| 58 |
$sanitizer = [ |
| 59 |
'object_type' => 'sanitize_text_field', |
| 60 |
//phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key |
| 61 |
'meta_key' => 'sanitize_text_field', |
| 62 |
'type' => 'sanitize_text_field', |
| 63 |
'default' => 'sanitize_text_field', |
| 64 |
'store_name' => 'sanitize_text_field', |
| 65 |
'company_name' => 'sanitize_text_field', |
| 66 |
'legal_registration_id' => 'sanitize_text_field', |
| 67 |
'seller_vat_id' => 'sanitize_text_field', |
| 68 |
'seller_tax_id' => 'sanitize_text_field', |
| 69 |
'store_logo' => function ($value) { |
| 70 |
if (!is_array($value)) { |
| 71 |
return ''; |
| 72 |
} |
| 73 |
return [ |
| 74 |
'id' => sanitize_text_field(Arr::get($value, 'id')), |
| 75 |
'url' => sanitize_url(Arr::get($value, 'url')), |
| 76 |
'title' => sanitize_text_field(Arr::get($value, 'title')), |
| 77 |
]; |
| 78 |
}, |
| 79 |
'checkout_button_text' => 'sanitize_text_field', |
| 80 |
'view_cart_button_text' => 'sanitize_text_field', |
| 81 |
'note_for_user_account_creation' => 'sanitize_text_field', |
| 82 |
'cart_button_text' => 'sanitize_text_field', |
| 83 |
'popup_button_text' => 'sanitize_text_field', |
| 84 |
'out_of_stock_button_text' => 'sanitize_text_field', |
| 85 |
'thousand_separator' => 'sanitize_text_field', |
| 86 |
'decimal_separator' => 'sanitize_text_field', |
| 87 |
'currency_position' => 'sanitize_text_field', |
| 88 |
'checkout_method_style' => 'sanitize_text_field', |
| 89 |
'require_logged_in' => 'sanitize_text_field', |
| 90 |
'enable_modal_checkout' => 'sanitize_text_field', |
| 91 |
'show_cart_icon_in_nav' => 'sanitize_text_field', |
| 92 |
'show_cart_icon_in_body' => 'sanitize_text_field', |
| 93 |
'additional_address_field' => 'sanitize_text_field', |
| 94 |
'hide_coupon_field' => 'sanitize_text_field', |
| 95 |
'user_account_creation_mode' => 'sanitize_text_field', |
| 96 |
'force_ssl' => 'sanitize_text_field', |
| 97 |
'checkout_page_id' => 'intval', |
| 98 |
'custom_payment_page_id' => 'intval', |
| 99 |
'cart_page_id' => 'intval', |
| 100 |
'receipt_page_id' => 'intval', |
| 101 |
'shop_page_id' => 'intval', |
| 102 |
'customer_profile_page_id' => 'intval', |
| 103 |
'customer_profile_page_slug' => 'sanitize_text_field', |
| 104 |
'registration_page_id' => 'intval', |
| 105 |
'login_page_id' => 'intval', |
| 106 |
'plugin_activated_once' => 'sanitize_text_field', |
| 107 |
'rest_route' => 'sanitize_text_field', |
| 108 |
'currency' => 'sanitize_text_field', |
| 109 |
'store_address1' => 'sanitize_text_field', |
| 110 |
'store_address2' => 'sanitize_text_field', |
| 111 |
'store_city' => 'sanitize_text_field', |
| 112 |
'store_country' => 'sanitize_text_field', |
| 113 |
'store_postcode' => 'sanitize_text_field', |
| 114 |
'store_state' => 'sanitize_text_field', |
| 115 |
'template_settings_checkout_page_mode' => 'sanitize_text_field', |
| 116 |
'show_relevant_product_in_single_page' => 'sanitize_text_field', |
| 117 |
'show_relevant_product_in_modal' => 'sanitize_text_field', |
| 118 |
'enable_early_payment_for_installment' => 'sanitize_text_field', |
| 119 |
'subscription_management_mode' => function ($value) { |
| 120 |
$value = sanitize_text_field($value); |
| 121 |
$allowed = ['gateway_managed', 'store_managed']; |
| 122 |
return in_array($value, $allowed, true) ? $value : 'gateway_managed'; |
| 123 |
}, |
| 124 |
'subscription_system_charge' => function ($value) { |
| 125 |
$value = sanitize_text_field($value); |
| 126 |
return in_array($value, ['yes', 'no'], true) ? $value : 'no'; |
| 127 |
}, |
| 128 |
'subscription_manual_fallback' => function ($value) { |
| 129 |
$value = sanitize_text_field($value); |
| 130 |
return in_array($value, ['yes', 'no'], true) ? $value : 'no'; |
| 131 |
}, |
| 132 |
'order_mode' => 'sanitize_text_field', |
| 133 |
'subscription_mode_guard' => function ($value) { |
| 134 |
$value = sanitize_text_field($value); |
| 135 |
return in_array($value, ['yes', 'no'], true) ? $value : 'yes'; |
| 136 |
}, |
| 137 |
'variation_view' => 'sanitize_text_field', |
| 138 |
'variation_columns' => 'sanitize_text_field', |
| 139 |
'modules_settings' => 'sanitize_text_field', |
| 140 |
'product_slug' => 'sanitize_text_field', |
| 141 |
'min_receipt_number' => 'sanitize_text_field', |
| 142 |
'inv_prefix' => 'sanitize_text_field', |
| 143 |
'weight_unit' => function ($value) { |
| 144 |
if (!PermissionManager::hasPermission(['store/sensitive'])) { |
| 145 |
$stored = get_option('fluent_cart_store_settings', []); |
| 146 |
return $stored['weight_unit'] ?? 'kg'; |
| 147 |
} |
| 148 |
$value = sanitize_text_field($value); |
| 149 |
$allowed = ['kg', 'g', 'lbs', 'oz']; |
| 150 |
return in_array($value, $allowed, true) ? $value : 'kg'; |
| 151 |
}, |
| 152 |
'dimension_unit' => function ($value) { |
| 153 |
if (!PermissionManager::hasPermission(['store/sensitive'])) { |
| 154 |
$stored = get_option('fluent_cart_store_settings', []); |
| 155 |
return $stored['dimension_unit'] ?? 'cm'; |
| 156 |
} |
| 157 |
$value = sanitize_text_field($value); |
| 158 |
$allowed = ['cm', 'mm', 'in', 'm']; |
| 159 |
return in_array($value, $allowed, true) ? $value : 'cm'; |
| 160 |
}, |
| 161 |
'enable_image_zoom_in_single_product' => 'sanitize_text_field', |
| 162 |
'enable_image_zoom_in_modal' => 'sanitize_text_field', |
| 163 |
'theme_setup' => function ($value) { |
| 164 |
if (!is_array($value)) { |
| 165 |
return []; |
| 166 |
} |
| 167 |
$data = []; |
| 168 |
|
| 169 |
foreach ($value as $key => $val) { |
| 170 |
$data[sanitize_text_field($key)] = sanitize_hex_color($val); |
| 171 |
} |
| 172 |
|
| 173 |
return $data; |
| 174 |
}, |
| 175 |
|
| 176 |
]; |
| 177 |
|
| 178 |
return apply_filters('fluent_cart/store_settings/sanitizer', $sanitizer); |
| 179 |
} |
| 180 |
} |
| 181 |
|