Skip to content

Commit

Permalink
hotfix: realise 3.23.0 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
DEMAxx committed Oct 9, 2024
1 parent b4c755a commit af0431f
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 13 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,
)->json();
if (!$result) {
);
if (!$result->body()) {
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 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,
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,
]);
}

Expand Down
6 changes: 3 additions & 3 deletions src/Transport/HttpResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function getStatusCode(): int
*/
public function data(): array
{
if (!isset($this->headers['content-type']) || $this->headers['content-type'] !== 'application/json') {
if (!isset($this->headers['content-type']) || strpos($this->headers['content-type'], 'application/json') === false) {
throw new RuntimeException('Response is not JSON');
}

Expand All @@ -67,7 +67,7 @@ public function data(): array
*/
public function error(): array
{
if (!isset($this->headers['content-type']) || $this->headers['content-type'] !== 'application/json') {
if (!isset($this->headers['content-type']) || strpos($this->headers['content-type'], 'application/json') === false) {
throw new RuntimeException('Response is not JSON');
}

Expand All @@ -83,7 +83,7 @@ public function error(): array
*/
public function json(): array
{
if (!isset($this->headers['content-type']) || $this->headers['content-type'] !== 'application/json') {
if (!isset($this->headers['content-type']) || strpos($this->headers['content-type'], 'application/json') === false) {
throw new RuntimeException('Response is not JSON');
}

Expand Down
3 changes: 1 addition & 2 deletions src/UI/AdminShippingFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ public function __invoke($item_id, $item): void
break;
case MetaKeys::OFFICE_CODE:
try {
$officeAddress = json_decode((new CdekApi)->getOffices(['code' => $meta['value']])['body'],
true, 512, JSON_THROW_ON_ERROR);
$officeAddress = (new CdekApi)->getOffices(['code' => $meta['value']])->json();

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'] : '[]';
])->body() : '[]';

$mapAutoClose = CheckoutHelper::getMapAutoClose();

Expand Down

0 comments on commit af0431f

Please sign in to comment.