| @@ -868,12 +868,16 @@ | ||
| 868 | 868 | */ |
| 869 | 869 | private function formatDiscountAmount($discount): string { |
| 870 | 870 | $amount = $discount->group_discount_amount ?? 0; |
| 871 | 871 | if ($discount->group_discount_type === 'percentage') { |
| 872 | - return "{$amount}% off"; | |
| 873 | - } else { | |
| 874 | - return "$" . number_format((float) $amount, 2) . " off"; | |
| 872 | + /* translators: %s: discount percentage. */ | |
| 873 | + return sprintf(__('%s%% off', 'yatra'), $amount); | |
| 875 | 874 | } |
| 875 | + | |
| 876 | + // Was a hardcoded "$" with default separators, so every non-dollar site | |
| 877 | + // showed the wrong currency (and the label could not be translated). | |
| 878 | + /* translators: %s: discount amount, already formatted with the site currency. */ | |
| 879 | + return sprintf(__('%s off', 'yatra'), yatra_format_price((float) $amount, null, false)); | |
| 876 | 880 | } |
| 877 | 881 | |
| 878 | 882 | /** |
| 879 | 883 | * @param array $travelerCounts Array of category_id => count (e.g., ['3' => 4, '5' => 1]) |
| @@ -898,19 +902,32 @@ | ||
| 898 | 902 | |
| 899 | 903 | |
| 900 | 904 | $totalTravelers = array_sum(array_map('intval', $travelerCounts)); |
| 901 | 905 | |
| 902 | - // Build price lookup by category_id | |
| 906 | + // Build price + price-type lookup by category_id | |
| 903 | 907 | $priceByCategory = []; |
| 908 | + $ptByCategory = []; | |
| 904 | 909 | foreach ($priceTypes as $pt) { |
| 905 | - $pt = (object) $pt; | |
| 906 | - $categoryId = $pt->category_id ?? null; | |
| 910 | + $pt = (array) $pt; | |
| 911 | + $categoryId = $pt['category_id'] ?? null; | |
| 907 | 912 | if ($categoryId !== null) { |
| 908 | - $priceByCategory[$categoryId] = (float) ($pt->effective_price ?? $pt->sale_price ?? $pt->original_price ?? 0); | |
| 913 | + $priceByCategory[$categoryId] = (float) ($pt['effective_price'] ?? $pt['sale_price'] ?? $pt['original_price'] ?? 0); | |
| 914 | + $ptByCategory[$categoryId] = $pt; | |
| 909 | 915 | } |
| 910 | 916 | } |
| 911 | 917 | |
| 918 | + // Effective subtotal for a category — delegate to the single source of | |
| 919 | + // truth so the discount base ALWAYS matches CalculationService's charge | |
| 920 | + // (per-person × count, flat per-group, or per-block group pricing). | |
| 921 | + $catSubtotal = function ($categoryId, $count) use ($priceByCategory, $ptByCategory): float { | |
| 922 | + return \Yatra\Services\TripPricingService::categoryLineSubtotal( | |
| 923 | + $ptByCategory[$categoryId] ?? [], | |
| 924 | + (int) $count, | |
| 925 | + (float) ($priceByCategory[$categoryId] ?? 0) | |
| 926 | + ); | |
| 927 | + }; | |
| 912 | 928 | |
| 929 | + | |
| 913 | 930 | foreach ($groupDiscounts as $discount) { |
| 914 | 931 | $discountMode = $discount->discount_mode ?? 'total'; |
| 915 | 932 | |
| 916 | 933 | // Category-based discounts: check each category's count and apply to that category's subtotal |
| @@ -940,10 +957,10 @@ | ||
| 940 | 957 | $discountType = $range->discount_type ?? 'percentage'; |
| 941 | 958 | $discountValue = (float) ($range->discount_amount ?? 0); |
| 942 | 959 | |
| 943 | 960 | // Calculate discount for this category's subtotal only |
| 944 | - $categoryPrice = $priceByCategory[$categoryId] ?? 0; | |
| 945 | - $categorySubtotal = $categoryPrice * $categoryCount; | |
| 961 | + // (flat for per-group, price × count for per-person). | |
| 962 | + $categorySubtotal = $catSubtotal($categoryId, $categoryCount); | |
| 946 | 963 | |
| 947 | 964 | if ($discountType === 'percentage') { |
| 948 | 965 | $categoryDiscount = $categorySubtotal * ($discountValue / 100); |
| 949 | 966 | } else { |
| @@ -1004,10 +1021,9 @@ | ||
| 1004 | 1021 | |
| 1005 | 1022 | // Calculate total subtotal from all categories |
| 1006 | 1023 | $totalSubtotal = 0; |
| 1007 | 1024 | foreach ($travelerCounts as $catId => $count) { |
| 1008 | - $categoryPrice = $priceByCategory[$catId] ?? 0; | |
| 1009 | - $totalSubtotal += $categoryPrice * $count; | |
| 1025 | + $totalSubtotal += $catSubtotal($catId, $count); | |
| 1010 | 1026 | } |
| 1011 | 1027 | |
| 1012 | 1028 | // Calculate the actual discount amount |
| 1013 | 1029 | $calculatedAmount = $discountType === 'percentage' |
| @@ -1047,10 +1063,9 @@ | ||
| 1047 | 1063 | |
| 1048 | 1064 | // Calculate total subtotal from all categories |
| 1049 | 1065 | $totalSubtotal = 0; |
| 1050 | 1066 | foreach ($travelerCounts as $catId => $count) { |
| 1051 | - $categoryPrice = $priceByCategory[$catId] ?? 0; | |
| 1052 | - $totalSubtotal += $categoryPrice * $count; | |
| 1067 | + $totalSubtotal += $catSubtotal($catId, $count); | |
| 1053 | 1068 | } |
| 1054 | 1069 | |
| 1055 | 1070 | // Calculate the actual discount amount |
| 1056 | 1071 | $calculatedAmount = $discountType === 'percentage' |