use yii_app\records\Prices;
use yii_app\records\PricesDynamic;
use yii_app\records\PricesZakup;
-use yii_app\records\Product1cPropType;
+use yii_app\records\Products1CPropType;
use yii_app\records\Products1c;
use yii_app\records\Products1cAdditionalCharacteristics;
use yii_app\records\Sales;
}
if (!empty($arr["AdditionCharacteristics"])) {
- foreach ($arr["AdditionCharacteristics"] as $characteristic) {
- $propertyType = Product1cPropType::findOne(['id' => $characteristic["id"]]);
+
+ $passedCharacteristics = array_column($arr["AdditionCharacteristics"], null, "id");
+
+
+ $currentCharacteristics = Products1cAdditionalCharacteristics::find()
+ ->where(['product_id' => $arr["id"]])
+ ->indexBy('property_id')
+ ->all();
+
+
+ foreach ($currentCharacteristics as $propertyId => $currentCharacteristic) {
+ if (!isset($passedCharacteristics[$propertyId])) {
+
+ if (!$currentCharacteristic->delete()) {
+ LogService::apiErrorLog(json_encode([
+ "error_id" => 8.3,
+ "error" => $currentCharacteristic->getErrors()
+ ], JSON_UNESCAPED_UNICODE));
+ }
+ }
+ }
+
+
+
+
+ foreach ($arr["AdditionCharacteristics"] as $characteristic) {
+
+ $propertyType = Products1CPropType::findOne(['id' => $characteristic["id"]]);
if (!$propertyType) {
- $propertyType = new Product1cPropType();
+ $propertyType = new Products1CPropType();
$propertyType->id = $characteristic["id"];
$propertyType->name = $characteristic["name"];
if (!$propertyType->save()) {
use yii\web\Controller;
use yii_app\records\ExportImportTable;
use yii_app\records\Prices;
-use yii_app\records\Product1cPropType;
+use yii_app\records\Products1CPropType;
use yii_app\records\Products1c;
use yii_app\records\Products1cAdditionalCharacteristics;
use yii_app\records\Products1cOptions;
}
- $properties = Product1cPropType::find()
+ $properties = Products1CPropType::find()
->select(['id', 'name'])
->all();
$properties = ArrayHelper::map($properties, 'id', 'name');
+++ /dev/null
-<?php
-
-use yii\db\Migration;
-
-/**
- * Handles the creation of table `{{%product_1c_prop_type}}`.
- */
-class m241102_124933_create_product_1c_prop_type_table extends Migration
-{
-
- const TABLE_NAME = 'erp24.product_1c_prop_type';
- /**
- * {@inheritdoc}
- */
- public function safeUp()
- {
- $this->createTable(self::TABLE_NAME, [
- 'id' => $this->string()->notNull()->unique()->comment('GUID свойства'),
- 'name' => $this->string()->notNull()->comment('Имя свойства')
- ]);
-
- $this->addPrimaryKey('pk_product_1c_prop_type', self::TABLE_NAME, 'id');
- }
-
- /**
- * {@inheritdoc}
- */
- public function safeDown()
- {
- $this->dropTable(self::TABLE_NAME);
- }
-}
--- /dev/null
+<?php
+
+use yii\db\Migration;
+
+/**
+ * Handles the creation of table `{{%products_1c_prop_type}}`.
+ */
+class m241102_124933_create_products_1c_prop_type_table extends Migration
+{
+
+ const TABLE_NAME = 'erp24.products_1c_prop_type';
+ /**
+ * {@inheritdoc}
+ */
+ public function safeUp()
+ {
+
+ $tableSchema = $this->db->getTableSchema(self::TABLE_NAME);
+
+ if (!isset($tableSchema)) {
+ $this->createTable(self::TABLE_NAME, [
+ 'id' => $this->string()->notNull()->unique()->comment('GUID свойства'),
+ 'name' => $this->string()->notNull()->comment('Имя свойства')
+ ]);
+
+ $this->addPrimaryKey('pk_products_1c_prop_type', self::TABLE_NAME, 'id');
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function safeDown()
+ {
+ $tableSchema = $this->db->getTableSchema(self::TABLE_NAME);
+ if (isset($tableSchema)) {
+ $this->dropTable(self::TABLE_NAME);
+ }
+ }
+}
*/
public function safeUp()
{
- $this->createTable(self::TABLE_NAME, [
- 'id' => $this->primaryKey()->comment('Идентификатор инкрементируемый'),
- 'product_id' => $this->string()->notNull()->comment('GUID товара'),
- 'property_id' => $this->string()->notNull()->comment('ID из product_1c_prop_type'),
- 'value' => $this->string()->notNull()->comment('Название свойства, привязанного к продукту и относящегося к данному property_id') ]);
-
- $this->addForeignKey(
- 'fk_products_1c_additional_characteristics_property_id',
- self::TABLE_NAME,
- 'property_id',
- '{{%erp24.product_1c_prop_type}}',
- 'id',
- 'CASCADE',
- 'CASCADE'
- );
+
+ $tableSchema = $this->db->getTableSchema(self::TABLE_NAME);
+
+ if (!isset($tableSchema)) {
+ $this->createTable(self::TABLE_NAME, [
+
+ 'product_id' => $this->string()->notNull()->comment('GUID товара'),
+ 'property_id' => $this->string()->notNull()->comment('ID из products_1c_prop_type'),
+ 'value' => $this->string()->notNull()->comment('Название свойства, привязанного к продукту и относящегося к данному property_id')]);
+
+ $this->addPrimaryKey(
+ 'pk_products_1c_additional_characteristics',
+ self::TABLE_NAME,
+ ['product_id', 'property_id']
+ );
+
+ $this->addForeignKey(
+ 'fk_products_1c_additional_characteristics_property_id',
+ self::TABLE_NAME,
+ 'property_id',
+ '{{%erp24.products_1c_prop_type}}',
+ 'id',
+ );
+ }
}
/**
*/
public function safeDown()
{
- $this->dropForeignKey('fk_products_1c_additional_characteristics_property_id', self::TABLE_NAME);
- $this->dropTable(self::TABLE_NAME);
+ $tableSchema = $this->db->getTableSchema(self::TABLE_NAME);
+ if (isset($tableSchema)) {
+ $this->dropPrimaryKey('pk_products_1c_additional_characteristics', self::TABLE_NAME);
+ $this->dropForeignKey('fk_products_1c_additional_characteristics_property_id', self::TABLE_NAME);
+ $this->dropTable(self::TABLE_NAME);
+ }
}
}
\ No newline at end of file
+++ /dev/null
-<?php
-
-namespace yii_app\records;
-
-use Yii;
-
-/**
- * This is the model class for table "product_1c_prop_type".
- *
- * @property string $id GUID свойства
- * @property string $name Имя свойства
- *
- * @property Products1cAdditionalCharacteristics[] $products1cAdditionalCharacteristics
- */
-class Product1cPropType extends \yii\db\ActiveRecord
-{
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return 'product_1c_prop_type';
- }
-
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['id', 'name'], 'required'],
- [['id', 'name'], 'string', 'max' => 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']);
- }
-}
/**
* This is the model class for table "products_1c_additional_characteristics".
*
- * @property int $id Идентификатор инкрементируемый
+
* @property string $product_id GUID товара
* @property string $property_id ID из product_1c_prop_type
* @property string $value Название свойства, привязанного к продукту и относящегося к данному property_id
*
- * @property Product1cPropType $property
+ * @property Products1CPropType $property
*/
class Products1cAdditionalCharacteristics extends \yii\db\ActiveRecord
{
return 'products_1c_additional_characteristics';
}
+
+ public static function primaryKey()
+ {
+ return ['product_id', 'property_id'];
+ }
+
+
/**
* {@inheritdoc}
*/
return [
[['product_id', 'property_id', 'value'], 'required'],
[['product_id', 'property_id', 'value'], 'string', 'max' => 255],
- [['property_id'], 'exist', 'skipOnError' => true, 'targetClass' => Product1cPropType::class, 'targetAttribute' => ['property_id' => 'id']],
+ [['property_id'], 'exist', 'skipOnError' => true, 'targetClass' => Products1CPropType::class, 'targetAttribute' => ['property_id' => 'id']],
];
}
public function attributeLabels()
{
return [
- 'id' => 'ID',
+
'product_id' => 'Product ID',
'property_id' => 'Property ID',
'value' => 'Value Name',
*/
public function getProperty()
{
- return $this->hasOne(Product1cPropType::class, ['id' => 'property_id']);
+ return $this->hasOne(Products1CPropType::class, ['id' => 'property_id']);
}
}
--- /dev/null
+<?php
+
+namespace yii_app\records;
+
+use Yii;
+
+/**
+ * This is the model class for table "products_1c_prop_type".
+ *
+ * @property string $id GUID свойства
+ * @property string $name Имя свойства
+ *
+ * @property Products1cAdditionalCharacteristics[] $products1cAdditionalCharacteristics
+ */
+class Products1CPropType extends \yii\db\ActiveRecord
+{
+ /**
+ * {@inheritdoc}
+ */
+ public static function tableName()
+ {
+ return 'products_1c_prop_type';
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function rules()
+ {
+ return [
+ [['id', 'name'], 'required'],
+ [['id', 'name'], 'string', 'max' => 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']);
+ }
+}