OrderProduct.php
4.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
namespace artweb\artbox\ecommerce\models;
use artweb\artbox\ecommerce\components\OrderProductLogger;
use Yii;
use yii\db\ActiveRecord;
/**
* Class OrderProduct
*
* @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
* @package artweb\artbox\ecommerce\models
*/
class OrderProduct extends ActiveRecord
{
public static function tableName()
{
return 'order_product';
}
public function afterSave($insert, $changedAttributes)
{
// $data = OrderProductLogger::generateData($changedAttributes, $this->oldAttributes, $insert);
// OrderProductLogger::saveData($data, $this->id, [ 'order_id' => $this->order_id ]);
parent::afterSave($insert, $changedAttributes);
}
public function beforeSave($insert)
{
$this->price = $this->productVariant->price;
$this->sum_cost = $this->price * $this->count;
return parent::beforeSave($insert);
}
public function rules()
{
return [
[
[ 'order_id' ],
'required',
],
[
[
'return',
'removed',
],
'boolean',
],
[
[
'booking',
'status',
],
'string',
],
[
[
'product_name',
'name',
'price',
'count',
'sum_cost',
'product_variant_id',
'sku',
],
'safe',
],
];
}
public function attributeLabels()
{
return [
'product_name' => Yii::t('app', 'Наименование'),
'name' => Yii::t('app', 'op_name'),
'art' => Yii::t('app', 'art'),
'cost' => Yii::t('app', 'Сумма'),
'count' => Yii::t('app', 'Количество'),
'sum_cost' => Yii::t('app', 'Сумма'),
'status' => Yii::t('app', 'Статус'),
'booking' => Yii::t('app', 'Бронь'),
'return' => Yii::t('app', 'Возврат'),
'sku' => Yii::t('app', 'Артикул'),
'price' => Yii::t('app', 'Цена'),
'order_id' => Yii::t('app', 'Id заказа'),
'product_variant_id' => Yii::t('app', 'Id товара'),
'id' => Yii::t('app', 'Id'),
'removed' => Yii::t('app', 'Удален'),
];
}
/**
* @return \yii\db\ActiveQuery
*/
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' ]);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getLogs()
{
return $this->hasMany(OrderProductLog::className(), [ 'order_product_id' => 'id' ]);
}
}