update
This commit is contained in:
@@ -157,6 +157,60 @@ class Carei_Softra_API {
|
||||
return $this->request( 'GET', '/car/class/listAll' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get branches list with all segment names.
|
||||
* Returns branches + all segments. Frontend shows all branches for any segment
|
||||
* (actual availability verified at booking time by the API).
|
||||
* Cached as WP transient for 6 hours.
|
||||
*/
|
||||
public function get_segments_branches_map() {
|
||||
$cache_key = 'carei_segments_branches_map';
|
||||
$cached = get_transient( $cache_key );
|
||||
if ( false !== $cached ) {
|
||||
return $cached;
|
||||
}
|
||||
|
||||
$branches = $this->get_branches();
|
||||
if ( is_wp_error( $branches ) || ! is_array( $branches ) ) {
|
||||
return is_wp_error( $branches ) ? $branches : array();
|
||||
}
|
||||
|
||||
$all_classes = $this->get_all_car_classes();
|
||||
$segments = array();
|
||||
if ( ! is_wp_error( $all_classes ) && is_array( $all_classes ) ) {
|
||||
foreach ( $all_classes as $cls ) {
|
||||
$seg = is_string( $cls ) ? $cls : ( isset( $cls['name'] ) ? $cls['name'] : '' );
|
||||
if ( '' !== $seg ) {
|
||||
$segments[] = $seg;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// All branches potentially have all segments.
|
||||
// Actual availability is checked at booking via /car/class/list.
|
||||
$branch_names = array();
|
||||
foreach ( $branches as $b ) {
|
||||
if ( ! empty( $b['name'] ) ) {
|
||||
$branch_names[] = $b['name'];
|
||||
}
|
||||
}
|
||||
|
||||
$map = array();
|
||||
foreach ( $segments as $seg ) {
|
||||
$map[ $seg ] = $branch_names;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
'segmentToBranches' => $map,
|
||||
'branchToSegments' => array(),
|
||||
'branches' => $branches,
|
||||
);
|
||||
|
||||
set_transient( $cache_key, $result, 6 * HOUR_IN_SECONDS );
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function get_car_classes( $date_from, $date_to, $branch_name ) {
|
||||
return $this->request( 'POST', '/car/class/list', array(
|
||||
'dateFrom' => $date_from,
|
||||
@@ -203,6 +257,13 @@ class Carei_Softra_API {
|
||||
) );
|
||||
}
|
||||
|
||||
public function cancel_booking( $reservation_id, $reason ) {
|
||||
return $this->request( 'POST', '/rent/cancel', array(
|
||||
'reservationId' => $reservation_id,
|
||||
'reason' => $reason,
|
||||
) );
|
||||
}
|
||||
|
||||
public function get_agreements() {
|
||||
return $this->request( 'GET', '/agreement/def/list' );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user