| @@ -174,8 +174,9 @@ | ||
| 174 | 174 | $reversedTaxTotal = 0; |
| 175 | 175 | $reversedShippingTax = 0; |
| 176 | 176 | $rcPriceMode = ''; |
| 177 | 177 | $rcShippingAdjustment = 0; |
| 178 | + $rcTotalAdjustment = 0; | |
| 178 | 179 | $shippingNetStored = false; |
| 179 | 180 | if ($isReverseCharge) { |
| 180 | 181 | $primaryRate = $order->orderTaxRates ? $order->orderTaxRates->first() : null; |
| 181 | 182 | if ($primaryRate) { |
| @@ -183,8 +184,18 @@ | ||
| 183 | 184 | $reversedTaxTotal = (int) Arr::get($meta, 'reverse_charge_original_tax_total', 0); |
| 184 | 185 | $reversedShippingTax = (int) Arr::get($meta, 'reverse_charge_original_shipping_tax', 0); |
| 185 | 186 | $rcPriceMode = (string) Arr::get($meta, 'reverse_charge_price_mode', 'fixed'); |
| 186 | 187 | $shippingNetStored = !empty($meta['shipping_net_stored']); |
| 188 | + } else { | |
| 189 | + // No orderTaxRate row at all — a MoR gateway (Paddle, or any future one) | |
| 190 | + // applied the reverse charge and never ran the tax module, so there's no | |
| 191 | + // rate row to read. order.total_amount is still the gross catalog price | |
| 192 | + // (never lowered — see PaddleReconciler::coverReverseCharge), so the full | |
| 193 | + // removed VAT has to come from business_info instead of the shipping-only | |
| 194 | + // adjustment used for core-handled reverse charge orders below. | |
| 195 | + $businessInfo = $order->getBusinessInfo(); | |
| 196 | + $reversedTaxTotal = (int) Arr::get($businessInfo, 'mor_vat_removed', 0); | |
| 197 | + $rcTotalAdjustment = $reversedTaxTotal; | |
| 187 | 198 | } |
| 188 | 199 | // Only apply the display adjustment for orders where shipping_total in DB is still gross. |
| 189 | 200 | // New orders (shipping_net_stored = true) already have net shipping in DB — no adjustment. |
| 190 | 201 | if ($rcPriceMode === 'dynamic' && $isShippingInclusive && $reversedShippingTax > 0 && !$shippingNetStored) { |
| @@ -213,9 +224,9 @@ | ||
| 213 | 224 | 'reversedTaxTotal' => $reversedTaxTotal, |
| 214 | 225 | 'reversedShippingTax' => $reversedShippingTax, |
| 215 | 226 | 'rcPriceMode' => $rcPriceMode, |
| 216 | 227 | 'rcShippingAdjustment' => $rcShippingAdjustment, |
| 217 | - 'rcTotalAdjustment' => $rcShippingAdjustment, | |
| 228 | + 'rcTotalAdjustment' => $rcTotalAdjustment ?: $rcShippingAdjustment, | |
| 218 | 229 | 'showRcShippingRow' => $showRcShippingRow, |
| 219 | 230 | // Under reverse charge the stored rate/shipping lines are zeroed, so the |
| 220 | 231 | // per-rate rows are rebuilt from item-level line_meta instead. Empty rows |
| 221 | 232 | // there mean "not recoverable" — surfaces fall back to the simplified box. |