docs: Document Rajaongkir integration issue and add session support

## Discovery 

Rajaongkir plugin uses a completely different approach:
- Removes standard WooCommerce city/state fields
- Adds custom destination dropdown with Select2 search
- Stores destination in WooCommerce session (not address fields)
- Reads from session during shipping calculation

## Root Cause of Issues:

### 1. Same rates for different provinces
- OrderForm sends: city="Bandung", state="Jawa Barat"
- Rajaongkir ignores these fields
- Rajaongkir reads: WC()->session->get("selected_destination_id")
- Session empty → Uses cached/default rates

### 2. No Rajaongkir API hits
- No destination_id in session
- Rajaongkir can't calculate without destination
- Returns empty or cached rates

## Backend Fix ( DONE):

Added Rajaongkir session support in calculate_shipping:
```php
// Support for Rajaongkir plugin
if ( $country === 'ID' && ! empty( $shipping['destination_id'] ) ) {
    WC()->session->set( 'selected_destination_id', $shipping['destination_id'] );
    WC()->session->set( 'selected_destination_label', $shipping['destination_label'] );
}
```

## Frontend Fix (TODO):

Need to add Rajaongkir destination field:
1. Add destination search component (Select2/Combobox)
2. Search Rajaongkir API for locations
3. Pass destination_id to backend
4. Backend sets session before calculate_shipping()

## Documentation:

Created RAJAONGKIR_INTEGRATION.md with:
- How Rajaongkir works
- Why our implementation fails
- Complete solution steps
- Testing checklist

## Next Steps:

1. Add Rajaongkir search endpoint to OrdersController
2. Create destination search component in OrderForm
3. Pass destination_id in shipping data
4. Test with real Rajaongkir API
This commit is contained in:
dwindown
2025-11-10 18:56:41 +07:00
parent a499b6ad0b
commit 03ef9e3f24
2 changed files with 240 additions and 0 deletions

View File

@@ -1312,6 +1312,17 @@ class OrdersController {
WC()->customer->set_billing_state( $state );
WC()->customer->set_billing_postcode( $postcode );
WC()->customer->set_billing_city( $city );
// Support for Rajaongkir plugin - set destination in session
// Rajaongkir uses session-based destination instead of standard address fields
if ( $country === 'ID' && ! empty( $shipping['destination_id'] ) ) {
WC()->session->set( 'selected_destination_id', $shipping['destination_id'] );
WC()->session->set( 'selected_destination_label', $shipping['destination_label'] ?? $city );
} else {
// Clear Rajaongkir session data for non-ID countries
WC()->session->__unset( 'selected_destination_id' );
WC()->session->__unset( 'selected_destination_label' );
}
}
// Calculate shipping