PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.2.6
Yatra – Travel Booking & Tour Operator Software v3.0.2.6
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
yatra / app / Ajax / DiscountShortcodeAjax.php

DiscountShortcodeAjax.php in Yatra – Travel Booking & Tour Operator Software 3.0.2.6, at app/Ajax/DiscountShortcodeAjax.php

92 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Yatra\Ajax;
6
7 /**
8 * AJAX handlers for Discount Shortcode
9 */
10 class DiscountShortcodeAjax
11 {
12 public function __construct()
13 {
14 // Use the same AJAX handler as regular trips
15 add_action('wp_ajax_yatra_discount_trip_shortcode_load', [$this, 'loadTrips']);
16 add_action('wp_ajax_nopriv_yatra_discount_trip_shortcode_load', [$this, 'loadTrips']);
17 }
18
19 /**
20 * Load trips via AJAX for pagination (same as regular trips)
21 */
22 public function loadTrips(): void
23 {
24 // Debug: Log AJAX request
25 if (defined('WP_DEBUG') && WP_DEBUG) {
26 error_log('Yatra Discount AJAX - Request received: ' . print_r($_POST, true));
27 }
28
29 // Verify nonce
30 if (!wp_verify_nonce($_POST['nonce'] ?? '', 'yatra_trip_shortcode_nonce')) {
31 if (defined('WP_DEBUG') && WP_DEBUG) {
32 error_log('Yatra Discount AJAX - Security check failed');
33 }
34 wp_die(esc_html__('Security check failed', 'yatra'), '', ['response' => 403]);
35 }
36
37 // Parse shortcode attributes
38 $atts = $_POST['atts'] ?? [];
39 $page = (int) ($_POST['page'] ?? 1);
40
41 // Add page to attributes for AJAX pagination
42 $atts['current_page'] = $page;
43
44 try {
45 $discountShortcode = new \Yatra\Shortcodes\DiscountAndDealsShortcode();
46 $trips_data = $discountShortcode->getTrips($atts);
47
48 // Prepare data for template - extract variables for template scope
49 $trips = [
50 'trips' => $trips_data['trips'] ?? [],
51 'max_pages' => $trips_data['max_pages'] ?? 1,
52 'current_page' => $trips_data['current_page'] ?? 1,
53 'total_found' => $trips_data['total_found'] ?? 0,
54 ];
55
56 // Additional template variables
57 $max_pages = $trips_data['max_pages'] ?? 1;
58 $current_page = $trips_data['current_page'] ?? 1;
59 $total_found = $trips_data['total_found'] ?? 0;
60
61 // Start output buffering
62 ob_start();
63
64 // Load the trip template (same as regular trips)
65 include YATRA_PLUGIN_PATH . 'templates/shortcodes/trip.php';
66
67 $html = ob_get_clean();
68
69 // Send success response
70 wp_send_json_success([
71 'html' => $html,
72 'trips' => $trips_data['trips'] ?? [],
73 'max_pages' => $max_pages,
74 'current_page' => $current_page,
75 'total_found' => $total_found,
76 ]);
77
78 } catch (\Exception $e) {
79 // Debug: Log error
80 if (defined('WP_DEBUG') && WP_DEBUG) {
81 error_log('Yatra Discount AJAX Error: ' . $e->getMessage());
82 }
83
84 wp_send_json_error([
85 'message' => (defined('WP_DEBUG') && WP_DEBUG)
86 ? 'Error loading discount trips: ' . $e->getMessage()
87 : __('Unable to load trips. Please try again.', 'yatra'),
88 ]);
89 }
90 }
91 }
92