Blame view

common/models/Product.php 2.07 KB
8e73da4f   Volodymyr   product models an...
1
2
3
4
5
6
  <?php
  
  namespace common\models;
  
  use artbox\core\behaviors\LanguageBehavior;
  use artbox\core\models\Image;
96c82e64   Volodymyr   product admin price
7
  use Yii;
8e73da4f   Volodymyr   product models an...
8
9
10
11
  use yii\db\ActiveRecord;
  
  class Product extends ActiveRecord
  {
71161f15   Volodymyr   add type to product
12
13
14
15
      const TYPE_BOTH = 0;
      const TYPE_COMPANY = 1;
      const TYPE_PRIVATE = 2;
  
8e73da4f   Volodymyr   product models an...
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
      /**
       * @inheritdoc
       */
      public static function tableName()
      {
          return 'product';
      }
  
      public function behaviors()
      {
          return [
              'language' => [
                  'class' => LanguageBehavior::className(),
              ],
          ];
      }
  
      public function rules()
      {
          return [
  //            [
  //                [
  //                    'image',
  //                ],
  //                'required',
  //            ],
              [
                  [
                      'status',
                  ],
                  'boolean',
              ],
              [
                  [
                      'sku',
96c82e64   Volodymyr   product admin price
51
                      'price',
8e73da4f   Volodymyr   product models an...
52
53
54
55
56
57
58
59
                  ],
                  'string',
                  'max' => 255,
              ],
              [
                  [
                      'sort',
                      'image_id',
71161f15   Volodymyr   add type to product
60
                      'type',
8e73da4f   Volodymyr   product models an...
61
62
63
64
65
66
67
68
69
70
71
72
                  ],
                  'integer',
              ],
              [
                  ['image_id'],
                  'exist',
                  'skipOnError'     => true,
                  'targetClass'     => Image::className(),
                  'targetAttribute' => ['image_id' => 'id'],
              ],
          ];
      }
96c82e64   Volodymyr   product admin price
73
74
75
76
77
78
79
80
81
82
      /**
       * @inheritdoc
       */
      public function attributeLabels()
      {
          return [
              'id'            => Yii::t('core', 'ID'),
              'status'        => Yii::t('core', 'Status'),
              'sort'          => Yii::t('core', 'Sort'),
              'price'          => Yii::t('app', 'Price'),
71161f15   Volodymyr   add type to product
83
              'type'          => 'Тип продукта для главной',
96c82e64   Volodymyr   product admin price
84
  //            'image_mini_id' => Yii::t('core', 'Image Mini'),
8e73da4f   Volodymyr   product models an...
85
  
96c82e64   Volodymyr   product admin price
86
87
          ];
      }
8e73da4f   Volodymyr   product models an...
88
89
90
91
92
93
94
95
      /**
       * @return \yii\db\ActiveQuery
       */
      public function getImage()
      {
          return $this->hasOne(Image::className(), ['id' => 'image_id']);
      }
  }