diff --git a/src/Actions/Schedule/CollectOrders.php b/src/Actions/Schedule/CollectOrders.php new file mode 100644 index 0000000..edba458 --- /dev/null +++ b/src/Actions/Schedule/CollectOrders.php @@ -0,0 +1,58 @@ + 'id', + 'order' => 'ASC', + 'paginate' => true, + 'limit' => self::ORDERS_LIMIT, + 'return' => 'ids', + ], + ); + + for ($page = 1, $maxPages = 1; $page <= $maxPages; $page++) { + $query->set('page', $page); + $result = $query->get_orders(); + + $maxPages = $result->max_num_pages; + + $response = $this->cdekCoreApi->sendTaskData( + $this->taskId, + new TaskOutputData( + 'success', + [ + 'orders' => array_map( + static fn($order) => (string)$order, + $result->orders, + ) + ], + $page, + $maxPages + ) + ); + + $this->initData($response); + } + } + } +} diff --git a/src/Actions/Schedule/ReindexOrders.php b/src/Actions/Schedule/ReindexOrders.php new file mode 100644 index 0000000..ee46781 --- /dev/null +++ b/src/Actions/Schedule/ReindexOrders.php @@ -0,0 +1,61 @@ +initTaskData(); + } + + public static function getName(): string + { + return 'restore-order-uuids'; + } + + /** + * @return void + * @throws CdekApiException + * @throws CdekScheduledTaskException + * @throws \JsonException + */ + public function start(): void + { + if (empty($this->getTaskMeta())) { + throw new CdekScheduledTaskException( + '[CDEKDelivery] Failed to get orders meta info', + 'cdek_error.core.data', + ); + } + + foreach ($this->getTaskMeta() as $arOrder) { + OrderMetaData::updateMetaByOrderId( + $arOrder['external_id'], + [ + 'order_uuid' => $arOrder['id'], + ], + ); + } + + $this->initData($this->cdekCoreApi->sendTaskData( + $this->taskId, + new TaskOutputData('success'), + )); + } + } +} diff --git a/src/Cache/FileCache.php b/src/Cache/FileCache.php new file mode 100644 index 0000000..7c7b289 --- /dev/null +++ b/src/Cache/FileCache.php @@ -0,0 +1,67 @@ + Loader::getPluginPath() . DIRECTORY_SEPARATOR . self::CACHE_FILE_NAME], + true); + } + }else{ + if(!is_writable(Loader::getPluginPath())){ + throw new CdekApiException('[CDEKDelivery] Failed check directory rights', + 'cdek_error.cache.rights', + ['path' => Loader::getPluginPath()], + true); + } + } + + + $logFile = fopen( Loader::getPluginPath() . DIRECTORY_SEPARATOR . self::CACHE_FILE_NAME, 'w+'); + + fwrite($logFile, 'deliveryMethod = Helper::getActualShippingMethod($shippingInstanceId); - $this->apiUrl = $this->getApiUrl(); - - if (!isset($_ENV['CDEK_REST_API']) && $this->deliveryMethod->get_option('test_mode') === 'yes') { - $this->clientId = Config::TEST_CLIENT_ID; - $this->clientSecret = Config::TEST_CLIENT_SECRET; - } else { - $this->clientId = $this->deliveryMethod->get_option('client_id'); - $this->clientSecret = $this->deliveryMethod->get_option('client_secret'); - } - - $this->tokenStorage = $tokenStorage ?? new DBTokenStorage(); - } +namespace { - private function getApiUrl(): string - { - if ($this->deliveryMethod->get_option('test_mode') === 'yes') { - return $_ENV['CDEK_REST_API'] ?? Config::TEST_API_URL; - } + defined('ABSPATH') or exit; +} - return Config::API_URL; - } +namespace Cdek { - /** - * @throws \Cdek\Exceptions\CdekApiException - */ - final public function checkAuth(): bool - { - return (bool)$this->tokenStorage->getToken(); - } + use Cdek\Contracts\TokenStorageContract; + use Cdek\Enums\BarcodeFormat; + use Cdek\Exceptions\CdekApiException; + use Cdek\Exceptions\RestApiInvalidRequestException; + use Cdek\Helpers\DBTokenStorage; + use Cdek\Transport\HttpClient; + use WC_Shipping_Method; - /** - * @throws \Cdek\Exceptions\CdekApiException - * @throws \JsonException - */ - public function fetchToken(): string + class CdekApi { - $body = json_decode(HttpClient::sendRequest($this->getAuthUrl(), 'POST'), true); - if ($body === null || isset($body['error_description']) || isset($body['error'])) { - throw new CdekApiException('[CDEKDelivery] Failed to get the token', - 'cdek_error.token.auth', - $body, - true); + private const TOKEN_PATH = 'oauth/token'; + private const REGION_PATH = 'location/cities'; + private const ORDERS_PATH = 'orders/'; + private const PVZ_PATH = 'deliverypoints'; + private const CALC_LIST_PATH = 'calculator/tarifflist'; + private const CALC_PATH = 'calculator/tariff'; + private const WAYBILL_PATH = 'print/orders/'; + private const BARCODE_PATH = 'print/barcodes/'; + private const CALL_COURIER = 'intakes'; + + private string $apiUrl; + + private string $clientId; + private string $clientSecret; + private WC_Shipping_Method $deliveryMethod; + + private TokenStorageContract $tokenStorage; + + + public function __construct(?int $shippingInstanceId = null, ?TokenStorageContract $tokenStorage = null) + { + $this->deliveryMethod = Helper::getActualShippingMethod($shippingInstanceId); + $this->apiUrl = $this->getApiUrl(); + + if (!isset($_ENV['CDEK_REST_API']) && $this->deliveryMethod->get_option('test_mode') === 'yes') { + $this->clientId = Config::TEST_CLIENT_ID; + $this->clientSecret = Config::TEST_CLIENT_SECRET; + } else { + $this->clientId = $this->deliveryMethod->get_option('client_id'); + $this->clientSecret = $this->deliveryMethod->get_option('client_secret'); + } + + $this->tokenStorage = $tokenStorage ?? new DBTokenStorage(); } - return $body['access_token']; - } - private function getAuthUrl(): string - { - return sprintf('%s%s?%s', - $this->apiUrl, - self::TOKEN_PATH, - http_build_query([ - 'grant_type' => 'client_credentials', - 'client_id' => $this->clientId, - 'client_secret' => $this->clientSecret, - ])); - } + private function getApiUrl(): string + { + if ($this->deliveryMethod->get_option('test_mode') === 'yes') { + return $_ENV['CDEK_REST_API'] ?? Config::TEST_API_URL; + } - /** - * @throws \JsonException - * @throws \Cdek\Exceptions\CdekApiException - */ - final public function getOrder(string $uuid) - { - $url = $this->apiUrl . self::ORDERS_PATH . $uuid; + return Config::API_URL; + } - return HttpClient::sendCdekRequest($url, 'GET', $this->tokenStorage->getToken()); - } + /** + * @throws \Cdek\Exceptions\CdekApiException + */ + final public function checkAuth(): bool + { + return (bool)$this->tokenStorage->getToken(); + } - /** - * @throws \Cdek\Exceptions\RestApiInvalidRequestException - * @throws \Cdek\Exceptions\CdekApiException - */ - public function createOrder(array $params) - { - $url = $this->apiUrl . self::ORDERS_PATH; - $params['developer_key'] = Config::DEV_KEY; + /** + * @throws \Cdek\Exceptions\CdekApiException + * @throws \JsonException + */ + public function fetchToken(): string + { + $body = json_decode(HttpClient::sendRequest($this->getAuthUrl(), 'POST'), true); + if ($body === null || isset($body['error_description']) || isset($body['error'])) { + throw new CdekApiException('[CDEKDelivery] Failed to get the token', + 'cdek_error.token.auth', + $body, + true); + } + return $body['access_token']; + } - $result = json_decode(HttpClient::sendCdekRequest($url, 'POST', $this->tokenStorage->getToken(), $params), true); + private function getAuthUrl(): string + { + return sprintf('%s%s?%s', + $this->apiUrl, + self::TOKEN_PATH, + http_build_query([ + 'grant_type' => 'client_credentials', + 'client_id' => $this->clientId, + 'client_secret' => $this->clientSecret, + ])); + } - $request = $result['requests'][0]; + /** + * @throws \JsonException + * @throws \Cdek\Exceptions\CdekApiException + */ + final public function getOrder(string $uuid) + { + $url = $this->apiUrl . self::ORDERS_PATH . $uuid; - if ($request['state'] === 'INVALID') { - throw new RestApiInvalidRequestException(self::ORDERS_PATH, $request['errors']); + return HttpClient::sendCdekRequest($url, 'GET', $this->tokenStorage->getToken()); } - return $result; - } + /** + * @throws \Cdek\Exceptions\RestApiInvalidRequestException + * @throws \Cdek\Exceptions\CdekApiException + */ + public function createOrder(array $params) + { + $url = $this->apiUrl . self::ORDERS_PATH; + $params['developer_key'] = Config::DEV_KEY; - /** - * @throws \Cdek\Exceptions\CdekApiException - */ - public function getFileByLink($link) - { - return HttpClient::sendCdekRequest($link, 'GET', $this->tokenStorage->getToken(), null, true)['body']; - } + $result = json_decode(HttpClient::sendCdekRequest($url, 'POST', $this->tokenStorage->getToken(), $params), true); - /** - * @throws \JsonException - * @throws \Cdek\Exceptions\CdekApiException - */ - public function createWaybill($orderUuid) - { - $url = $this->apiUrl . self::WAYBILL_PATH; + $request = $result['requests'][0]; - return HttpClient::sendCdekRequest($url, 'POST', $this->tokenStorage->getToken(), ['orders' => ['order_uuid' => $orderUuid]]); - } + if ($request['state'] === 'INVALID') { + throw new RestApiInvalidRequestException(self::ORDERS_PATH, $request['errors']); + } - /** - * @throws \JsonException - * @throws \Cdek\Exceptions\CdekApiException - */ - public function createBarcode($orderUuid) - { - return HttpClient::sendCdekRequest($this->apiUrl . self::BARCODE_PATH, 'POST', $this->tokenStorage->getToken(), [ - 'orders' => ['order_uuid' => $orderUuid], - 'format' => BarcodeFormat::getByIndex($this->deliveryMethod->get_option('barcode_format', 0)), - ]); - } + return $result; + } - /** - * @throws \JsonException - * @throws \Cdek\Exceptions\CdekApiException - */ - public function getBarcode($uuid) - { - return HttpClient::sendCdekRequest($this->apiUrl . self::BARCODE_PATH . $uuid, 'GET', $this->tokenStorage->getToken()); - } + /** + * @throws \Cdek\Exceptions\CdekApiException + */ + public function getFileByLink($link) + { + return HttpClient::sendCdekRequest($link, 'GET', $this->tokenStorage->getToken(), null, true)['body']; + } - /** - * @throws \JsonException - * @throws \Cdek\Exceptions\CdekApiException - */ - public function getWaybill($uuid) - { - return HttpClient::sendCdekRequest($this->apiUrl . self::WAYBILL_PATH . $uuid, 'GET', $this->tokenStorage->getToken()); - } + /** + * @throws \JsonException + * @throws \Cdek\Exceptions\CdekApiException + */ + public function createWaybill($orderUuid) + { + $url = $this->apiUrl . self::WAYBILL_PATH; - /** - * @throws \JsonException - * @throws \Cdek\Exceptions\CdekApiException - */ - public function deleteOrder($uuid) - { - $url = $this->apiUrl . self::ORDERS_PATH . $uuid; + return HttpClient::sendCdekRequest($url, 'POST', $this->tokenStorage->getToken(), ['orders' => ['order_uuid' => $orderUuid]]); + } - return HttpClient::sendCdekRequest($url, 'DELETE', $this->tokenStorage->getToken()); - } + /** + * @throws \JsonException + * @throws \Cdek\Exceptions\CdekApiException + */ + public function createBarcode($orderUuid) + { + return HttpClient::sendCdekRequest($this->apiUrl . self::BARCODE_PATH, 'POST', $this->tokenStorage->getToken(), [ + 'orders' => ['order_uuid' => $orderUuid], + 'format' => BarcodeFormat::getByIndex($this->deliveryMethod->get_option('barcode_format', 0)), + ]); + } - /** - * @throws \JsonException - * @throws \Cdek\Exceptions\CdekApiException - */ - public function calculateTariffList($deliveryParam) - { - $url = $this->apiUrl . self::CALC_LIST_PATH; + /** + * @throws \JsonException + * @throws \Cdek\Exceptions\CdekApiException + */ + public function getBarcode($uuid) + { + return HttpClient::sendCdekRequest($this->apiUrl . self::BARCODE_PATH . $uuid, 'GET', $this->tokenStorage->getToken()); + } - $request = [ - 'type' => $deliveryParam['type'], - 'from_location' => $deliveryParam['from'], - 'to_location' => $deliveryParam['to'], - 'packages' => $deliveryParam['packages'], - ]; + /** + * @throws \JsonException + * @throws \Cdek\Exceptions\CdekApiException + */ + public function getWaybill($uuid) + { + return HttpClient::sendCdekRequest($this->apiUrl . self::WAYBILL_PATH . $uuid, 'GET', $this->tokenStorage->getToken()); + } - return HttpClient::sendCdekRequest($url, 'POST', $this->tokenStorage->getToken(), $request); - } + /** + * @throws \JsonException + * @throws \Cdek\Exceptions\CdekApiException + */ + public function deleteOrder($uuid) + { + $url = $this->apiUrl . self::ORDERS_PATH . $uuid; - /** - * @throws \Cdek\Exceptions\CdekApiException - * @throws \JsonException - */ - public function calculateTariff($deliveryParam) - { - $url = $this->apiUrl . self::CALC_PATH; - - $request = [ - 'type' => $deliveryParam['type'], - 'from_location' => $deliveryParam['from'], - 'tariff_code' => $deliveryParam['tariff_code'], - 'to_location' => $deliveryParam['to'], - 'packages' => $deliveryParam['packages'], - 'services' => array_key_exists('services', - $deliveryParam) ? $deliveryParam['services'] : [], - ]; - - return HttpClient::sendCdekRequest($url, 'POST', $this->tokenStorage->getToken(), $request); - } + return HttpClient::sendCdekRequest($url, 'DELETE', $this->tokenStorage->getToken()); + } - /** - * @throws \JsonException - * @throws \Cdek\Exceptions\CdekApiException - */ - public function getCityCode(string $city, ?string $postcode): int - { - $url = $this->apiUrl . self::REGION_PATH; + /** + * @throws \JsonException + * @throws \Cdek\Exceptions\CdekApiException + */ + public function calculateTariffList($deliveryParam) + { + $url = $this->apiUrl . self::CALC_LIST_PATH; + + $request = [ + 'type' => $deliveryParam['type'], + 'from_location' => $deliveryParam['from'], + 'to_location' => $deliveryParam['to'], + 'packages' => $deliveryParam['packages'], + ]; - //по запросу к api v2 климовск записан как "климовск микрорайон" поэтому добавляем "микрорайон" - if (mb_strtolower($city) === 'климовск') { - $city .= ' микрорайон'; + return HttpClient::sendCdekRequest($url, 'POST', $this->tokenStorage->getToken(), $request); } - $cityData = json_decode(HttpClient::sendCdekRequest($url, 'GET', $this->tokenStorage->getToken(), - ['city' => $city, 'postal_code' => $postcode]), false, 512, - JSON_THROW_ON_ERROR); + /** + * @throws \Cdek\Exceptions\CdekApiException + * @throws \JsonException + */ + public function calculateTariff($deliveryParam) + { + $url = $this->apiUrl . self::CALC_PATH; + + $request = [ + 'type' => $deliveryParam['type'], + 'from_location' => $deliveryParam['from'], + 'tariff_code' => $deliveryParam['tariff_code'], + 'to_location' => $deliveryParam['to'], + 'packages' => $deliveryParam['packages'], + 'services' => array_key_exists('services', + $deliveryParam) ? $deliveryParam['services'] : [], + ]; - if (empty($cityData)) { - return -1; + return HttpClient::sendCdekRequest($url, 'POST', $this->tokenStorage->getToken(), $request); } - return $cityData[0]->code; - } + /** + * @throws \JsonException + * @throws \Cdek\Exceptions\CdekApiException + */ + public function getCityCode(string $city, ?string $postcode): int + { + $url = $this->apiUrl . self::REGION_PATH; - /** - * @throws \Cdek\Exceptions\CdekApiException - * @throws \JsonException - */ - public function getOffices($filter) - { - $url = $this->apiUrl . self::PVZ_PATH; + //по запросу к api v2 климовск записан как "климовск микрорайон" поэтому добавляем "микрорайон" + if (mb_strtolower($city) === 'климовск') { + $city .= ' микрорайон'; + } - $result = HttpClient::sendCdekRequest($url, 'GET', $this->tokenStorage->getToken(), $filter, true); - if (!$result) { - return [ - 'success' => false, - 'message' => esc_html__("In this locality, delivery is available only for \"door-to-door\" tariffs. Select another locality to gain access to \"from warehouse\" tariffs.", 'cdekdelivery'), - ]; + $cityData = json_decode(HttpClient::sendCdekRequest($url, 'GET', $this->tokenStorage->getToken(), + ['city' => $city, 'postal_code' => $postcode]), false, 512, + JSON_THROW_ON_ERROR); + + if (empty($cityData)) { + return -1; + } + + return $cityData[0]->code; } - return $result; - } + /** + * @throws \Cdek\Exceptions\CdekApiException + * @throws \JsonException + */ + public function getOffices($filter) + { + $url = $this->apiUrl . self::PVZ_PATH; + + $result = HttpClient::sendCdekRequest($url, 'GET', $this->tokenStorage->getToken(), $filter, true); + if (!$result) { + return [ + 'success' => false, + 'message' => esc_html__("In this locality, delivery is available only for \"door-to-door\" tariffs. Select another locality to gain access to \"from warehouse\" tariffs.", 'cdekdelivery'), + ]; + } + + return $result; + } - /** - * @throws \JsonException - * @throws \Cdek\Exceptions\CdekApiException - */ - public function callCourier($param) - { - return HttpClient::sendCdekRequest($this->apiUrl . self::CALL_COURIER, 'POST', $this->tokenStorage->getToken(), $param); - } + /** + * @throws \JsonException + * @throws \Cdek\Exceptions\CdekApiException + */ + public function callCourier($param) + { + return HttpClient::sendCdekRequest($this->apiUrl . self::CALL_COURIER, 'POST', $this->tokenStorage->getToken(), $param); + } - /** - * @throws \Cdek\Exceptions\CdekApiException - * @throws \JsonException - */ - public function courierInfo($uuid) - { - return HttpClient::sendCdekRequest($this->apiUrl . self::CALL_COURIER . '/' . $uuid, 'GET', $this->tokenStorage->getToken()); - } + /** + * @throws \Cdek\Exceptions\CdekApiException + * @throws \JsonException + */ + public function courierInfo($uuid) + { + return HttpClient::sendCdekRequest($this->apiUrl . self::CALL_COURIER . '/' . $uuid, 'GET', $this->tokenStorage->getToken()); + } - /** - * @throws \Cdek\Exceptions\CdekApiException - * @throws \JsonException - */ - public function callCourierDelete($uuid) - { - return HttpClient::sendCdekRequest($this->apiUrl . self::CALL_COURIER . '/' . $uuid, - 'DELETE', - $this->tokenStorage->getToken()); + /** + * @throws \Cdek\Exceptions\CdekApiException + * @throws \JsonException + */ + public function callCourierDelete($uuid) + { + return HttpClient::sendCdekRequest($this->apiUrl . self::CALL_COURIER . '/' . $uuid, + 'DELETE', + $this->tokenStorage->getToken()); + } } } diff --git a/src/CdekCoreApi.php b/src/CdekCoreApi.php new file mode 100644 index 0000000..bdf1701 --- /dev/null +++ b/src/CdekCoreApi.php @@ -0,0 +1,243 @@ +coreClient = new HttpCoreClient(); + $this->generalTokenStorage = $tokenStorage ?? new DBTokenStorage(); + $this->tokenCoreStorage = $tokenCoreStorage ?? new DBCoreTokenStorage(); + } + + /** + * @throws CdekApiException + * @throws CdekScheduledTaskException + * @throws \JsonException + */ + public function fetchShopToken(): array + { + $response = $this->coreClient->sendCdekRequest( + Config::API_CORE_URL . self::SHOP, + 'POST', + $this->generalTokenStorage->getToken(), + [ + 'name' => get_bloginfo('name'), + 'url' => [ + 'rest' => rest_url(), + 'home' => home_url(), + 'admin' => admin_url(), + ], + ], + ); + + if (empty($response['body'])) { + throw new CdekScheduledTaskException('[CDEKDelivery] Register shop failed', + 'cdek_error.register.shop', + $response + ); + } + + $body = json_decode($response['body'], true); + + if (empty($body['data']['id'])) { + throw new CdekScheduledTaskException('[CDEKDelivery] Failed to get shop uuid', + 'cdek_error.uuid.auth', + $response, + ); + } + + $response = $this->coreClient->sendCdekRequest( + sprintf(Config::API_CORE_URL . self::TOKEN_PATH, $body['data']['id']), + 'POST', + $this->generalTokenStorage->getToken(), + ); + + $body = json_decode($response['body'], true); + + if ($body === null || !$body['success'] || empty($body['data'])) { + throw new CdekScheduledTaskException('[CDEKDelivery] Failed to get shop token', + 'cdek_error.shop_token.auth', + $body, + ); + } + + return ['tokens' => $body['data']]; + } + + /** + * @param string|null $next + * + * @throws CdekApiException + * @throws CdekScheduledTaskException + * @throws \JsonException + */ + public function taskManager(?string $next = null): array + { + $response = $this->coreClient->sendCdekRequest( + $this->getShopApiUrl() . '/' . self::TASKS . ($next === null ? '' : '?cursor=' . $next), + 'GET', + $this->tokenCoreStorage->getToken(), + ); + + return $this->initData($response); + } + + /** + * @param string $taskId + * @param TaskOutputData $data + * + * @throws \Cdek\Exceptions\CdekApiException + * @throws \Cdek\Exceptions\CdekScheduledTaskException + * @throws \JsonException + */ + public function taskInfo(string $taskId, TaskOutputData $data): array + { + $response = $this->coreClient->sendCdekRequest( + $this->getShopApiUrl() . '/' . self::TASKS . '/' . $taskId, + 'GET', + $this->tokenCoreStorage->getToken(), + [ + 'status' => $data->getStatus(), + 'result' => $data->getData(), + ], + ); + + return $this->initData($response); + } + + /** + * @param string $taskId + * @param TaskOutputData $data + * + * @throws \Cdek\Exceptions\CdekApiException + * @throws \Cdek\Exceptions\CdekScheduledTaskException + * @throws \JsonException + */ + public function sendTaskData(string $taskId, TaskOutputData $data): array + { + $response = $this->coreClient->sendCdekRequest( + $this->getShopApiUrl() . '/' . self::TASKS . '/' . $taskId, + 'PUT', + $this->tokenCoreStorage->getToken(), + [ + 'status' => $data->getStatus(), + 'result' => $data->getData(), + ], + [ + 'X-Current-Page' => $data->getCurrentPage(), + 'X-Total-Pages' => $data->getTotalPages(), + ], + ); + + return $this->initData($response); + } + + public function isServerError(): bool + { + return empty($this->status) || strpos($this->status, self::FATAL_ERRORS_FIRST_NUMBER) === 0; + } + + /** + * @throws CdekApiException + * @throws CdekScheduledTaskException + * @throws \JsonException + */ + private function getShopApiUrl(): string + { + return $this->tokenCoreStorage->getOrRefreshApiPath(); + } + + /** + * @param array $response + * + * @throws CdekScheduledTaskException + */ + private function initData(array $response): array + { + if($response['error']){ + throw new CdekScheduledTaskException( + '[CDEKDelivery] Failed to get core api response', + 'cdek_error.core.response_error', + $response, + ); + } + + $decodeResponse = json_decode($response['body'], true); + + $this->status = $response['response']['code']; + + if ( + !$this->isSuccessStatus() + && + !$this->isServerError() + || + ( + empty($decodeResponse['success']) + && + $this->status !== self::EMPTY_ANSWER + ) + ) { + throw new CdekScheduledTaskException( + '[CDEKDelivery] Failed to get core api response', + 'cdek_error.core.response', + $response, + ); + } + + return $decodeResponse ?? []; + } + + private function isSuccessStatus(): bool + { + if ($this->status === self::SUCCESS_STATUS) { + return true; + } + + if ($this->status === self::FINISH_STATUS) { + return true; + } + + if ($this->status === self::HAS_NEXT_INFO_STATUS) { + return true; + } + + if ($this->status === self::EMPTY_ANSWER) { + return true; + } + + return false; + } + } + +} diff --git a/src/CdekShippingMethod.php b/src/CdekShippingMethod.php index 4c8169a..33f2313 100644 --- a/src/CdekShippingMethod.php +++ b/src/CdekShippingMethod.php @@ -14,16 +14,16 @@ class CdekShippingMethod extends WC_Shipping_Method public function __construct($instance_id = 0) { parent::__construct($instance_id); - $this->id = Config::DELIVERY_NAME; - $this->instance_id = absint($instance_id); - $this->method_title = esc_html__('CDEK Shipping', 'cdekdelivery'); + $this->id = Config::DELIVERY_NAME; + $this->instance_id = absint($instance_id); + $this->method_title = esc_html__('CDEK Shipping', 'cdekdelivery'); $this->method_description = esc_html__('Official Shipping Method for Cdek', 'cdekdelivery'); - $this->supports = [ + $this->supports = [ 'settings', 'shipping-zones', 'instance-settings', ]; - $this->enabled = 'yes'; + $this->enabled = 'yes'; $this->init(); } @@ -31,7 +31,7 @@ final public function init(): void { $this->title = esc_html__('CDEK Shipping', 'cdekdelivery'); $this->init_settings(); - add_action('woocommerce_update_options_shipping_'.$this->id, [$this, 'process_admin_options']); + add_action('woocommerce_update_options_shipping_' . $this->id, [$this, 'process_admin_options']); $this->init_form_fields(); } @@ -51,7 +51,7 @@ final public function init_form_fields(): void $this->form_fields = [ 'auth_block_name' => [ - 'title' => '