From: fomichev Date: Thu, 28 Nov 2024 13:15:38 +0000 (+0300) Subject: Добавление характеристик в таблицу X-Git-Tag: 1.7~215^2~8 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=0dadf4b49b2daca685a024a4fa079b0a080006cc;p=erp24_rep%2Fyii-erp24%2F.git Добавление характеристик в таблицу --- diff --git a/erp24/api2/controllers/DataController.php b/erp24/api2/controllers/DataController.php index d8b43180..04aa6e35 100644 --- a/erp24/api2/controllers/DataController.php +++ b/erp24/api2/controllers/DataController.php @@ -49,8 +49,8 @@ class DataController extends BaseController { const OUT_DIR = // __DIR__ . "/../json"; - // "/www/api2/json"; - "/var/www/erp24/api2/json"; + "/www/api2/json"; + // "/var/www/erp24/api2/json"; // "/var/www/www-root/data/www/api.bazacvetov24.ru/data/json"; @@ -576,6 +576,39 @@ class DataController extends BaseController { LogService::apiErrorLog(json_encode(["error_id" => 8, "error" => $products1c6->getErrors()], JSON_UNESCAPED_UNICODE)); } + foreach ($arr as $key => $property) { + if (!in_array($key, Products1c::PRODUCT1C_FIELDS)) { + if (empty($property)) continue; + $propertyType = Products1cPropType::findOne(['id' => $key]); + if (!$propertyType) { + $propertyType = new Products1cPropType(); + $propertyType->id = $key; + $propertyType->name = $key; + if (!$propertyType->save()) { + LogService::apiErrorLog(json_encode(["error_id" => 8.1, + "error" => $propertyType->getErrors()], + JSON_UNESCAPED_UNICODE)); + continue; + } + } + $additionalCharacteristic = Products1cAdditionalCharacteristics::findOne([ + 'product_id' => $arr["id"], + 'property_id' => $key + ]); + if (!$additionalCharacteristic && !empty($property)) { + $additionalCharacteristic = new Products1cAdditionalCharacteristics(); + $additionalCharacteristic->product_id = $arr["id"]; + $additionalCharacteristic->property_id = $key; + } + $additionalCharacteristic->value = $property; + if (!$additionalCharacteristic->save()) { + LogService::apiErrorLog(json_encode(["error_id" => 8.2, + "error" => $additionalCharacteristic->getErrors()], + JSON_UNESCAPED_UNICODE)); + } + } + } + if (!empty($arr["AdditionCharacteristics"])) { $passedCharacteristics = array_column($arr["AdditionCharacteristics"], null, "id"); $currentCharacteristics = Products1cAdditionalCharacteristics::find() diff --git a/erp24/records/Products1c.php b/erp24/records/Products1c.php index 11b180ee..2a4e9ef0 100644 --- a/erp24/records/Products1c.php +++ b/erp24/records/Products1c.php @@ -19,6 +19,8 @@ use yii\helpers\ArrayHelper; */ class Products1c extends \yii\db\ActiveRecord { + + const PRODUCT1C_FIELDS = ['id', 'parent_id', 'tip', 'code', 'name', 'articule', 'view', 'components', 'AdditionCharacteristics']; /** * {@inheritdoc} */