| @@ -15,8 +15,9 @@ | ||
| 15 | 15 | { |
| 16 | 16 | parent::__construct('yatra_tour', [ |
| 17 | 17 | 'order' => 'asc', |
| 18 | 18 | 'featured' => '0', |
| 19 | + 'featured_priority' => '', | |
| 19 | 20 | 'per_page' => '10', |
| 20 | 21 | 'category' => '', |
| 21 | 22 | 'destination' => '', |
| 22 | 23 | 'activity' => '', |
| @@ -27,9 +28,13 @@ | ||
| 27 | 28 | 'duration_max' => '', |
| 28 | 29 | 'search' => '', |
| 29 | 30 | 'columns' => '3', |
| 30 | 31 | 'show_pagination' => 'yes', |
| 31 | - 'title' => 'Our Trips' | |
| 32 | + 'title' => 'Our Trips', | |
| 33 | + // Per-instance card layout override. 'inherit' (default) = use the | |
| 34 | + // site-wide Settings → Design "Listing Card Layout". | |
| 35 | + // Also accepts: standard | compact_mobile | compact_all. | |
| 36 | + 'card_layout' => 'inherit' | |
| 32 | 37 | ]); |
| 33 | 38 | } |
| 34 | 39 | |
| 35 | 40 | /** |
| @@ -55,93 +60,8 @@ | ||
| 55 | 60 | * Get trips using Yatra's service |
| 56 | 61 | */ |
| 57 | 62 | public function getTrips(array $atts): array |
| 58 | 63 | { |
| 59 | - try { | |
| 60 | - $tripService = new \Yatra\Services\TripService(); | |
| 61 | - | |
| 62 | - // Get current page from query string or attributes (for AJAX) | |
| 63 | - $current_page = isset($atts['current_page']) ? (int) $atts['current_page'] : (isset($_GET['trip_page']) ? (int) $_GET['trip_page'] : 1); | |
| 64 | - // Use per_page parameter only | |
| 65 | - $per_page = (int) $atts['per_page']; | |
| 66 | - $offset = ($current_page - 1) * $per_page; | |
| 67 | - | |
| 68 | - // Start with very basic arguments to ensure we get trips | |
| 69 | - $args = [ | |
| 70 | - 'limit' => $per_page, | |
| 71 | - 'offset' => $offset, | |
| 72 | - 'order_by' => 'created_at', | |
| 73 | - 'order' => $atts['order'] === 'asc' ? 'ASC' : 'DESC' | |
| 74 | - ]; | |
| 75 | - | |
| 76 | - // Add featured filter if requested | |
| 77 | - if ($atts['featured'] === '1') { | |
| 78 | - $args['where']['is_featured'] = 1; | |
| 79 | - } | |
| 80 | - | |
| 81 | - // Get total count for pagination | |
| 82 | - $count_args = $args; | |
| 83 | - unset($count_args['limit']); | |
| 84 | - unset($count_args['offset']); | |
| 85 | - $total_trips = $tripService->count($count_args); | |
| 86 | - | |
| 87 | - // Get trips using the service | |
| 88 | - $trips_data = $tripService->getActiveTrips($args); | |
| 89 | - | |
| 90 | - | |
| 91 | - | |
| 92 | - $trips = []; | |
| 93 | - foreach ($trips_data as $tripData) { | |
| 94 | - // Convert to Trip model | |
| 95 | - $trip = \Yatra\Models\Trip::fromStdClass($tripData); | |
| 96 | - | |
| 97 | - // Add basic data needed for the card | |
| 98 | - // Note: reviews are loaded elsewhere; bookings_count is attached below | |
| 99 | - $trip->reviews = []; | |
| 100 | - | |
| 101 | - $trips[] = $trip; | |
| 102 | - } | |
| 103 | - | |
| 104 | - // Attach bookings_count (computed from bookings table) for just these trips | |
| 105 | - $tripIds = array_map(static function ($t) { | |
| 106 | - return isset($t->id) ? (int) $t->id : 0; | |
| 107 | - }, $trips); | |
| 108 | - $tripIds = array_values(array_filter($tripIds)); | |
| 109 | - if (!empty($tripIds)) { | |
| 110 | - $bookingsCountMap = $tripService->getBookingsCountMap($tripIds); | |
| 111 | - foreach ($trips as $t) { | |
| 112 | - $tId = isset($t->id) ? (int) $t->id : 0; | |
| 113 | - if ($tId > 0) { | |
| 114 | - $t->bookings_count = (int) ($bookingsCountMap[$tId] ?? 0); | |
| 115 | - } | |
| 116 | - } | |
| 117 | - } | |
| 118 | - | |
| 119 | - // Calculate pagination data | |
| 120 | - $max_pages = $per_page > 0 ? ceil($total_trips / $per_page) : 1; | |
| 121 | - | |
| 122 | - return [ | |
| 123 | - 'trips' => $trips, | |
| 124 | - 'max_pages' => $max_pages, | |
| 125 | - 'current_page' => $current_page, | |
| 126 | - 'total_found' => $total_trips, | |
| 127 | - 'debug_info' => [ | |
| 128 | - 'args_used' => $args, | |
| 129 | - 'raw_count' => count($trips_data) | |
| 130 | - ] | |
| 131 | - ]; | |
| 132 | - | |
| 133 | - } catch (\Exception $e) { | |
| 134 | - if (defined('WP_DEBUG') && WP_DEBUG) { | |
| 135 | - error_log('Yatra TripShortcode Error: ' . $e->getMessage()); | |
| 136 | - } | |
| 137 | - | |
| 138 | - return [ | |
| 139 | - 'trips' => [], | |
| 140 | - 'max_pages' => 1, | |
| 141 | - 'current_page' => 1, | |
| 142 | - 'total_found' => 0 | |
| 143 | - ]; | |
| 144 | - } | |
| 64 | + return \Yatra\Services\BlockDataService::getTripListingForShortcode($atts); | |
| 145 | 65 | } |
| 146 | 66 | |
| 147 | 67 | } |