4bf9edb7
Yarik
Order
|
1
2
3
|
<?php
namespace frontend\models;
|
6c8e3423
Yarik
Fast buy
|
4
5
|
use artbox\catalog\models\Variant;
|
4bf9edb7
Yarik
Order
|
6
7
|
use artbox\order\models\Delivery;
use artbox\order\models\Payment;
|
543f1653
Yarik
Fixed
|
8
9
|
use yii\behaviors\BlameableBehavior;
|
4bf9edb7
Yarik
Order
|
10
11
|
class Order extends \artbox\order\models\Order
{
|
6c8e3423
Yarik
Fast buy
|
12
|
public $variantId;
|
35b13e82
Yarik
Fixes
|
13
|
public $returnUrl;
|
6c8e3423
Yarik
Fast buy
|
14
|
|
4bf9edb7
Yarik
Order
|
15
16
17
18
|
const SCENARIO_INFO = 'info';
const SCENARIO_DELIVERY = 'delivery';
const SCENARIO_PAYMENT = 'payment';
const SCENARIO_CONFIRM = 'confirm';
|
6c8e3423
Yarik
Fast buy
|
19
20
|
const SCENARIO_FAST = 'fast';
|
4bf9edb7
Yarik
Order
|
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
/**
* @inheritdoc
*/
public function scenarios()
{
return array_merge(
parent::scenarios(),
[
self::SCENARIO_INFO => [
'name',
'phone',
'email',
'city',
'address',
'comment',
],
self::SCENARIO_DELIVERY => [
'delivery_id',
],
self::SCENARIO_PAYMENT => [
'payment_id',
],
|
6c8e3423
Yarik
Fast buy
|
43
44
45
46
|
self::SCENARIO_FAST => [
'name',
'phone',
'variantId',
|
35b13e82
Yarik
Fixes
|
47
|
'returnUrl',
|
6c8e3423
Yarik
Fast buy
|
48
|
],
|
4bf9edb7
Yarik
Order
|
49
50
51
|
]
);
}
|
6c8e3423
Yarik
Fast buy
|
52
|
|
543f1653
Yarik
Fixed
|
53
54
|
public function behaviors()
{
|
fa8dafba
Alexey Boroda
-User's password ...
|
55
56
57
58
59
|
$behaviors = parent::behaviors();
$behaviors[] = [
'class' => BlameableBehavior::className(),
'createdByAttribute' => 'user_id',
'updatedByAttribute' => false,
|
543f1653
Yarik
Fixed
|
60
|
];
|
fa8dafba
Alexey Boroda
-User's password ...
|
61
|
return $behaviors;
|
543f1653
Yarik
Fixed
|
62
63
|
}
|
4bf9edb7
Yarik
Order
|
64
65
66
67
68
69
70
71
72
73
74
75
76
|
/**
* @inheritdoc
*/
public function rules()
{
return [
[
[
'name',
'phone',
'email',
'delivery_id',
'payment_id',
|
4bf9edb7
Yarik
Order
|
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
],
'required',
],
[
[
'name',
'phone',
'email',
'city',
'address',
],
'string',
'max' => 255,
],
[
[
'comment',
|
35b13e82
Yarik
Fixes
|
94
|
'returnUrl',
|
4bf9edb7
Yarik
Order
|
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
|
],
'string',
],
[
[
'delivery_id',
'payment_id',
],
'integer',
],
[
[
'delivery_id',
],
'exist',
'targetClass' => Delivery::className(),
'targetAttribute' => 'id',
],
[
[
'payment_id',
],
'exist',
'targetClass' => Payment::className(),
'targetAttribute' => 'id',
],
|
6c8e3423
Yarik
Fast buy
|
121
122
|
[
[
|
e67c95f9
Yarik
Fast buy
|
123
|
'variantId',
|
6c8e3423
Yarik
Fast buy
|
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
],
'exist',
'targetClass' => Variant::className(),
'targetAttribute' => 'id',
'filter' => function ($query) {
/**
* @var \yii\db\Query $query
*/
$query->andWhere(
[
'>',
'price',
0,
]
)
->andWhere([ 'status' => true ])
->andWhere(
[
'>',
'stock',
0,
]
);
},
|
e67c95f9
Yarik
Fast buy
|
148
149
150
151
152
153
154
155
|
'on' => self::SCENARIO_FAST,
],
[
[
'variantId',
],
'required',
'on' => self::SCENARIO_FAST,
|
6c8e3423
Yarik
Fast buy
|
156
|
],
|
4bf9edb7
Yarik
Order
|
157
158
|
];
}
|
6c8e3423
Yarik
Fast buy
|
159
|
|
4bf9edb7
Yarik
Order
|
160
161
162
163
164
165
166
167
168
169
170
|
/**
* Save active attributes to session variable 'order'
*/
public function saveActive()
{
$order = \Yii::$app->session->get('order', []);
foreach ($this->activeAttributes() as $attribute) {
$order[ $attribute ] = $this->getAttribute($attribute);
}
\Yii::$app->session[ 'order' ] = $order;
}
|
6c8e3423
Yarik
Fast buy
|
171
|
|
4bf9edb7
Yarik
Order
|
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
/**
* Load active attributes from session variable 'order'
*/
public function loadActive()
{
$order = \Yii::$app->session->get('order');
if (!empty($order)) {
foreach ($this->activeAttributes() as $attribute) {
if (!empty($order[ $attribute ])) {
$this->setAttribute($attribute, $order[ $attribute ]);
}
}
}
}
}
|