PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.16
Yatra – Travel Booking & Tour Operator Software v3.0.16
3.0.16 3.0.15 3.0.14 3.0.14.1 3.0.14.2 3.0.12 3.0.13 3.0.11 3.0.10 3.0.9 3.0.8 3.0.7 3.0.6 3.0.5 3.0.5.1 3.0.4 3.0.3 3.0.2.9 3.0.2.7 3.0.2.8 3.0.2.6 trunk 1.0.0 2.0.0 2.0.1 All 84 releases
← All changes | app/Services/TravelerCategoryService.php +52 -17 3.0.2.7 → 3.0.16 View file →
@@ -144,8 +144,17 @@
144 144 if ($min_pax > $max_pax) {
145 145 throw new \InvalidArgumentException('Maximum group size must be greater than or equal to minimum group size');
146 146 }
147 147 }
148 +
149 + // "Charge for additional groups" needs a maximum group size to know
150 + // how big one group (one priced block) is.
151 + if (
152 + ($data['group_overflow'] ?? 'block') === 'per_block' &&
153 + (!isset($data['max_pax']) || $data['max_pax'] === '' || $data['max_pax'] === null || (int) $data['max_pax'] <= 0)
154 + ) {
155 + throw new \InvalidArgumentException('Maximum group size is required to charge for additional groups');
156 + }
148 157 }
149 158 }
150 159
151 160 /**
@@ -168,9 +177,9 @@
168 177 // Always auto-generate slug from name (backend ensures uniqueness)
169 178 if (!empty($data['name'])) {
170 179 $data['slug'] = SlugHelper::generateUniqueFromDatabase(
171 180 $data['name'],
172 - 'yatra_new_classifications',
181 + 'yatra_classifications',
173 182 'slug'
174 183 );
175 184 } elseif (isset($data['slug'])) {
176 185 // If name is empty but slug is provided, sanitize it
@@ -212,16 +221,22 @@
212 221 if (isset($data['max_pax']) && $data['max_pax'] !== '' && $data['max_pax'] !== null) {
213 222 $metadata['max_pax'] = (int) $data['max_pax'];
214 223 }
215 224
225 + if (isset($data['group_overflow'])) {
226 + $metadata['group_overflow'] = in_array($data['group_overflow'], ['block', 'per_block'], true)
227 + ? $data['group_overflow']
228 + : 'block';
229 + }
230 +
216 231 // Set the type for traveler categories
217 232 $data['type'] = 'traveler_type';
218 -
233 +
219 234 // Store metadata as JSON
220 235 $data['metadata'] = wp_json_encode($metadata);
221 236
222 237 // Remove old field names that don't exist in ClassificationsTable
223 - unset($data['age_min'], $data['age_max'], $data['pricing_mode'], $data['min_pax'], $data['max_pax']);
238 + unset($data['age_min'], $data['age_max'], $data['pricing_mode'], $data['min_pax'], $data['max_pax'], $data['group_overflow']);
224 239
225 240 // Set created_by and updated_by to current user
226 241 $current_user_id = get_current_user_id();
227 242 $data['created_by'] = absint($current_user_id);
@@ -229,18 +244,10 @@
229 244
230 245 // Sanitize and serialize icon if it's an array
231 246 if (isset($data['icon'])) {
232 247 if (is_array($data['icon'])) {
233 - // Sanitize icon array
234 - $icon = [
235 - 'type' => isset($data['icon']['type']) && in_array($data['icon']['type'], ['icon', 'image'], true)
236 - ? $data['icon']['type']
237 - : 'icon',
238 - 'value' => isset($data['icon']['value'])
239 - ? sanitize_text_field($data['icon']['value'])
240 - : '',
241 - ];
242 - $data['icon'] = maybe_serialize($icon);
248 + $data['icon'] = yatra_normalize_icon_picker_for_storage($data['icon']);
249 + $data['icon'] = maybe_serialize($data['icon']);
243 250 } elseif (is_string($data['icon'])) {
244 251 // If it's already a string, sanitize it
245 252 $data['icon'] = sanitize_text_field($data['icon']);
246 253 }
@@ -273,9 +280,9 @@
273 280 if ($preserveSlug && isset($data['slug']) && !empty($data['slug'])) {
274 281 // Slug was manually edited - preserve it but ensure uniqueness
275 282 $data['slug'] = SlugHelper::generateUniqueFromDatabase(
276 283 $data['slug'],
277 - 'yatra_new_classifications',
284 + 'yatra_classifications',
278 285 'slug',
279 286 $id // Exclude current record when checking uniqueness
280 287 );
281 288 } elseif (!empty($data['name'])) {
@@ -281,9 +288,9 @@
281 288 } elseif (!empty($data['name'])) {
282 289 // Auto-generate slug from name if name is provided and slug not manually edited
283 290 $data['slug'] = SlugHelper::generateUniqueFromDatabase(
284 291 $data['name'],
285 - 'yatra_new_classifications',
292 + 'yatra_classifications',
286 293 'slug',
287 294 $id // Exclude current record when checking uniqueness
288 295 );
289 296 } elseif (isset($data['slug'])) {
@@ -352,13 +359,41 @@
352 359 $metadata['max_pax'] = absint($data['max_pax']);
353 360 }
354 361 }
355 362
356 - // Store updated metadata as JSON
363 + if (isset($data['group_overflow'])) {
364 + $metadata['group_overflow'] = in_array($data['group_overflow'], ['block', 'per_block'], true)
365 + ? $data['group_overflow']
366 + : 'block';
367 + }
368 +
369 + // Store updated metadata as JSON (existing metadata read above, so
370 + // untouched keys are preserved — only the keys present in $data change).
357 371 $data['metadata'] = wp_json_encode($metadata);
358 372
359 373 // Remove old field names that don't exist in ClassificationsTable
360 - unset($data['age_min'], $data['age_max'], $data['pricing_mode'], $data['min_pax'], $data['max_pax']);
374 + unset($data['age_min'], $data['age_max'], $data['pricing_mode'], $data['min_pax'], $data['max_pax'], $data['group_overflow']);
375 +
376 + // Sanitize and serialize icon if it's an array
377 + if (isset($data['icon'])) {
378 + if (is_array($data['icon'])) {
379 + if ($data['icon']['type'] === 'image' && !empty($data['icon']['value'])) {
380 + $value = $data['icon']['value'];
381 + if (filter_var($value, FILTER_VALIDATE_URL)) {
382 + $attachment_id = attachment_url_to_postid($value);
383 + if ($attachment_id) {
384 + $data['icon']['value'] = $attachment_id;
385 + }
386 + } elseif (is_numeric($value)) {
387 + $data['icon']['value'] = (int) $value;
388 + }
389 + }
390 + $data['icon'] = yatra_normalize_icon_picker_for_storage($data['icon']);
391 + $data['icon'] = maybe_serialize($data['icon']);
392 + } elseif (is_string($data['icon'])) {
393 + $data['icon'] = sanitize_text_field($data['icon']);
394 + }
395 + }
361 396
362 397 // Set updated_by to current user
363 398 $data['updated_by'] = absint(get_current_user_id());
364 399