From 8bb1dbcf9e09bf0920a867b8c610c95b4089f479 Mon Sep 17 00:00:00 2001 From: Alexander Smirnov Date: Tue, 15 Apr 2025 12:54:11 +0300 Subject: [PATCH] [ERP-399] refactor 2 --- erp24/commands/MatrixErpController.php | 12 ++++++------ erp24/records/MatrixErpPropertyDynamic.php | 6 ++++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/erp24/commands/MatrixErpController.php b/erp24/commands/MatrixErpController.php index 0f54014b..df6bc2ba 100644 --- a/erp24/commands/MatrixErpController.php +++ b/erp24/commands/MatrixErpController.php @@ -26,9 +26,9 @@ class MatrixErpController extends Controller $products = MarketplaceService::getMarketplaceProducts(); $matrixErpPropertyDynamicByGuid = []; - foreach (range(1,2) as $ind) { - $matrixErpPropertyDynamicByGuid[$ind] = MatrixErpPropertyDynamic::find() - ->where(['product_id' => ArrayHelper::getColumn($products, 'id'), 'category' => $ind]) + foreach (MatrixErpPropertyDynamic::fieldByCategory() as $category => $field) { + $matrixErpPropertyDynamicByGuid[$category] = MatrixErpPropertyDynamic::find() + ->where(['product_id' => ArrayHelper::getColumn($products, 'id'), 'category' => $category]) ->indexBy('product_id')->asArray()->all(); } @@ -37,9 +37,9 @@ class MatrixErpController extends Controller if (in_array($product->id, array_keys($existingMapGuidGroupNames)) && (in_array('marketplace', $existingMapGuidGroupNames[$product->id]))) { $matrixErp = $existingMapGuidMatrixErp[$product->id]; - foreach (['components', 'articule'] as $fieldInd => $field) { + foreach (MatrixErpPropertyDynamic::fieldByCategory() as $category => $field) { if ($matrixErp->$field != $product->$field) { - $matrixErpPropertyDynamic1 = $matrixErpPropertyDynamicByGuid[$fieldInd + 1][$matrixErp->guid] ?? null; + $matrixErpPropertyDynamic1 = $matrixErpPropertyDynamicByGuid[$category][$matrixErp->guid] ?? null; /* @var MatrixErpPropertyDynamic $matrixErpPropertyDynamic1 */ if ($matrixErpPropertyDynamic1) { $matrixErpPropertyDynamic1->date_end = date("Y-m-d H:i:s"); @@ -52,7 +52,7 @@ class MatrixErpController extends Controller $matrixErpPropertyDynamic2 = new MatrixErpPropertyDynamic; $matrixErpPropertyDynamic2->product_id = $matrixErp->guid; $matrixErpPropertyDynamic2->value = $product->$field; - $matrixErpPropertyDynamic2->category = $fieldInd + 1; + $matrixErpPropertyDynamic2->category = $category; $matrixErpPropertyDynamic2->date_from = date("Y-m-d H:i:s"); $matrixErpPropertyDynamic2->date_end = '2100-01-01 00:00:00'; $matrixErpPropertyDynamic2->save(); diff --git a/erp24/records/MatrixErpPropertyDynamic.php b/erp24/records/MatrixErpPropertyDynamic.php index f5b660ec..e7f690be 100644 --- a/erp24/records/MatrixErpPropertyDynamic.php +++ b/erp24/records/MatrixErpPropertyDynamic.php @@ -17,6 +17,12 @@ use Yii; */ class MatrixErpPropertyDynamic extends \yii\db\ActiveRecord { + public static function fieldByCategory() { + return [ + 1 => 'components', + 2 => 'articule', + ]; + } /** * {@inheritdoc} */ -- 2.39.5