Commit 8e73da4f4ad91b7bca97bc302547d024bcce5eca

Authored by Volodymyr
1 parent 9cf612c4

product models and migrations

common/messages/ru/app.php
... ... @@ -390,7 +390,7 @@ return [
390 390 'section-question__title'=> 'ЧАСТО ЗАДАВАЕМЫЕ ВОПРОСЫ',
391 391 'Номінальна потужність мережевого інвертора'=>'Номінальна потужність мережевого інвертора',
392 392 'Встановлена потужність фотоелектричних модулів'=>'Встановлена потужність фотоелектричних модулів',
393   - 'Вартість системи "під ключ"'=>'Вартість системи "під ключ"',
  393 + 'Вартість системи "під ключ"'=>'Стоимость системы "под ключ"',
394 394  
395 395  
396 396  
... ...
common/models/Product.php 0 → 100644
  1 +<?php
  2 +
  3 +namespace common\models;
  4 +
  5 +use artbox\core\behaviors\LanguageBehavior;
  6 +use artbox\core\models\Image;
  7 +use yii\db\ActiveRecord;
  8 +
  9 +class Product extends ActiveRecord
  10 +{
  11 + /**
  12 + * @inheritdoc
  13 + */
  14 + public static function tableName()
  15 + {
  16 + return 'product';
  17 + }
  18 +
  19 + public function behaviors()
  20 + {
  21 + return [
  22 + 'language' => [
  23 + 'class' => LanguageBehavior::className(),
  24 + ],
  25 + ];
  26 + }
  27 +
  28 + public function rules()
  29 + {
  30 + return [
  31 +// [
  32 +// [
  33 +// 'image',
  34 +// ],
  35 +// 'required',
  36 +// ],
  37 + [
  38 + [
  39 + 'status',
  40 + ],
  41 + 'boolean',
  42 + ],
  43 + [
  44 + [
  45 + 'sku',
  46 + ],
  47 + 'string',
  48 + 'max' => 255,
  49 + ],
  50 + [
  51 + [
  52 + 'sort',
  53 + 'image_id',
  54 + ],
  55 + 'integer',
  56 + ],
  57 + [
  58 + ['image_id'],
  59 + 'exist',
  60 + 'skipOnError' => true,
  61 + 'targetClass' => Image::className(),
  62 + 'targetAttribute' => ['image_id' => 'id'],
  63 + ],
  64 + ];
  65 + }
  66 +
  67 + /**
  68 + * @return \yii\db\ActiveQuery
  69 + */
  70 + public function getImage()
  71 + {
  72 + return $this->hasOne(Image::className(), ['id' => 'image_id']);
  73 + }
  74 +}
0 75 \ No newline at end of file
... ...
common/models/ProductLang.php 0 → 100644
  1 +<?php
  2 +
  3 +namespace common\models;
  4 +
  5 +use artbox\core\models\Language;
  6 +use yii\db\ActiveRecord;
  7 +
  8 +class ProductLang extends ActiveRecord
  9 +{
  10 + /**
  11 + * @inheritdoc
  12 + */
  13 + public static function tableName()
  14 + {
  15 + return 'product_lang';
  16 + }
  17 +
  18 + /**
  19 + * @inheritdoc
  20 + */
  21 + public function rules()
  22 + {
  23 + return [
  24 + [
  25 + [
  26 + 'product_id',
  27 + 'language_id',
  28 + 'title',
  29 + ],
  30 + 'required',
  31 + ],
  32 + [
  33 + [
  34 + 'product_id',
  35 + 'language_id',
  36 + ],
  37 + 'integer',
  38 + ],
  39 + [
  40 + [
  41 + 'title',
  42 + ],
  43 + 'string',
  44 + 'max' => 255,
  45 + ],
  46 + [
  47 + [
  48 + 'description',
  49 + ],
  50 + 'string',
  51 + ],
  52 + [
  53 + [ 'language_id' ],
  54 + 'exist',
  55 + 'skipOnError' => true,
  56 + 'targetClass' => Language::className(),
  57 + 'targetAttribute' => [ 'language_id' => 'id' ],
  58 + ],
  59 + [
  60 + [ 'tile_id' ],
  61 + 'exist',
  62 + 'skipOnError' => true,
  63 + 'targetClass' => Product::className(),
  64 + 'targetAttribute' => [ 'product_id' => 'id' ],
  65 + ],
  66 + ];
  67 + }
  68 +
  69 +
  70 + /**
  71 + * @return \yii\db\ActiveQuery
  72 + */
  73 + public function getLanguage()
  74 + {
  75 + return $this->hasOne(Language::className(), [ 'id' => 'language_id' ]);
  76 + }
  77 +
  78 + /**
  79 + * @return \yii\db\ActiveQuery
  80 + */
  81 + public function getProduct()
  82 + {
  83 + return $this->hasOne(Product::className(), [ 'id' => 'product_id' ]);
  84 + }
  85 +}
0 86 \ No newline at end of file
... ...
console/migrations/m220412_144550_create_product_table.php 0 → 100644
  1 +<?php
  2 +
  3 +use yii\db\Migration;
  4 +
  5 +/**
  6 + * Handles the creation of table `product`.
  7 + */
  8 +class m220412_144550_create_product_table extends Migration
  9 +{
  10 + /**
  11 + * @inheritdoc
  12 + */
  13 + public function up()
  14 + {
  15 + $this->createTable('product', [
  16 + 'id' => $this->primaryKey(),
  17 + 'status' => $this->boolean(),
  18 + 'sort' => $this->smallInteger(),
  19 + 'sku' =>$this->string(255),
  20 + 'image_id' => $this->integer(),
  21 + ]);
  22 + $this->addForeignKey(
  23 + 'fk-product-image_id',
  24 + 'product',
  25 + 'image_id',
  26 + 'ImageManager',
  27 + 'id',
  28 + 'CASCADE'
  29 + );
  30 + }
  31 +
  32 + /**
  33 + * @inheritdoc
  34 + */
  35 + public function down()
  36 + {
  37 + $this->dropForeignKey(
  38 + 'fk-product-image_id',
  39 + 'product'
  40 + );
  41 + $this->dropTable('product');
  42 + }
  43 +}
... ...
console/migrations/m220412_144602_create_product_lang_table.php 0 → 100644
  1 +<?php
  2 +
  3 +use yii\db\Migration;
  4 +
  5 +/**
  6 + * Handles the creation of table `product_lang`.
  7 + */
  8 +class m220412_144602_create_product_lang_table extends Migration
  9 +{
  10 + /**
  11 + * @inheritdoc
  12 + */
  13 + public function up()
  14 + {
  15 + $this->createTable('product_lang', [
  16 + 'product_id' => $this->integer()->notNull(),
  17 + 'language_id' => $this->smallInteger()->notNull(),
  18 + 'description' => $this->text(),
  19 + 'title' => $this->string(255),
  20 + ]);
  21 + // creates index for column `product_id`
  22 + $this->createIndex(
  23 + 'idx-product_lang-product_id',
  24 + 'product_lang',
  25 + 'product_id'
  26 + );
  27 +
  28 + // add foreign key for table `object`
  29 + $this->addForeignKey(
  30 + 'fk-product_lang-product_id',
  31 + 'product_lang',
  32 + 'product_id',
  33 + 'product',
  34 + 'id',
  35 + 'CASCADE'
  36 + );
  37 +
  38 + // creates index for column `language_id`
  39 + $this->createIndex(
  40 + 'idx-product_lang-language_id',
  41 + 'product_lang',
  42 + 'language_id'
  43 + );
  44 +
  45 + // add foreign key for table `language`
  46 + $this->addForeignKey(
  47 + 'fk-product_lang-language_id',
  48 + 'product_lang',
  49 + 'language_id',
  50 + 'language',
  51 + 'id',
  52 + 'CASCADE'
  53 + );
  54 + // add double primary key
  55 + $this->addPrimaryKey(
  56 + "pk-product_lang-product_id-language_id",
  57 + "product_lang",
  58 + [
  59 + "product_id",
  60 + "language_id",
  61 + ]
  62 + );
  63 + }
  64 +
  65 + /**
  66 + * @inheritdoc
  67 + */
  68 + public function down()
  69 + {
  70 + // drop double primary key
  71 + $this->dropPrimaryKey(
  72 + "pk-product_lang-product_id-language_id",
  73 + "product_lang"
  74 + );
  75 +
  76 + // drops foreign key for table `product`
  77 + $this->dropForeignKey(
  78 + 'fk-product_lang-product_id',
  79 + 'product_lang'
  80 + );
  81 +
  82 + // drops index for column `product_id`
  83 + $this->dropIndex(
  84 + 'idx-product_lang-product_id',
  85 + 'product_lang'
  86 + );
  87 +
  88 + // drops foreign key for table `language`
  89 + $this->dropForeignKey(
  90 + 'fk-product_lang-language_id',
  91 + 'product_lang'
  92 + );
  93 +
  94 + // drops index for column `language_id`
  95 + $this->dropIndex(
  96 + 'idx-product_lang-language_id',
  97 + 'product_lang'
  98 + );
  99 + $this->dropTable('product_lang');
  100 + }
  101 +}
... ...