| 1 |
<?php |
| 2 |
if (!defined('ABSPATH')) { |
| 3 |
exit; |
| 4 |
} |
| 5 |
|
| 6 |
// Similar Trips Section |
| 7 |
// Expected variables: $trip |
| 8 |
?> |
| 9 |
<section class="yatra-similar-section"> |
| 10 |
<div class="yatra-similar-section-container"> |
| 11 |
<div class="yatra-similar-section-header"> |
| 12 |
<h2 class="yatra-similar-section-title"> |
| 13 |
<?php echo yatra_svg_icon('mountain', 'yatra-similar-section-icon'); ?> |
| 14 |
<?php echo esc_html__('Similar Adventures', 'yatra'); ?> |
| 15 |
</h2> |
| 16 |
<div class="yatra-carousel-nav"> |
| 17 |
<button type="button" class="yatra-carousel-btn yatra-carousel-prev" id="similar-prev" aria-label="<?php echo esc_attr__('Previous', 'yatra'); ?>"> |
| 18 |
<svg width="20" height="20" fill="none" stroke="currentColor" viewBox="0 0 24 24"> |
| 19 |
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"/> |
| 20 |
</svg> |
| 21 |
</button> |
| 22 |
<button type="button" class="yatra-carousel-btn yatra-carousel-next" id="similar-next" aria-label="<?php echo esc_attr__('Next', 'yatra'); ?>"> |
| 23 |
<svg width="20" height="20" fill="none" stroke="currentColor" viewBox="0 0 24 24"> |
| 24 |
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"/> |
| 25 |
</svg> |
| 26 |
</button> |
| 27 |
</div> |
| 28 |
</div> |
| 29 |
<div class="yatra-carousel-wrapper"> |
| 30 |
<div class="yatra-carousel-track" id="similar-carousel"> |
| 31 |
<?php |
| 32 |
// Use dynamic similar trips from controller, with fallback to sample data |
| 33 |
$similar_trips_data = $trip->getSimilarTrips(); |
| 34 |
|
| 35 |
// Only show real trips from database - no dummy data |
| 36 |
|
| 37 |
$yatra_similar_dp_flags = function_exists('yatra_get_dynamic_pricing_display_flags') ? yatra_get_dynamic_pricing_display_flags() : [ |
| 38 |
'show_original_price' => true, |
| 39 |
'show_savings_badge' => true, |
| 40 |
'show_urgency_messages' => false, |
| 41 |
]; |
| 42 |
|
| 43 |
foreach ($similar_trips_data as $similar_trip) { |
| 44 |
// Prepare trip data directly from object properties |
| 45 |
$title = $similar_trip->title ?? ''; |
| 46 |
$slug = $similar_trip->slug ?? ''; |
| 47 |
|
| 48 |
// Duration |
| 49 |
$duration_days = (int) ($similar_trip->duration_days ?? 0); |
| 50 |
$duration_nights = (int) ($similar_trip->duration_nights ?? 0); |
| 51 |
$duration = [ |
| 52 |
'has_duration' => $duration_days > 0, |
| 53 |
'formatted' => $duration_nights > 0 |
| 54 |
? sprintf(_n('%d day %d night', '%d days %d nights', $duration_days, 'yatra'), $duration_days, $duration_nights) |
| 55 |
: sprintf(_n('%d day', '%d days', $duration_days, 'yatra'), $duration_days) |
| 56 |
]; |
| 57 |
|
| 58 |
// Difficulty — resolve classification id to label + icon (same logic as Trip::getDifficulty / quick facts) |
| 59 |
$similar_difficulty_level = isset($similar_trip->difficulty_level) && $similar_trip->difficulty_level !== '' |
| 60 |
? (string) $similar_trip->difficulty_level |
| 61 |
: null; |
| 62 |
$similar_difficulty_name = isset($similar_trip->difficulty_name) && $similar_trip->difficulty_name !== '' |
| 63 |
? (string) $similar_trip->difficulty_name |
| 64 |
: null; |
| 65 |
$difficulty = \Yatra\Models\Trip::resolveDifficultyDisplay( |
| 66 |
$similar_difficulty_level, |
| 67 |
$similar_difficulty_name, |
| 68 |
$similar_trip->difficulty_icon ?? null |
| 69 |
); |
| 70 |
|
| 71 |
// Pricing |
| 72 |
$original_price = (float) ($similar_trip->original_price ?? 0); |
| 73 |
$sale_price = (float) ($similar_trip->sale_price ?? $original_price); |
| 74 |
$current_price = $sale_price > 0 ? $sale_price : $original_price; |
| 75 |
$discount_pct = 0; |
| 76 |
$has_discount = false; |
| 77 |
|
| 78 |
if ($original_price > 0 && $sale_price < $original_price) { |
| 79 |
$discount_pct = round((($original_price - $sale_price) / $original_price) * 100); |
| 80 |
// Only show discount if percentage is greater than 0 |
| 81 |
$has_discount = $discount_pct > 0; |
| 82 |
} |
| 83 |
|
| 84 |
$pricing = [ |
| 85 |
'has_price' => $current_price > 0, |
| 86 |
'current_price' => yatra_format_price($current_price), |
| 87 |
'original_price' => $has_discount ? yatra_format_price($original_price) : '', |
| 88 |
'has_discount' => $has_discount, |
| 89 |
]; |
| 90 |
|
| 91 |
$discount = [ |
| 92 |
'has_discount' => $has_discount, |
| 93 |
'discount_text' => $has_discount ? $discount_pct . '%' : '' |
| 94 |
]; |
| 95 |
|
| 96 |
$yatra_similar_urgency = []; |
| 97 |
if (!empty($yatra_similar_dp_flags['show_urgency_messages']) && function_exists('yatra_trip_card_dynamic_pricing_urgency_lines')) { |
| 98 |
$yatra_similar_urgency = yatra_trip_card_dynamic_pricing_urgency_lines((int) ($similar_trip->id ?? 0), [ |
| 99 |
'base_sale_price' => $current_price, |
| 100 |
'base_original_price' => $original_price, |
| 101 |
'sale_price' => $current_price, |
| 102 |
'original_price' => $original_price, |
| 103 |
'departure_date' => null, |
| 104 |
'spots_remaining' => null, |
| 105 |
'availability_id' => null, |
| 106 |
'surface' => 'similar', |
| 107 |
]); |
| 108 |
} |
| 109 |
|
| 110 |
// Image |
| 111 |
$image_url = $similar_trip->featured_image_url ?? ''; |
| 112 |
if (empty($image_url)) { |
| 113 |
$image_url = plugins_url('assets/images/trip-placeholder.svg', YATRA_PLUGIN_FILE); |
| 114 |
} |
| 115 |
$image = [ |
| 116 |
'url' => $image_url, |
| 117 |
'alt' => $title |
| 118 |
]; |
| 119 |
|
| 120 |
// Permalink — use canonical helper (pretty + plain permalink structures). |
| 121 |
$permalink = ''; |
| 122 |
if (!empty($slug) && function_exists('yatra_get_trip_permalink')) { |
| 123 |
$permalink = yatra_get_trip_permalink($similar_trip); |
| 124 |
} |
| 125 |
|
| 126 |
// Empty arrays for now (can be populated later if needed) |
| 127 |
$destinations = []; |
| 128 |
$categories = []; |
| 129 |
$activities = []; |
| 130 |
|
| 131 |
// Rating |
| 132 |
$rating = [ |
| 133 |
'average_rating' => 0, |
| 134 |
'review_count' => 0, |
| 135 |
'formatted_rating' => '0.0', |
| 136 |
'has_rating' => false |
| 137 |
]; |
| 138 |
?> |
| 139 |
<div class="yatra-carousel-item"> |
| 140 |
<div class="yatra-similar-trip-card"> |
| 141 |
<div class="yatra-similar-trip-image"> |
| 142 |
<?php if (!empty($permalink)): ?> |
| 143 |
<a href="<?php echo esc_url($permalink); ?>" class="yatra-similar-image-link"> |
| 144 |
<img src="<?php echo esc_url($image['url']); ?>" alt="<?php echo esc_attr($image['alt']); ?>"> |
| 145 |
</a> |
| 146 |
<?php else: ?> |
| 147 |
<img src="<?php echo esc_url($image['url']); ?>" alt="<?php echo esc_attr($image['alt']); ?>"> |
| 148 |
<?php endif; ?> |
| 149 |
|
| 150 |
<?php if ($discount['has_discount'] && !empty($yatra_similar_dp_flags['show_savings_badge'])): ?> |
| 151 |
<div class="yatra-similar-discount-badge"> |
| 152 |
<?php |
| 153 |
printf( |
| 154 |
/* translators: %s: discount text (e.g. "10%") */ |
| 155 |
esc_html__('%s OFF', 'yatra'), |
| 156 |
esc_html($discount['discount_text']) |
| 157 |
); |
| 158 |
?> |
| 159 |
</div> |
| 160 |
<?php endif; ?> |
| 161 |
|
| 162 |
<?php if (function_exists('yatra_wishlist_enabled') && yatra_wishlist_enabled()) : ?> |
| 163 |
<button type="button" class="yatra-favorite-btn yatra-similar-favorite-btn" data-trip-id="<?php echo esc_attr($similar_trip->id); ?>" title="<?php esc_attr_e('Save to wishlist', 'yatra'); ?>"> |
| 164 |
<?php echo yatra_svg_icon('heart', ''); ?> |
| 165 |
</button> |
| 166 |
<?php endif; ?> |
| 167 |
|
| 168 |
<?php if (!empty($difficulty['has_difficulty'])) : ?> |
| 169 |
<div class="yatra-similar-difficulty-overlay"> |
| 170 |
<?php |
| 171 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 172 |
echo yatra_stored_picker_icon_markup($difficulty['icon_picker'] ?? null, 'mountain', 'similar-difficulty-icon'); |
| 173 |
?> |
| 174 |
<?php echo ' ' . esc_html($difficulty['level']); ?> |
| 175 |
</div> |
| 176 |
<?php endif; ?> |
| 177 |
</div> |
| 178 |
|
| 179 |
<div class="yatra-similar-trip-content"> |
| 180 |
<!-- Destination --> |
| 181 |
<?php if (!empty($destinations)) : ?> |
| 182 |
<div class="yatra-similar-destinations"> |
| 183 |
<?php echo yatra_svg_icon('map-pin', 'similar-location-icon'); ?> |
| 184 |
<?php |
| 185 |
$destination_names = []; |
| 186 |
foreach ($destinations as $destination) { |
| 187 |
if (isset($destination->name)) { |
| 188 |
$destination_permalink = function_exists('yatra_get_destination_permalink') |
| 189 |
? yatra_get_destination_permalink($destination) |
| 190 |
: '#'; |
| 191 |
$destination_names[] = '<a href="' . esc_url($destination_permalink) . '" class="similar-destination-link">' . esc_html($destination->name) . '</a>'; |
| 192 |
} |
| 193 |
} |
| 194 |
echo implode(', ', $destination_names); |
| 195 |
?> |
| 196 |
</div> |
| 197 |
<?php endif; ?> |
| 198 |
|
| 199 |
<h3 class="yatra-similar-trip-title"> |
| 200 |
<?php if (!empty($permalink)): ?> |
| 201 |
<a href="<?php echo esc_url($permalink); ?>" class="yatra-similar-title-link"><?php echo esc_html($title); ?></a> |
| 202 |
<?php else: ?> |
| 203 |
<?php echo esc_html($title); ?> |
| 204 |
<?php endif; ?> |
| 205 |
</h3> |
| 206 |
|
| 207 |
<!-- Trip Stats --> |
| 208 |
<div class="yatra-similar-trip-stats"> |
| 209 |
<?php if ($duration['has_duration']): ?> |
| 210 |
<div class="yatra-similar-stat"> |
| 211 |
<?php echo yatra_svg_icon('calendar', 'similar-stat-icon'); ?> |
| 212 |
<span><?php echo esc_html($duration['formatted']); ?></span> |
| 213 |
</div> |
| 214 |
<?php endif; ?> |
| 215 |
|
| 216 |
<?php if (!empty($similar_trip->min_travelers) || !empty($similar_trip->max_travelers)): ?> |
| 217 |
<div class="yatra-similar-stat"> |
| 218 |
<?php echo yatra_svg_icon('users', 'similar-stat-icon'); ?> |
| 219 |
<span> |
| 220 |
<?php |
| 221 |
$min_travelers = $similar_trip->min_travelers ?? 1; |
| 222 |
$max_travelers = $similar_trip->max_travelers ?? 20; |
| 223 |
echo esc_html($min_travelers . '-' . $max_travelers); |
| 224 |
?> |
| 225 |
</span> |
| 226 |
</div> |
| 227 |
<?php endif; ?> |
| 228 |
|
| 229 |
<?php if ($rating['has_rating'] && $rating['average_rating'] > 0): ?> |
| 230 |
<div class="yatra-similar-stat"> |
| 231 |
<?php echo yatra_svg_icon('star', 'similar-stat-icon'); ?> |
| 232 |
<span><?php echo esc_html($rating['formatted_rating']); ?></span> |
| 233 |
</div> |
| 234 |
<?php endif; ?> |
| 235 |
</div> |
| 236 |
|
| 237 |
<!-- Categories --> |
| 238 |
<?php if (!empty($categories)) : ?> |
| 239 |
<div class="yatra-similar-categories"> |
| 240 |
<?php foreach (array_slice($categories, 0, 2) as $category) : ?> |
| 241 |
<a href="<?php echo esc_url(yatra_get_category_permalink($category)); ?>" class="yatra-similar-category-tag"> |
| 242 |
<?php echo esc_html($category->name); ?> |
| 243 |
</a> |
| 244 |
<?php endforeach; ?> |
| 245 |
</div> |
| 246 |
<?php endif; ?> |
| 247 |
|
| 248 |
<div class="yatra-similar-trip-footer"> |
| 249 |
<div class="yatra-similar-price"> |
| 250 |
<?php if ($pricing['has_price']): ?> |
| 251 |
<div class="yatra-similar-trip-price"> |
| 252 |
<span class="yatra-similar-price-label"><?php esc_html_e('From', 'yatra'); ?></span> |
| 253 |
<span class="yatra-similar-price-amount"><?php echo esc_html($pricing['current_price']); ?></span> |
| 254 |
<?php if (!empty($yatra_similar_dp_flags['show_original_price']) && $pricing['has_discount'] && !empty($pricing['original_price'])): ?> |
| 255 |
<span class="yatra-similar-original-price"><?php echo esc_html($pricing['original_price']); ?></span> |
| 256 |
<?php endif; ?> |
| 257 |
</div> |
| 258 |
<?php if (!empty($yatra_similar_urgency)) : ?> |
| 259 |
<?php foreach ($yatra_similar_urgency as $yatra_sim_urg) : ?> |
| 260 |
<div style="background-color:#fef3c7;color:#92400e;padding:4px 6px;border-radius:4px;font-size:11px;line-height:1.3;margin-top:6px;"> |
| 261 |
<?php echo esc_html((string) $yatra_sim_urg); ?> |
| 262 |
</div> |
| 263 |
<?php endforeach; ?> |
| 264 |
<?php endif; ?> |
| 265 |
<?php else: ?> |
| 266 |
<span class="yatra-similar-trip-price yatra-similar-price-contact"><?php esc_html_e('Contact for pricing', 'yatra'); ?></span> |
| 267 |
<?php endif; ?> |
| 268 |
</div> |
| 269 |
<?php if (!empty($permalink)): ?> |
| 270 |
<a href="<?php echo esc_url($permalink); ?>" class="yatra-similar-view-btn"><?php esc_html_e('View Details', 'yatra'); ?></a> |
| 271 |
<?php endif; ?> |
| 272 |
</div> |
| 273 |
</div> |
| 274 |
</div> |
| 275 |
</div> |
| 276 |
<?php } ?> |
| 277 |
</div> |
| 278 |
</div> |
| 279 |
</div> |
| 280 |
</section> |
| 281 |
|