]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Исправление кодировки в заказах Яндекс маркета
authorVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Fri, 20 Jun 2025 11:52:03 +0000 (14:52 +0300)
committerVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Fri, 20 Jun 2025 11:52:03 +0000 (14:52 +0300)
erp24/commands/MarketplaceController.php
erp24/services/MarketplaceService.php

index bde21904b425289715468643dba18bb3d4be01f0..1777a3bb460e17b9c741d57f11efb7719df78bb2 100644 (file)
@@ -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
index 65324a768a55abcab21ece1dfbc4a42c56c8283c..f7dcfb7ddbe0d7759707311e3040bef5979f7b66 100644 (file)
@@ -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;
             }
         }