From 1bfaea7fc1bb02b05e55abd6d81fb658e6762cd7 Mon Sep 17 00:00:00 2001 From: fomichev Date: Tue, 19 Nov 2024 12:14:19 +0300 Subject: [PATCH] =?utf8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5?= =?utf8?q?=D0=BD=D0=B8=D0=B5=20=D0=BC=D0=B8=D0=B3=D1=80=D0=B0=D1=86=D0=B8?= =?utf8?q?=D0=B9=20=D0=B8=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?utf8?q?=D0=BD=D0=B8=D0=B5=20=D0=BC=D0=BE=D0=B4=D0=B5=D0=BB=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- ...4933_create_product_1c_prop_type_table.php | 5 +- ...956_create_product_1c_prop_value_table.php | 47 -------------- ...ts_1c_additional_characteristics_table.php | 43 +++++++++++++ erp24/records/Product1cPropType.php | 57 +++++++++++++++++ .../Products1cAdditionalCharacteristics.php | 61 +++++++++++++++++++ 5 files changed, 163 insertions(+), 50 deletions(-) delete mode 100644 erp24/migrations/m241102_124956_create_product_1c_prop_value_table.php create mode 100644 erp24/migrations/m241102_124956_create_products_1c_additional_characteristics_table.php create mode 100644 erp24/records/Product1cPropType.php create mode 100644 erp24/records/Products1cAdditionalCharacteristics.php diff --git a/erp24/migrations/m241102_124933_create_product_1c_prop_type_table.php b/erp24/migrations/m241102_124933_create_product_1c_prop_type_table.php index 97cce874..e99444c4 100644 --- a/erp24/migrations/m241102_124933_create_product_1c_prop_type_table.php +++ b/erp24/migrations/m241102_124933_create_product_1c_prop_type_table.php @@ -15,9 +15,8 @@ class m241102_124933_create_product_1c_prop_type_table extends Migration public function safeUp() { $this->createTable(self::TABLE_NAME, [ - 'id' => $this->string()->notNull()->unique()->comment('Идентификатор из 1С'), - 'alias' => $this->string()->notNull()->comment('Алиас свойства'), - 'value' => $this->string()->notNull()->comment('Значение - например, "Срезка"'), + 'id' => $this->string()->notNull()->unique()->comment('GUID свойства'), + 'name' => $this->string()->notNull()->comment('Имя свойства') ]); $this->addPrimaryKey('pk_product_1c_prop_type', self::TABLE_NAME, 'id'); diff --git a/erp24/migrations/m241102_124956_create_product_1c_prop_value_table.php b/erp24/migrations/m241102_124956_create_product_1c_prop_value_table.php deleted file mode 100644 index ca1ab185..00000000 --- a/erp24/migrations/m241102_124956_create_product_1c_prop_value_table.php +++ /dev/null @@ -1,47 +0,0 @@ -createTable(self::TABLE_NAME, [ - 'id' => $this->string()->notNull()->unique()->comment('Идентификатор значения в системе 1С'), - 'prop_id' => $this->string()->notNull()->comment('Идентификатор свойства для которого присваивается значение'), - 'value_type' => $this->string()->notNull()->comment('Тип данных значения'), - 'value_string' => $this->string()->null()->comment('String '), - 'value_int' => $this->integer()->null()->comment('Integer'), - 'value_float' => $this->float()->null()->comment('Float'), - ]); - - $this->addPrimaryKey('pk_product_1c_prop_value', self::TABLE_NAME, 'id'); - $this->addForeignKey( - 'fk_product_1c_prop_value_prop_id', - self::TABLE_NAME, - 'prop_id', - '{{%erp24.product_1c_prop_type}}', - 'id', - 'CASCADE', - 'CASCADE' - ); - } - - /** - * {@inheritdoc} - */ - public function safeDown() - { - $this->dropForeignKey('fk_product_1c_prop_value_prop_id', self::TABLE_NAME); - $this->dropTable(self::TABLE_NAME); - - } -} diff --git a/erp24/migrations/m241102_124956_create_products_1c_additional_characteristics_table.php b/erp24/migrations/m241102_124956_create_products_1c_additional_characteristics_table.php new file mode 100644 index 00000000..6fbc2b5f --- /dev/null +++ b/erp24/migrations/m241102_124956_create_products_1c_additional_characteristics_table.php @@ -0,0 +1,43 @@ +createTable(self::TABLE_NAME, [ + 'id' => $this->primaryKey()->comment('Идентификатор инкрементируемый'), // Auto-incrementing primary key + 'product_id' => $this->string()->notNull()->comment('GUID товара'), // GUID of the product + 'property_id' => $this->string()->notNull()->comment('ID из product_1c_prop_type'), // Foreign key to property type + 'value_name' => $this->string()->notNull()->comment('Название свойства, привязанного к продукту и относящегося к данному property_id') // Property name associated with the product + ]); + + $this->addForeignKey( + 'fk_products_1c_additional_characteristics_property_id', + self::TABLE_NAME, + 'property_id', + '{{%erp24.product_1c_prop_type}}', + 'id', + 'CASCADE', + 'CASCADE' + ); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->dropForeignKey('fk_products_1c_additional_characteristics_property_id', self::TABLE_NAME); + $this->dropTable(self::TABLE_NAME); + } +} \ No newline at end of file diff --git a/erp24/records/Product1cPropType.php b/erp24/records/Product1cPropType.php new file mode 100644 index 00000000..b80f36f3 --- /dev/null +++ b/erp24/records/Product1cPropType.php @@ -0,0 +1,57 @@ + 255], + [['id'], 'unique'], + ]; + } + + /** + * {@inheritdoc} + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'name' => 'Name', + ]; + } + + /** + * Gets query for [[Products1cAdditionalCharacteristics]]. + * + * @return \yii\db\ActiveQuery + */ + public function getProducts1cAdditionalCharacteristics() + { + return $this->hasMany(Products1cAdditionalCharacteristics::class, ['property_id' => 'id']); + } +} diff --git a/erp24/records/Products1cAdditionalCharacteristics.php b/erp24/records/Products1cAdditionalCharacteristics.php new file mode 100644 index 00000000..eedf9ae6 --- /dev/null +++ b/erp24/records/Products1cAdditionalCharacteristics.php @@ -0,0 +1,61 @@ + 255], + [['property_id'], 'exist', 'skipOnError' => true, 'targetClass' => Product1cPropType::class, 'targetAttribute' => ['property_id' => 'id']], + ]; + } + + /** + * {@inheritdoc} + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'product_id' => 'Product ID', + 'property_id' => 'Property ID', + 'value_name' => 'Value Name', + ]; + } + + /** + * Gets query for [[Property]]. + * + * @return \yii\db\ActiveQuery + */ + public function getProperty() + { + return $this->hasOne(Product1cPropType::class, ['id' => 'property_id']); + } +} -- 2.39.5