This commit is contained in:
2026-04-22 22:00:50 +02:00
parent 16be247ce1
commit e979fbe755
46 changed files with 5302 additions and 274 deletions

View File

@@ -145,7 +145,7 @@ class Carei_REST_Proxy {
public function check_nonce( WP_REST_Request $request ) {
$nonce = $request->get_header( 'X-WP-Nonce' );
if ( ! $nonce || ! wp_verify_nonce( $nonce, 'wp_rest' ) ) {
return new WP_Error( 'rest_forbidden', 'Invalid nonce.', array( 'status' => 403 ) );
return new WP_Error( 'rest_forbidden', __( 'Invalid nonce.', 'carei-reservation' ), array( 'status' => 403 ) );
}
return true;
}
@@ -156,7 +156,7 @@ class Carei_REST_Proxy {
private function api() {
$api = Carei_Softra_API::get_instance();
if ( null === $api ) {
return new WP_Error( 'carei_not_configured', 'Softra API not configured.', array( 'status' => 500 ) );
return new WP_Error( 'carei_not_configured', __( 'Softra API not configured.', 'carei-reservation' ), array( 'status' => 500 ) );
}
return $api;
}
@@ -227,12 +227,34 @@ class Carei_REST_Proxy {
if ( is_wp_error( $api ) ) {
return $api;
}
return $this->respond( $api->get_pricelist(
$pricelists = $api->get_pricelist(
$request->get_param( 'category' ),
$request->get_param( 'dateFrom' ),
$request->get_param( 'dateTo' ),
$request->get_param( 'pickUpLocation' )
) );
);
// Auto-collect PL extra names + per-locale translate (Phase 19).
if ( is_array( $pricelists ) ) {
$locale = $this->resolve_locale( $request );
$translations = Carei_Admin_Panel::get_extras_translations();
foreach ( $pricelists as &$pricelist ) {
if ( ! is_array( $pricelist ) || empty( $pricelist['additionalItems'] ) || ! is_array( $pricelist['additionalItems'] ) ) continue;
foreach ( $pricelist['additionalItems'] as &$item ) {
if ( ! is_array( $item ) || ! isset( $item['name'] ) || ! is_string( $item['name'] ) ) continue;
$pl_name = trim( $item['name'] );
if ( $pl_name === '' ) continue;
Carei_Admin_Panel::remember_extra_name( $pl_name );
if ( $locale === 'en' && isset( $translations[ $pl_name ] ) && $translations[ $pl_name ] !== '' ) {
$item['name'] = $translations[ $pl_name ];
}
}
unset( $item );
}
unset( $pricelist );
}
return $this->respond( $pricelists );
}
public function get_pricing_summary( WP_REST_Request $request ) {
@@ -307,18 +329,36 @@ class Carei_REST_Proxy {
}
public function get_protection_packages( WP_REST_Request $request ) {
$all = Carei_Admin_Panel::get_protection_packages();
$out = array( 'soft' => null, 'premium' => null );
$all = Carei_Admin_Panel::get_protection_packages();
$locale = $this->resolve_locale( $request );
$out = array( 'soft' => null, 'premium' => null );
foreach ( array( 'soft', 'premium' ) as $key ) {
if ( isset( $all[ $key ] ) && ! empty( $all[ $key ]['active'] ) ) {
$pkg = $all[ $key ];
if ( 'en' === $locale ) {
$name = ! empty( $pkg['name_en'] ) ? $pkg['name_en'] : $pkg['name'];
$desc = ! empty( $pkg['description_en'] ) ? $pkg['description_en'] : $pkg['description'];
} else {
$name = $pkg['name'];
$desc = $pkg['description'];
}
$out[ $key ] = array(
'key' => $key,
'name' => $all[ $key ]['name'],
'pricePerDay' => (float) $all[ $key ]['pricePerDay'],
'description' => $all[ $key ]['description'],
'name' => $name,
'pricePerDay' => (float) $pkg['pricePerDay'],
'description' => $desc,
);
}
}
return rest_ensure_response( $out );
}
private function resolve_locale( WP_REST_Request $request ) {
$lang = $request->get_param( 'lang' );
if ( $lang && in_array( strtolower( $lang ), array( 'pl', 'en' ), true ) ) {
return strtolower( $lang );
}
$locale = function_exists( 'determine_locale' ) ? determine_locale() : get_locale();
return ( 0 === strpos( (string) $locale, 'en' ) ) ? 'en' : 'pl';
}
}