From b4c755a66b4fb1aacd5d8ed1dd091bb335f76aa6 Mon Sep 17 00:00:00 2001 From: Stas Demin Date: Wed, 9 Oct 2024 12:38:08 +0300 Subject: [PATCH] Revert "hotfix: get offices and auth" This reverts commit 456ae251c1fd5fc0a03db6516227c0b04a131deb. --- src/Blocks/CheckoutMapBlock.php | 2 +- src/CdekApi.php | 4 ++-- src/Controllers/LocationController.php | 8 ++++---- src/UI/AdminShippingFields.php | 3 ++- src/UI/CheckoutMap.php | 2 +- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/Blocks/CheckoutMapBlock.php b/src/Blocks/CheckoutMapBlock.php index 693f7e9..fe9e37a 100644 --- a/src/Blocks/CheckoutMapBlock.php +++ b/src/Blocks/CheckoutMapBlock.php @@ -65,7 +65,7 @@ public static function extend_cart_data(): array 'city' => $city, 'points' => $city !== -1 ? $api->getOffices([ 'city_code' => $city, - ])->body() : '[]', + ])['body'] : '[]', ]; } diff --git a/src/CdekApi.php b/src/CdekApi.php index a75bc83..601a1a9 100644 --- a/src/CdekApi.php +++ b/src/CdekApi.php @@ -310,8 +310,8 @@ public function getOffices($filter) 'GET', $this->tokenStorage->getToken(), $filter, - ); - if (!$result->body()) { + )->json(); + if (!$result) { return [ 'success' => false, 'message' => esc_html__( diff --git a/src/Controllers/LocationController.php b/src/Controllers/LocationController.php index bac3a21..e94456d 100644 --- a/src/Controllers/LocationController.php +++ b/src/Controllers/LocationController.php @@ -20,10 +20,10 @@ public static function getPoints(WP_REST_Request $data): WP_REST_Response { $data = (new CdekApi)->getOffices($data->get_params()); - return new WP_REST_Response($data->body(), 200, [ - 'x-current-page' => $data->getHeaders()['x-current-page'] ?? null, - 'x-total-pages' => $data->getHeaders()['x-total-pages'] ?? null, - 'x-total-elements' => $data->getHeaders()['x-total-elements'] ?? null, + return new WP_REST_Response($data instanceof WP_Error ? $data : $data['body'], 200, [ + 'x-current-page' => $data['headers']['x-current-page'] ?? null, + 'x-total-pages' => $data['headers']['x-total-pages'] ?? null, + 'x-total-elements' => $data['headers']['x-total-elements'] ?? null, ]); } diff --git a/src/UI/AdminShippingFields.php b/src/UI/AdminShippingFields.php index 4a9ffe7..ac69419 100644 --- a/src/UI/AdminShippingFields.php +++ b/src/UI/AdminShippingFields.php @@ -48,7 +48,8 @@ public function __invoke($item_id, $item): void break; case MetaKeys::OFFICE_CODE: try { - $officeAddress = (new CdekApi)->getOffices(['code' => $meta['value']])->json(); + $officeAddress = json_decode((new CdekApi)->getOffices(['code' => $meta['value']])['body'], + true, 512, JSON_THROW_ON_ERROR); if (empty($officeAddress[0]['location']['address'])) { self::renderOffice(esc_html__('Not available for order', 'cdekdelivery')); diff --git a/src/UI/CheckoutMap.php b/src/UI/CheckoutMap.php index 33e7dde..54fdd82 100644 --- a/src/UI/CheckoutMap.php +++ b/src/UI/CheckoutMap.php @@ -37,7 +37,7 @@ public function __invoke($shippingMethodCurrent): void $points = $city !== -1 ? $api->getOffices([ 'city_code' => $city, - ]) : '[]'; + ])['body'] : '[]'; $mapAutoClose = CheckoutHelper::getMapAutoClose();