d8c1a2e0
Yarik
Big commit artbox
|
1
|
<?php
|
5c2eb7c8
Yarik
Big commit almost...
|
2
3
4
5
6
|
namespace common\modules\product\models;
use yii\db\ActiveRecord;
|
d8c1a2e0
Yarik
Big commit artbox
|
7
|
/**
|
5c2eb7c8
Yarik
Big commit almost...
|
8
|
* This is the model class for table "product_stock".
|
4428da8c
Yarik
Almost all databa...
|
9
|
*
|
5c2eb7c8
Yarik
Big commit almost...
|
10
11
12
13
14
15
|
* @property integer $stock_id
* @property integer $quantity
* @property integer $product_variant_id
* @property Product $product
* @property ProductVariant $productVariant
* @property Stock $stock
|
772a3ca4
Yarik
Big commit
|
16
|
* @property string $title
|
d8c1a2e0
Yarik
Big commit artbox
|
17
|
*/
|
5c2eb7c8
Yarik
Big commit almost...
|
18
|
class ProductStock extends ActiveRecord
|
d8c1a2e0
Yarik
Big commit artbox
|
19
|
{
|
772a3ca4
Yarik
Big commit
|
20
|
protected $title;
|
5c2eb7c8
Yarik
Big commit almost...
|
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
/**
* @inheritdoc
*/
public static function tableName()
{
return 'product_stock';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[
[
|
5c2eb7c8
Yarik
Big commit almost...
|
37
38
39
40
41
42
43
|
'stock_id',
'quantity',
'product_variant_id',
],
'integer',
],
[
|
8af13427
Yarik
For leha commit.
|
44
|
[ 'title' ],
|
5c2eb7c8
Yarik
Big commit almost...
|
45
46
47
|
'required',
],
[
|
5c2eb7c8
Yarik
Big commit almost...
|
48
49
50
51
|
[ 'product_variant_id' ],
'exist',
'skipOnError' => true,
'targetClass' => ProductVariant::className(),
|
4428da8c
Yarik
Almost all databa...
|
52
|
'targetAttribute' => [ 'product_variant_id' => 'id' ],
|
5c2eb7c8
Yarik
Big commit almost...
|
53
54
55
56
57
58
|
],
[
[ 'stock_id' ],
'exist',
'skipOnError' => true,
'targetClass' => Stock::className(),
|
4428da8c
Yarik
Almost all databa...
|
59
|
'targetAttribute' => [ 'stock_id' => 'id' ],
|
5c2eb7c8
Yarik
Big commit almost...
|
60
61
62
63
64
65
66
67
68
69
|
],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
|
5c2eb7c8
Yarik
Big commit almost...
|
70
71
72
|
'stock_id' => 'Stock ID',
'quantity' => 'Количество',
'product_variant_id' => 'Product Variant ID',
|
4428da8c
Yarik
Almost all databa...
|
73
|
'title' => "Название",
|
5c2eb7c8
Yarik
Big commit almost...
|
74
75
76
77
78
79
80
81
|
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getProduct()
{
|
4428da8c
Yarik
Almost all databa...
|
82
83
|
return $this->hasOne(Product::className(), [ 'id' => 'product_id' ])
->via('variants');
|
5c2eb7c8
Yarik
Big commit almost...
|
84
85
86
87
88
89
90
|
}
/**
* @return \yii\db\ActiveQuery
*/
public function getProductVariant()
{
|
4428da8c
Yarik
Almost all databa...
|
91
|
return $this->hasOne(ProductVariant::className(), [ 'id' => 'product_variant_id' ]);
|
5c2eb7c8
Yarik
Big commit almost...
|
92
93
|
}
|
772a3ca4
Yarik
Big commit
|
94
95
96
97
98
99
|
/**
* Get Stock title, tries to get from Stock lang
*
* @return string
*/
public function getTitle(): string
|
5c2eb7c8
Yarik
Big commit almost...
|
100
|
{
|
772a3ca4
Yarik
Big commit
|
101
102
103
104
105
106
107
|
if (!empty( $this->title )) {
return $this->title;
} elseif (!empty( $this->stock )) {
return $this->stock->lang->title;
} else {
return '';
}
|
5c2eb7c8
Yarik
Big commit almost...
|
108
|
}
|
4428da8c
Yarik
Almost all databa...
|
109
|
|
5c2eb7c8
Yarik
Big commit almost...
|
110
|
/**
|
772a3ca4
Yarik
Big commit
|
111
|
* Set Stock title, will be saved to Stock table
|
5c2eb7c8
Yarik
Big commit almost...
|
112
113
114
|
*
* @param mixed $value
*/
|
772a3ca4
Yarik
Big commit
|
115
|
public function setTitle(string $value)
|
5c2eb7c8
Yarik
Big commit almost...
|
116
|
{
|
8af13427
Yarik
For leha commit.
|
117
|
$this->title = $value;
|
5c2eb7c8
Yarik
Big commit almost...
|
118
119
120
121
122
123
124
|
}
/**
* @return \yii\db\ActiveQuery
*/
public function getStock()
{
|
4428da8c
Yarik
Almost all databa...
|
125
|
return $this->hasOne(Stock::className(), [ 'id' => 'stock_id' ]);
|
5c2eb7c8
Yarik
Big commit almost...
|
126
127
|
}
|
772a3ca4
Yarik
Big commit
|
128
129
130
|
/**
* @inheritdoc
*/
|
5c2eb7c8
Yarik
Big commit almost...
|
131
132
133
134
135
136
137
|
public static function primaryKey()
{
return [
"stock_id",
"product_variant_id",
];
}
|
d8c1a2e0
Yarik
Big commit artbox
|
138
|
}
|