Blame view

models/OrderProduct.php 4.29 KB
8a7e6ecf   Yarik   Namespaces
1
2
3
4
  <?php
      
      namespace artweb\artbox\ecommerce\models;
      
17569d93   Alexey Boroda   -Order product lo...
5
      use artweb\artbox\ecommerce\components\OrderProductLogger;
8a7e6ecf   Yarik   Namespaces
6
7
8
9
10
11
      use Yii;
      use yii\db\ActiveRecord;
      
      /**
       * Class OrderProduct
       *
e2af367e   Alexey Boroda   -Order product lo...
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
       * @property int               $id
       * @property int               $order_id
       * @property int               $product_variant_id
       * @property string            $booking
       * @property string            $status
       * @property boolean           $return
       * @property string            $product_name
       * @property string            $name
       * @property string            $sku
       * @property double            $price
       * @property int               $count
       * @property double            $sum_cost
       * @property Order             $order
       * @property boolean           $removed
       * @property OrderProductLog[] $logs
       * @property ProductVariant    $productVariant
8a7e6ecf   Yarik   Namespaces
28
29
30
31
32
33
34
35
36
37
       * @package artweb\artbox\ecommerce\models
       */
      class OrderProduct extends ActiveRecord
      {
          
          public static function tableName()
          {
              return 'order_product';
          }
          
17569d93   Alexey Boroda   -Order product lo...
38
39
          public function afterSave($insert, $changedAttributes)
          {
4c64240a   Administrator   select characteri...
40
41
  //            $data = OrderProductLogger::generateData($changedAttributes, $this->oldAttributes, $insert);
  //            OrderProductLogger::saveData($data, $this->id, [ 'order_id' => $this->order_id ]);
17569d93   Alexey Boroda   -Order product lo...
42
43
44
45
              
              parent::afterSave($insert, $changedAttributes);
          }
          
01185786   Alexey Boroda   -Sms in process
46
47
48
49
          public function beforeSave($insert)
          {
              $this->price = $this->productVariant->price;
              $this->sum_cost = $this->price * $this->count;
17569d93   Alexey Boroda   -Order product lo...
50
              return parent::beforeSave($insert);
01185786   Alexey Boroda   -Sms in process
51
52
          }
          
8a7e6ecf   Yarik   Namespaces
53
54
55
56
57
58
59
          public function rules()
          {
              return [
                  [
                      [ 'order_id' ],
                      'required',
                  ],
0893579c   Alexey Boroda   -Bug fixed
60
                  [
28b51b30   Alexey Boroda   -Order module bug...
61
62
63
64
                      [
                          'return',
                          'removed',
                      ],
0893579c   Alexey Boroda   -Bug fixed
65
66
67
68
69
70
71
72
73
                      'boolean',
                  ],
                  [
                      [
                          'booking',
                          'status',
                      ],
                      'string',
                  ],
8a7e6ecf   Yarik   Namespaces
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
                  [
                      [
                          'product_name',
                          'name',
                          'price',
                          'count',
                          'sum_cost',
                          'product_variant_id',
                          'sku',
                      ],
                      'safe',
                  ],
              ];
          }
          
          public function attributeLabels()
          {
              return [
43127bab   Alexey Boroda   -Order translatio...
92
                  'product_name' => Yii::t('app', 'Наименование'),
8a7e6ecf   Yarik   Namespaces
93
94
                  'name'         => Yii::t('app', 'op_name'),
                  'art'          => Yii::t('app', 'art'),
17569d93   Alexey Boroda   -Order product lo...
95
96
                  'cost'         => Yii::t('app', 'Сумма'),
                  'count'        => Yii::t('app', 'Количество'),
43127bab   Alexey Boroda   -Order translatio...
97
                  'sum_cost'     => Yii::t('app', 'Сумма'),
0893579c   Alexey Boroda   -Bug fixed
98
99
100
                  'status'       => Yii::t('app', 'Статус'),
                  'booking'      => Yii::t('app', 'Бронь'),
                  'return'       => Yii::t('app', 'Возврат'),
43127bab   Alexey Boroda   -Order translatio...
101
102
                  'sku'          => Yii::t('app', 'Артикул'),
                  'price'        => Yii::t('app', 'Цена'),
e2af367e   Alexey Boroda   -Order product lo...
103
104
105
106
                  'order_id' => Yii::t('app', 'Id заказа'),
                  'product_variant_id' => Yii::t('app', 'Id товара'),
                  'id' => Yii::t('app', 'Id'),
                  'removed' => Yii::t('app', 'Удален'),
8a7e6ecf   Yarik   Namespaces
107
108
109
              ];
          }
          
e2af367e   Alexey Boroda   -Order product lo...
110
111
112
          /**
           * @return \yii\db\ActiveQuery
           */
8a7e6ecf   Yarik   Namespaces
113
114
115
116
117
118
119
120
121
122
123
124
          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' ]);
          }
e2af367e   Alexey Boroda   -Order product lo...
125
126
127
128
129
130
131
132
          
          /**
           * @return \yii\db\ActiveQuery
           */
          public function getLogs()
          {
              return $this->hasMany(OrderProductLog::className(), [ 'order_product_id' => 'id' ]);
          }
8a7e6ecf   Yarik   Namespaces
133
      }