Blame view

models/OrderProduct.php 3.03 KB
8a7e6ecf   Yarik   Namespaces
1
2
3
4
5
6
7
8
9
10
11
12
13
  <?php
      
      namespace artweb\artbox\ecommerce\models;
      
      use Yii;
      use yii\db\ActiveRecord;
      
      /**
       * Class OrderProduct
       *
       * @property int            $id
       * @property int            $order_id
       * @property int            $product_variant_id
0893579c   Alexey Boroda   -Bug fixed
14
15
16
       * @property string         $booking
       * @property string         $status
       * @property boolean        $return
8a7e6ecf   Yarik   Namespaces
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
       * @property string         $product_name
       * @property string         $name
       * @property string         $sku
       * @property double         $price
       * @property int            $count
       * @property double         $sum_cost
       * @property Order          $order
       * @property ProductVariant $productVariant
       * @package artweb\artbox\ecommerce\models
       */
      class OrderProduct extends ActiveRecord
      {
          
          public static function tableName()
          {
              return 'order_product';
          }
          
01185786   Alexey Boroda   -Sms in process
35
36
37
38
39
40
41
          public function beforeSave($insert)
          {
              $this->price = $this->productVariant->price;
              $this->sum_cost = $this->price * $this->count;
              return parent::beforeSave($insert); // TODO: Change the autogenerated stub
          }
          
8a7e6ecf   Yarik   Namespaces
42
43
44
45
46
47
48
          public function rules()
          {
              return [
                  [
                      [ 'order_id' ],
                      'required',
                  ],
0893579c   Alexey Boroda   -Bug fixed
49
50
51
52
53
54
55
56
57
58
59
                  [
                      [ 'return' ],
                      'boolean',
                  ],
                  [
                      [
                          'booking',
                          'status',
                      ],
                      'string',
                  ],
8a7e6ecf   Yarik   Namespaces
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
                  [
                      [
                          'product_name',
                          'name',
                          'price',
                          'count',
                          'sum_cost',
                          'product_variant_id',
                          'sku',
                      ],
                      'safe',
                  ],
              ];
          }
          
          public function attributeLabels()
          {
              return [
                  'product_name' => Yii::t('app', 'product_name'),
                  'name'         => Yii::t('app', 'op_name'),
                  'art'          => Yii::t('app', 'art'),
                  'cost'         => Yii::t('app', 'cost'),
                  'count'        => Yii::t('app', 'count'),
                  'sum_cost'     => Yii::t('app', 'sum_cost'),
0893579c   Alexey Boroda   -Bug fixed
84
85
86
                  'status'       => Yii::t('app', 'Статус'),
                  'booking'      => Yii::t('app', 'Бронь'),
                  'return'       => Yii::t('app', 'Возврат'),
8a7e6ecf   Yarik   Namespaces
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
              ];
          }
          
          public function getOrder()
          {
              return $this->hasOne(Order::className(), [ 'id' => 'order_id' ]);
          }
          
          /**
           * @return \yii\db\ActiveQuery
           */
          public function getProductVariant()
          {
              return $this->hasOne(ProductVariant::className(), [ 'id' => 'product_variant_id' ]);
          }
      }