Commit c6435b1f47b7f1177f6ff271a61ed810eff61ab0

Authored by Administrator
1 parent e590d126

image size

@@ -97,8 +97,6 @@ ExpiresByType image/x-icon "access 1 year" @@ -97,8 +97,6 @@ ExpiresByType image/x-icon "access 1 year"
97 ExpiresByType application/x-shockwave-flash "access 1 year" 97 ExpiresByType application/x-shockwave-flash "access 1 year"
98 </IfModule> 98 </IfModule>
99 99
100 -  
101 -# кеширование в браузере на стороне пользователя  
102 <IfModule mod_deflate.c> 100 <IfModule mod_deflate.c>
103 AddOutputFilterByType DEFLATE text/plain 101 AddOutputFilterByType DEFLATE text/plain
104 AddOutputFilterByType DEFLATE text/html 102 AddOutputFilterByType DEFLATE text/html
common/models/Orders.php
@@ -17,8 +17,7 @@ class Orders extends \yii\db\ActiveRecord @@ -17,8 +17,7 @@ class Orders extends \yii\db\ActiveRecord
17 { 17 {
18 return [ 18 return [
19 [['name', 'phone'], 'required','whenClient' => true], 19 [['name', 'phone'], 'required','whenClient' => true],
20 - //['email', 'email'],  
21 - [['total','body','email','phone2','delivery','payment'], 'safe'], 20 + [['total','body','email','phone2','delivery','payment','adress','city'], 'safe'],
22 [['email'],'email'], 21 [['email'],'email'],
23 ]; 22 ];
24 } 23 }
frontend/controllers/OrdersController.php deleted
1 -<?php  
2 -  
3 -namespace frontend\controllers;  
4 -  
5 -use common\models\Customer;  
6 -use common\models\OrderItems;  
7 -use common\models\Orders;  
8 -use common\modules\product\models\ProductVariant;  
9 -use common\widgets\BasketModal;  
10 -use Yii;  
11 -  
12 -use yii\web\Controller;  
13 -use yii\web\NotFoundHttpException;  
14 -use yii\data\ArrayDataProvider;  
15 -/**  
16 - * OrderController implements the CRUD actions for Order model.  
17 - */  
18 -class OrdersController extends Controller  
19 -{  
20 -  
21 -  
22 - /**  
23 - * @inheritdoc  
24 - */  
25 - public function beforeAction($action)  
26 - {  
27 - if ($action->id == 'buy-items' || $action->id == 'delete') {  
28 - Yii::$app->controller->enableCsrfValidation = false;  
29 - }  
30 -  
31 - return true;  
32 - }  
33 -  
34 - public function actionFirst(){  
35 -  
36 - $array = Yii::$app->session->get('order');  
37 -  
38 - if(isset($array['order_id']) ) {  
39 - $model = Orders::findOne($array['order_id']);  
40 - }else {  
41 - $model = new Orders();  
42 - }  
43 -  
44 -  
45 - if(Yii::$app->request->post() && $model->load(Yii::$app->request->post())){  
46 -  
47 - if($model->save()){  
48 -  
49 - $array['order_id'] = $model->order_id;  
50 -  
51 - Yii::$app->session->set('order', $array );  
52 -  
53 - return $this->redirect(['orders/second']);  
54 - }  
55 -  
56 - } else {  
57 - if (!Yii::$app->user->isGuest) {  
58 - $customer = Yii::$app->user->identity;  
59 - $model->name = $customer->name;  
60 - $model->email = $customer->email;  
61 - $model->phone = $customer->phone;  
62 - }  
63 - }  
64 -  
65 -  
66 - return $this->render('basket-step-01',[  
67 - 'model' => $model  
68 - ]);  
69 - }  
70 -  
71 - public function actionSecond(){  
72 -  
73 - $sessionData = \Yii::$app->session->get('order');  
74 -  
75 - $order_id = $sessionData['order_id'];  
76 -  
77 - if(!empty($order_id)){  
78 - $order_model = Orders::findOne($order_id);  
79 - } else{  
80 - $order_model = new Orders;  
81 - }  
82 -  
83 - unset($sessionData['order_id']);  
84 -  
85 - $variant = ProductVariant::find()->where(['product_variant_id'=>array_keys($sessionData)])->indexBy('product_variant_id')->all();  
86 -  
87 -  
88 - if(Yii::$app->request->post()){  
89 -  
90 - foreach ($sessionData as $k => $item) {  
91 - $itemModel = OrderItems::find()->where(['order_id'=>$order_id, 'item_id'=> $variant[$k]->product_variant_id])->one();  
92 - if($itemModel instanceof OrderItems){  
93 - $itemModel->order_id = $order_id;  
94 - $itemModel->item_id = $variant[$k]->product_variant_id;  
95 - $itemModel->item_count = $sessionData[$k]['num'];  
96 - $itemModel->price = $variant[$k]->price;  
97 - $itemModel->save();  
98 - } else {  
99 - $itemModel = new OrderItems();  
100 - $itemModel->order_id = $order_id;  
101 - $itemModel->item_id = $variant[$k]->product_variant_id;  
102 - $itemModel->item_count = $sessionData[$k]['num'];  
103 - $itemModel->price = $variant[$k]->price;  
104 - $itemModel->save();  
105 - }  
106 -  
107 - }  
108 - Yii::$app->session->set('order', [] );  
109 - return $this->redirect(['orders/third']);  
110 -  
111 - } else {  
112 -  
113 - $price = 0;  
114 -  
115 - $count = count($sessionData);  
116 -  
117 - foreach ($sessionData as $k => $item) {  
118 - $sessionData[$k]['item'] = $variant[$k];  
119 - $price += $variant[$k]->price * $sessionData[$k]['num'];  
120 - }  
121 -  
122 - }  
123 -  
124 - return $this->render('basket-step-02',[  
125 - 'items'=>$sessionData,  
126 - 'count' => $count,  
127 - 'price' => $price,  
128 - 'order_id' => $order_id,  
129 - 'order_model' => $order_model,  
130 - ]);  
131 -  
132 - }  
133 -  
134 - public function actionThird(){  
135 - return $this->render('basket-step-03');  
136 - }  
137 -  
138 -  
139 -// /**  
140 -// * Lists all Order models.  
141 -// * @return mixed  
142 -// */  
143 -// public function actionIndex()  
144 -// {  
145 -//  
146 -// if (Yii::$app->request->post()) {  
147 -// $item = $items_id = array();  
148 -//  
149 -// $i = 0;  
150 -// $order = Yii::$app->request->post();  
151 -//  
152 -// $orderData['Order'] = $order['OrderForm'];  
153 -//  
154 -// foreach($order['OrderForm']['one_item'] as $k => $v ){  
155 -// $item[$k]['num'] = $v['num'];  
156 -// $items_id[] = $k;  
157 -// $i++;  
158 -// }  
159 -//  
160 -// $items = Items::find()->where(['id'=>$items_id])->all();  
161 -//  
162 -//  
163 -// $orderModel = new Order();  
164 -// $orderModel->load($orderData);  
165 -// $orderModel->save();  
166 -//  
167 -//  
168 -// foreach($items as $one_item){  
169 -// $ItemOrderModel = new ItemOrder();  
170 -// $ItemOrderModel->order_id = $orderModel->id;  
171 -// $ItemOrderModel->num = $item[$one_item->id]['num'];  
172 -// $ItemOrderModel->item_id = $one_item->id;  
173 -// $ItemOrderModel->price = $one_item->price * $item[$one_item->id]['num'];  
174 -// $ItemOrderModel->item_name = $one_item->name;  
175 -// $ItemOrderModel->save();  
176 -// }  
177 -// Yii::$app->session->set('order', [] );  
178 -// return $this->redirect(['order/complete']);  
179 -// }  
180 -// $total_price = 0;  
181 -//  
182 -// $items_id = [];  
183 -//  
184 -// $orders = Yii::$app->session->get('order');  
185 -//  
186 -// if(!empty($orders)){  
187 -// foreach($orders as $k => $v) {  
188 -// $items_id[] = $k;  
189 -// }  
190 -// }  
191 -//  
192 -//  
193 -// $items = Items::find()->where(['id'=>$items_id])->all();  
194 -//  
195 -// foreach($items as $item) {  
196 -// $total_price += $orders[$item['id']]['num'] * $item['price'];  
197 -// }  
198 -//  
199 -//  
200 -// $dataProvider = new ArrayDataProvider([  
201 -// 'allModels' => $items  
202 -// ]);  
203 -//  
204 -// return $this->render('index', [  
205 -// 'dataProvider' => $dataProvider,  
206 -// 'total_price'=> $total_price,  
207 -// 'model' => new OrderForm()  
208 -// ]);  
209 -// }  
210 -  
211 -  
212 - public function actionComplete()  
213 - {  
214 - return $this->render('complete', [  
215 - ]);  
216 - }  
217 -  
218 - public function actionBuyItems(){  
219 - $data = Yii::$app->request->post();  
220 - $sessionData = Yii::$app->session->get('order');  
221 - if(isset($sessionData) && !array_search($data['id'],Yii::$app->session->get('order')) ){  
222 - $array = Yii::$app->session->get('order');  
223 - $array[$data['id']] = $data;  
224 - Yii::$app->session->set('order', $array );  
225 - } else {  
226 - $array[$data['id']] = $data;  
227 - Yii::$app->session->set('order', $array );  
228 - }  
229 - echo BasketModal::widget([]);  
230 -  
231 - }  
232 - /**  
233 - * Displays a single Order model.  
234 - * @param integer $id  
235 - * @return mixed  
236 - */  
237 - public function actionView($id)  
238 - {  
239 - return $this->render('view', [  
240 - 'model' => $this->findModel($id),  
241 - ]);  
242 - }  
243 -  
244 - /**  
245 - * Creates a new Order model.  
246 - * If creation is successful, the browser will be redirected to the 'view' page.  
247 - * @return mixed  
248 - */  
249 - public function actionCreate()  
250 - {  
251 - $model = new Orders();  
252 -  
253 - if ($model->load(Yii::$app->request->post()) && $model->save()) {  
254 - return $this->redirect(['view', 'id' => $model->id]);  
255 - } else {  
256 - return $this->render('create', [  
257 - 'model' => $model,  
258 - ]);  
259 - }  
260 - }  
261 -  
262 - /**  
263 - * Updates an existing Order model.  
264 - * If update is successful, the browser will be redirected to the 'view' page.  
265 - * @param integer $id  
266 - * @return mixed  
267 - */  
268 - public function actionUpdate($id)  
269 - {  
270 - $model = $this->findModel($id);  
271 -  
272 - if ($model->load(Yii::$app->request->post()) && $model->save()) {  
273 - return $this->redirect(['view', 'id' => $model->id]);  
274 - } else {  
275 - return $this->render('update', [  
276 - 'model' => $model,  
277 - ]);  
278 - }  
279 - }  
280 -  
281 - /**  
282 - * Deletes an existing Order model.  
283 - * If deletion is successful, the browser will be redirected to the 'index' page.  
284 - * @param integer $id  
285 - * @return mixed  
286 - */  
287 - public function actionDelete()  
288 - {  
289 - $data = Yii::$app->request->post();  
290 - $sessionData = Yii::$app->session->get('order');  
291 - unset($sessionData[$data['id']]);  
292 - Yii::$app->session->set('order', $sessionData);  
293 - return count(Yii::$app->session->get('order'));  
294 - }  
295 -  
296 - /**  
297 - * Finds the Order model based on its primary key value.  
298 - * If the model is not found, a 404 HTTP exception will be thrown.  
299 - * @param integer $id  
300 - * @return Orders the loaded model  
301 - * @throws NotFoundHttpException if the model cannot be found  
302 - */  
303 - protected function findModel($id)  
304 - {  
305 - if (($model = Orders::findOne($id)) !== null) {  
306 - return $model;  
307 - } else {  
308 - throw new NotFoundHttpException('The requested page does not exist.');  
309 - }  
310 - }  
311 -}