Skip to content

Commit

Permalink
Revert "hotfix: get offices and auth"
Browse files Browse the repository at this point in the history
This reverts commit 456ae25.
  • Loading branch information
DEMAxx committed Oct 9, 2024
1 parent d400acf commit b4c755a
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Blocks/CheckoutMapBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static function extend_cart_data(): array
'city' => $city,
'points' => $city !== -1 ? $api->getOffices([
'city_code' => $city,
])->body() : '[]',
])['body'] : '[]',
];
}

Expand Down
4 changes: 2 additions & 2 deletions src/CdekApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -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__(
Expand Down
8 changes: 4 additions & 4 deletions src/Controllers/LocationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]);
}

Expand Down
3 changes: 2 additions & 1 deletion src/UI/AdminShippingFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
2 changes: 1 addition & 1 deletion src/UI/CheckoutMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __invoke($shippingMethodCurrent): void

$points = $city !== -1 ? $api->getOffices([
'city_code' => $city,
]) : '[]';
])['body'] : '[]';

$mapAutoClose = CheckoutHelper::getMapAutoClose();

Expand Down

0 comments on commit b4c755a

Please sign in to comment.