From: Vladimir Fomichev Date: Fri, 20 Jun 2025 11:52:03 +0000 (+0300) Subject: Исправление кодировки в заказах Яндекс маркета X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=da0050011db469fb9168b391f5b9b0192ad3683d;p=erp24_rep%2Fyii-erp24%2F.git Исправление кодировки в заказах Яндекс маркета --- diff --git a/erp24/commands/MarketplaceController.php b/erp24/commands/MarketplaceController.php index bde21904..1777a3bb 100644 --- a/erp24/commands/MarketplaceController.php +++ b/erp24/commands/MarketplaceController.php @@ -8,6 +8,7 @@ use yii\console\Controller; use yii\console\ExitCode; use yii\helpers\ArrayHelper; use yii\helpers\BaseConsole; +use yii_app\records\MarketplaceOrders; use yii_app\records\MarketplaceStore; use yii_app\records\MatrixErp; use yii_app\records\Products1c; @@ -168,4 +169,36 @@ class MarketplaceController extends Controller return $options; } + // php yii marketplace/fix-json-encoding + public function actionFixJsonEncoding() { + $yandexOrders = MarketplaceOrders::find() + ->where(['marketplace_id' => 2]) + ->all(); + foreach ($yandexOrders as $yandexOrder) { + $rawJsonString = $yandexOrder->raw_data; + $decoded = json_decode($rawJsonString, true); + + if (json_last_error() !== JSON_ERROR_NONE) { + Yii::error(json_last_error_msg()); + $this->stdout( + "Ошибка декодирования.\n", + BaseConsole::FG_RED + ); + continue; + } + + $encoded = json_encode($decoded, JSON_UNESCAPED_UNICODE); + $yandexOrder->raw_data = $encoded; + $yandexOrder->save(); + if($yandexOrder->getErrors()) { + Yii::error(json_encode($yandexOrder->getErrors(), JSON_UNESCAPED_UNICODE)); + $this->stdout( + "Ошибка сохранения.\n", + BaseConsole::FG_RED + ); + } + } + return ExitCode::OK; + } + } \ No newline at end of file diff --git a/erp24/services/MarketplaceService.php b/erp24/services/MarketplaceService.php index 65324a76..f7dcfb7d 100644 --- a/erp24/services/MarketplaceService.php +++ b/erp24/services/MarketplaceService.php @@ -989,7 +989,7 @@ class MarketplaceService $substatusId = $statuses[$substatusCode]; } - $newRawData = json_encode($order); + $newRawData = json_encode($order, JSON_UNESCAPED_UNICODE); $marketplaceOrder = MarketplaceOrders::find() ->where(['marketplace_order_id' => (string)$order->getId()]) ->one(); @@ -1149,8 +1149,8 @@ class MarketplaceService $orderItem->shop_sku = $item->getShopSku(); $orderItem->subsidy = $item->getSubsidy(); $orderItem->partner_warehouse_id = $item->getPartnerWarehouseId(); - $orderItem->promos = json_encode($item->getPromos()); - $orderItem->subsidies = json_encode($item->getSubsidies()); + $orderItem->promos = json_encode($item->getPromos(), JSON_UNESCAPED_UNICODE); + $orderItem->subsidies = json_encode($item->getSubsidies(), JSON_UNESCAPED_UNICODE); if (!$orderItem->save()) { Yii::error( @@ -1287,8 +1287,8 @@ class MarketplaceService $orderItem->shop_sku = $item->getShopSku(); $orderItem->subsidy = $item->getSubsidy(); $orderItem->partner_warehouse_id = $item->getPartnerWarehouseId(); - $orderItem->promos = json_encode($item->getPromos()); - $orderItem->subsidies = json_encode($item->getSubsidies()); + $orderItem->promos = json_encode($item->getPromos(), JSON_UNESCAPED_UNICODE); + $orderItem->subsidies = json_encode($item->getSubsidies(), JSON_UNESCAPED_UNICODE); if (!$orderItem->save()) { Yii::error( @@ -1319,8 +1319,8 @@ class MarketplaceService 'shop_sku' => $item->getShopSku(), 'subsidy' => $item->getSubsidy(), 'partner_warehouse_id' => $item->getPartnerWarehouseId(), - 'promos' => json_encode($item->getPromos()), - 'subsidies' => json_encode($item->getSubsidies()), + 'promos' => json_encode($item->getPromos(), JSON_UNESCAPED_UNICODE), + 'subsidies' => json_encode($item->getSubsidies(), JSON_UNESCAPED_UNICODE), ]; foreach ($fields as $attr => $value) { @@ -1352,8 +1352,8 @@ class MarketplaceService $orderItem->shop_sku = $item->getShopSku(); $orderItem->subsidy = $item->getSubsidy(); $orderItem->partner_warehouse_id = $item->getPartnerWarehouseId(); - $orderItem->promos = json_encode($item->getPromos()); - $orderItem->subsidies = json_encode($item->getSubsidies()); + $orderItem->promos = json_encode($item->getPromos(), JSON_UNESCAPED_UNICODE); + $orderItem->subsidies = json_encode($item->getSubsidies(), JSON_UNESCAPED_UNICODE); if (!$orderItem->save()) { Yii::error( @@ -1436,7 +1436,7 @@ class MarketplaceService list($returnResponse) = $returnsApi->getReturnWithHttpInfo($campaignId, $orderId, $returnId, $contentType); $returnResult = $returnResponse->getResult(); $returnedAt = $returnResult->getCreationDate(); - $rawReturnData = json_encode($returnResponse); + $rawReturnData = json_encode($returnResponse , JSON_UNESCAPED_UNICODE); return [ 'returnedAt' => $returnedAt, 'rawReturnData' => $rawReturnData, @@ -1696,7 +1696,7 @@ class MarketplaceService if ($email->save()) { return $email; } else { - Yii::error('Письмо не сохранено' . json_encode($email->errors), __METHOD__); + Yii::error('Письмо не сохранено' . json_encode($email->errors, JSON_UNESCAPED_UNICODE), __METHOD__); return null; } }