@@ -10,146 +10,146 @@ discard block |
||
10 | 10 | */ |
11 | 11 | class CartController extends Controller { |
12 | 12 | |
13 | - public function indexAction() { |
|
13 | + public function indexAction() { |
|
14 | 14 | $cart = ''; |
15 | 15 | $deliverys = \Ecommerce\Delivery::getList(['order' => ['weight', 'ASC']]); |
16 | 16 | $payTypes = \Ecommerce\PayType::getList(['order' => ['weight', 'ASC']]); |
17 | 17 | if (!empty($_SESSION['cart']['cart_id'])) { |
18 | - $cart = Ecommerce\Cart::get($_SESSION['cart']['cart_id']); |
|
19 | - if (!empty($_POST)) { |
|
18 | + $cart = Ecommerce\Cart::get($_SESSION['cart']['cart_id']); |
|
19 | + if (!empty($_POST)) { |
|
20 | 20 | $error = false; |
21 | 21 | if (!Users\User::$cur->id) { |
22 | - $user_id = $this->Users->registration($_POST, true); |
|
23 | - if (!$user_id) { |
|
22 | + $user_id = $this->Users->registration($_POST, true); |
|
23 | + if (!$user_id) { |
|
24 | 24 | $error = true; |
25 | - } else { |
|
25 | + } else { |
|
26 | 26 | $user = Users\User::get($user_id); |
27 | - } |
|
27 | + } |
|
28 | 28 | } else { |
29 | - $user = Users\User::$cur; |
|
29 | + $user = Users\User::$cur; |
|
30 | 30 | } |
31 | 31 | $ids = []; |
32 | 32 | if (!empty($_POST['cartItems'])) { |
33 | - foreach ($_POST['cartItems'] as $cartItemId => $cartItemCont) { |
|
33 | + foreach ($_POST['cartItems'] as $cartItemId => $cartItemCont) { |
|
34 | 34 | $cartItem = \Ecommerce\Cart\Item::get((int) $cartItemId); |
35 | 35 | if (!$cartItem) { |
36 | - continue; |
|
36 | + continue; |
|
37 | 37 | } |
38 | 38 | if ($cartItem->cart_id != $cart->id) { |
39 | - continue; |
|
39 | + continue; |
|
40 | 40 | } |
41 | 41 | $count = (float) $cartItemCont; |
42 | 42 | if ($count < 0.001) { |
43 | - $count = 1; |
|
43 | + $count = 1; |
|
44 | 44 | } |
45 | 45 | $cartItem->count = $count; |
46 | 46 | $cartItem->save(); |
47 | 47 | $ids[] = $cartItemId; |
48 | - } |
|
48 | + } |
|
49 | 49 | } |
50 | 50 | foreach ($cart->cartItems as $cartItem) { |
51 | - if (!in_array($cartItem->id, $ids)) { |
|
51 | + if (!in_array($cartItem->id, $ids)) { |
|
52 | 52 | $cartItem->delete(); |
53 | - } |
|
53 | + } |
|
54 | 54 | } |
55 | 55 | $cart = Ecommerce\Cart::get($cart->id); |
56 | 56 | if (!$cart->cartItems) { |
57 | - $error = true; |
|
58 | - //Tools::redirect('/ecommerce', 'Ваша корзина пуста'); |
|
57 | + $error = true; |
|
58 | + //Tools::redirect('/ecommerce', 'Ваша корзина пуста'); |
|
59 | 59 | } |
60 | 60 | if (empty($this->module->config['sell_over_warehouse'])) { |
61 | - foreach ($cart->cartItems as $cartitem) { |
|
61 | + foreach ($cart->cartItems as $cartitem) { |
|
62 | 62 | $warecount = $cartitem->price->offer->warehouseCount($cart->id); |
63 | 63 | if ($cartitem->count > $warecount) { |
64 | - $error = true; |
|
65 | - Msg::add('Вы заказали <b>' . $cartitem->item->name . '</b> больше чем есть на складе. на складе: <b>' . $warecount . '</b>', 'danger'); |
|
64 | + $error = true; |
|
65 | + Msg::add('Вы заказали <b>' . $cartitem->item->name . '</b> больше чем есть на складе. на складе: <b>' . $warecount . '</b>', 'danger'); |
|
66 | + } |
|
66 | 67 | } |
67 | - } |
|
68 | 68 | } |
69 | 69 | if ($deliverys && empty($deliverys[$_POST['delivery']])) { |
70 | - $error = 1; |
|
71 | - Msg::add('Выберите способ доставки', 'danger'); |
|
70 | + $error = 1; |
|
71 | + Msg::add('Выберите способ доставки', 'danger'); |
|
72 | 72 | } elseif ($deliverys && !empty($deliverys[$_POST['delivery']])) { |
73 | - $cart->delivery_id = $_POST['delivery']; |
|
74 | - foreach ($deliverys[$cart->delivery_id]->fields as $field) { |
|
73 | + $cart->delivery_id = $_POST['delivery']; |
|
74 | + foreach ($deliverys[$cart->delivery_id]->fields as $field) { |
|
75 | 75 | if (empty($_POST['deliveryFields'][$field->id]) && $field->required) { |
76 | - $error = 1; |
|
77 | - Msg::add('Вы не указали: ' . $field->name, 'danger'); |
|
76 | + $error = 1; |
|
77 | + Msg::add('Вы не указали: ' . $field->name, 'danger'); |
|
78 | + } |
|
78 | 79 | } |
79 | - } |
|
80 | 80 | } |
81 | 81 | if ($payTypes && (empty($_POST['payType']) || empty($payTypes[$_POST['payType']]))) { |
82 | - $error = 1; |
|
83 | - Msg::add('Выберите способ оплаты', 'danger'); |
|
82 | + $error = 1; |
|
83 | + Msg::add('Выберите способ оплаты', 'danger'); |
|
84 | 84 | } elseif ($payTypes && !empty($payTypes[$_POST['payType']])) { |
85 | - $payType = $payTypes[$_POST['payType']]; |
|
86 | - $cart->paytype_id = $payType->id; |
|
85 | + $payType = $payTypes[$_POST['payType']]; |
|
86 | + $cart->paytype_id = $payType->id; |
|
87 | 87 | } else { |
88 | - $payType = null; |
|
88 | + $payType = null; |
|
89 | 89 | } |
90 | 90 | foreach (\Ecommerce\UserAdds\Field::getList() as $field) { |
91 | - if (empty($_POST['userAdds']['fields'][$field->id]) && $field->required) { |
|
91 | + if (empty($_POST['userAdds']['fields'][$field->id]) && $field->required) { |
|
92 | 92 | $error = 1; |
93 | 93 | Msg::add('Вы не указали: ' . $field->name, 'danger'); |
94 | - } |
|
94 | + } |
|
95 | 95 | } |
96 | 96 | if (!empty($_POST['discounts']['card_item_id'])) { |
97 | - $userCard = \Ecommerce\Card\Item::get((int) $_POST['discounts']['card_item_id']); |
|
98 | - if (!$userCard) { |
|
97 | + $userCard = \Ecommerce\Card\Item::get((int) $_POST['discounts']['card_item_id']); |
|
98 | + if (!$userCard) { |
|
99 | 99 | $error = true; |
100 | 100 | Msg::add('Такой карты не существует', 'danger'); |
101 | - } elseif ($userCard->user_id != $user->id) { |
|
101 | + } elseif ($userCard->user_id != $user->id) { |
|
102 | 102 | $error = true; |
103 | 103 | Msg::add('Это не ваша карта', 'danger'); |
104 | - } else { |
|
104 | + } else { |
|
105 | 105 | $cart->card_item_id = $userCard->id; |
106 | - } |
|
106 | + } |
|
107 | 107 | } |
108 | 108 | $cart->save(); |
109 | 109 | if (!$error && !empty($_POST['action']) && $_POST['action'] = 'order') { |
110 | - $cart->user_id = $user->user_id; |
|
111 | - $this->module->parseFields($_POST['userAdds']['fields'], $cart); |
|
112 | - if ($payTypes && !empty($payTypes[$cart->paytype_id]) && !empty($_POST['deliveryFields'])) { |
|
110 | + $cart->user_id = $user->user_id; |
|
111 | + $this->module->parseFields($_POST['userAdds']['fields'], $cart); |
|
112 | + if ($payTypes && !empty($payTypes[$cart->paytype_id]) && !empty($_POST['deliveryFields'])) { |
|
113 | 113 | $this->module->parseDeliveryFields($_POST['deliveryFields'], $cart, $deliverys[$cart->delivery_id]->fields); |
114 | - } |
|
115 | - $cart->cart_status_id = 2; |
|
116 | - $cart->comment = !empty($_POST['comment']) ? htmlspecialchars($_POST['comment']) : ''; |
|
117 | - $cart->date_status = date('Y-m-d H:i:s'); |
|
118 | - $cart->complete_data = date('Y-m-d H:i:s'); |
|
119 | - $cart->warehouse_block = 1; |
|
120 | - $cart->save(); |
|
114 | + } |
|
115 | + $cart->cart_status_id = 2; |
|
116 | + $cart->comment = !empty($_POST['comment']) ? htmlspecialchars($_POST['comment']) : ''; |
|
117 | + $cart->date_status = date('Y-m-d H:i:s'); |
|
118 | + $cart->complete_data = date('Y-m-d H:i:s'); |
|
119 | + $cart->warehouse_block = 1; |
|
120 | + $cart->save(); |
|
121 | 121 | |
122 | - $cart = \Ecommerce\Cart::get($cart->id); |
|
123 | - foreach ($cart->cartItems as $cartItem) { |
|
122 | + $cart = \Ecommerce\Cart::get($cart->id); |
|
123 | + foreach ($cart->cartItems as $cartItem) { |
|
124 | 124 | $cartItem->discount = $cartItem->discount(); |
125 | 125 | $cartItem->final_price = $cartItem->price->price - $cartItem->discount; |
126 | 126 | $cartItem->save(); |
127 | - } |
|
128 | - $cart = \Ecommerce\Cart::get($cart->id); |
|
129 | - if (!empty(\App::$cur->ecommerce->config['notify_mail'])) { |
|
127 | + } |
|
128 | + $cart = \Ecommerce\Cart::get($cart->id); |
|
129 | + if (!empty(\App::$cur->ecommerce->config['notify_mail'])) { |
|
130 | 130 | $text = 'Перейдите в админ панель чтобы просмотреть новый заказ <a href = "http://' . idn_to_utf8(INJI_DOMAIN_NAME) . '/admin/ecommerce/Cart">Админ панель</a>'; |
131 | 131 | $title = 'Новый заказ в интернет магазине на сайте ' . idn_to_utf8(INJI_DOMAIN_NAME); |
132 | 132 | \Tools::sendMail('noreply@' . INJI_DOMAIN_NAME, \App::$cur->ecommerce->config['notify_mail'], $title, $text); |
133 | - } |
|
134 | - if ($this->notifications) { |
|
133 | + } |
|
134 | + if ($this->notifications) { |
|
135 | 135 | $notification = new Notifications\Notification(); |
136 | 136 | $notification->name = 'Новый заказ в интернет магазине на сайте ' . idn_to_utf8(INJI_DOMAIN_NAME); |
137 | 137 | $notification->text = 'Перейдите в админ панель чтобы просмотреть новый заказ'; |
138 | 138 | $notification->chanel_id = $this->notifications->getChanel('Ecommerce-orders')->id; |
139 | 139 | $notification->save(); |
140 | - } |
|
141 | - $handlers = $this->ecommerce->getSnippets('payTypeHandler'); |
|
142 | - $redirect = ['/ecommerce/cart/success']; |
|
143 | - if ($payType && !empty($handlers[$payType->handler]['handler'])) { |
|
140 | + } |
|
141 | + $handlers = $this->ecommerce->getSnippets('payTypeHandler'); |
|
142 | + $redirect = ['/ecommerce/cart/success']; |
|
143 | + if ($payType && !empty($handlers[$payType->handler]['handler'])) { |
|
144 | 144 | $newRedirect = $handlers[$payType->handler]['handler']($cart); |
145 | 145 | if (!empty($newRedirect)) { |
146 | - $redirect = $newRedirect; |
|
146 | + $redirect = $newRedirect; |
|
147 | + } |
|
147 | 148 | } |
148 | - } |
|
149 | - unset($_SESSION['cart']['cart_id']); |
|
150 | - call_user_func_array(['Tools', 'redirect'], $redirect); |
|
149 | + unset($_SESSION['cart']['cart_id']); |
|
150 | + call_user_func_array(['Tools', 'redirect'], $redirect); |
|
151 | + } |
|
151 | 152 | } |
152 | - } |
|
153 | 153 | } |
154 | 154 | $this->view->setTitle('Корзина'); |
155 | 155 | $bread = []; |
@@ -162,12 +162,12 @@ discard block |
||
162 | 162 | 'href' => '/ecommerce/cart' |
163 | 163 | ]; |
164 | 164 | $this->view->page(['data' => compact('cart', 'items', 'deliverys', 'payTypes', 'packItem', 'bread')]); |
165 | - } |
|
165 | + } |
|
166 | 166 | |
167 | - public function orderDetailAction($id = 0) { |
|
167 | + public function orderDetailAction($id = 0) { |
|
168 | 168 | $cart = Ecommerce\Cart::get((int) $id); |
169 | 169 | if ($cart->user_id != Users\User::$cur->id) { |
170 | - $this->url->redirect('/', 'Это не ваша корзина'); |
|
170 | + $this->url->redirect('/', 'Это не ваша корзина'); |
|
171 | 171 | } |
172 | 172 | $bread[] = [ |
173 | 173 | 'text' => 'Каталог', |
@@ -183,54 +183,54 @@ discard block |
||
183 | 183 | ]; |
184 | 184 | $this->view->setTitle('Заказ №' . $cart->id); |
185 | 185 | $this->view->page(['data' => compact('cart', 'bread')]); |
186 | - } |
|
186 | + } |
|
187 | 187 | |
188 | - public function continueAction($id = 0) { |
|
188 | + public function continueAction($id = 0) { |
|
189 | 189 | $cart = \Ecommerce\Cart::get((int) $id); |
190 | 190 | if ($cart->user_id != Users\User::$cur->id) { |
191 | - Tools::redirect('/', 'Это не ваша корзина'); |
|
191 | + Tools::redirect('/', 'Это не ваша корзина'); |
|
192 | 192 | } |
193 | 193 | if ($cart->cart_status_id > 1) { |
194 | - Tools::redirect('/', 'Корзина уже оформлена'); |
|
194 | + Tools::redirect('/', 'Корзина уже оформлена'); |
|
195 | 195 | } |
196 | 196 | $_SESSION['cart']['cart_id'] = $cart->id; |
197 | 197 | Tools::redirect('/ecommerce/cart'); |
198 | - } |
|
198 | + } |
|
199 | 199 | |
200 | - public function deleteAction($id = 0) { |
|
200 | + public function deleteAction($id = 0) { |
|
201 | 201 | $cart = \Ecommerce\Cart::get((int) $id); |
202 | 202 | if ($cart->user_id != Users\User::$cur->id) { |
203 | - Tools::redirect('/', 'Это не ваша корзина'); |
|
203 | + Tools::redirect('/', 'Это не ваша корзина'); |
|
204 | 204 | } |
205 | 205 | if ($cart->cart_status_id > 1) { |
206 | - Tools::redirect('/', 'Корзина уже оформлена'); |
|
206 | + Tools::redirect('/', 'Корзина уже оформлена'); |
|
207 | 207 | } |
208 | 208 | if (!empty($_SESSION['cart']['cart_id']) && $_SESSION['cart']['cart_id'] == $cart->id) { |
209 | - unset($_SESSION['cart']['cart_id']); |
|
209 | + unset($_SESSION['cart']['cart_id']); |
|
210 | 210 | } |
211 | 211 | $cart->delete(); |
212 | 212 | Tools::redirect('/users/cabinet/ecommerceOrdersHistory', 'Корзина была удалена', 'success'); |
213 | - } |
|
213 | + } |
|
214 | 214 | |
215 | - public function refillAction($id = 0) { |
|
215 | + public function refillAction($id = 0) { |
|
216 | 216 | $cart = \Ecommerce\Cart::get((int) $id); |
217 | 217 | if ($cart->user_id != Users\User::$cur->id) { |
218 | - Tools::redirect('/', 'Это не ваша корзина'); |
|
218 | + Tools::redirect('/', 'Это не ваша корзина'); |
|
219 | 219 | } |
220 | 220 | if (!empty($_SESSION['cart']['cart_id'])) { |
221 | - unset($_SESSION['cart']['cart_id']); |
|
221 | + unset($_SESSION['cart']['cart_id']); |
|
222 | 222 | } |
223 | 223 | $newCart = $this->ecommerce->getCurCart(); |
224 | 224 | foreach ($cart->cartItems as $cartitem) { |
225 | - $newCart->addItem($cartitem->item_offer_price_id, $cartitem->count); |
|
225 | + $newCart->addItem($cartitem->item_offer_price_id, $cartitem->count); |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | $newCart->save(); |
229 | 229 | |
230 | 230 | Tools::redirect('/ecommerce/cart/'); |
231 | - } |
|
231 | + } |
|
232 | 232 | |
233 | - public function successAction() { |
|
233 | + public function successAction() { |
|
234 | 234 | $bread = []; |
235 | 235 | $bread[] = [ |
236 | 236 | 'text' => 'Каталог', |
@@ -246,70 +246,70 @@ discard block |
||
246 | 246 | ]; |
247 | 247 | $this->view->setTitle('Заказ принят'); |
248 | 248 | $this->view->page(['data' => compact('bread')]); |
249 | - } |
|
249 | + } |
|
250 | 250 | |
251 | - public function addAction() { |
|
251 | + public function addAction() { |
|
252 | 252 | $result = new Server\Result(); |
253 | 253 | if (empty($_GET['itemOfferPriceId'])) { |
254 | - $result->success = false; |
|
255 | - $result->content = 'Произошла непредвиденная ошибка при добавлении товара'; |
|
256 | - $result->send(); |
|
254 | + $result->success = false; |
|
255 | + $result->content = 'Произошла непредвиденная ошибка при добавлении товара'; |
|
256 | + $result->send(); |
|
257 | 257 | } |
258 | 258 | $price = \Ecommerce\Item\Offer\Price::get((int) $_GET['itemOfferPriceId']); |
259 | 259 | if (!$price) { |
260 | - $result->success = false; |
|
261 | - $result->content = 'Такой цены не найдено'; |
|
262 | - $result->send(); |
|
260 | + $result->success = false; |
|
261 | + $result->content = 'Такой цены не найдено'; |
|
262 | + $result->send(); |
|
263 | 263 | } |
264 | 264 | $item = $price->offer->item; |
265 | 265 | |
266 | 266 | if (!$item) { |
267 | - $result->success = false; |
|
268 | - $result->content = 'Такого товара не существует'; |
|
269 | - $result->send(); |
|
267 | + $result->success = false; |
|
268 | + $result->content = 'Такого товара не существует'; |
|
269 | + $result->send(); |
|
270 | 270 | } |
271 | 271 | |
272 | 272 | $item->sales ++; |
273 | 273 | $item->save(); |
274 | 274 | |
275 | 275 | if (empty($_GET['count'])) |
276 | - $count = 1; |
|
276 | + $count = 1; |
|
277 | 277 | else |
278 | - $count = (float) $_GET['count']; |
|
278 | + $count = (float) $_GET['count']; |
|
279 | 279 | |
280 | 280 | $cart = $this->ecommerce->getCurCart(); |
281 | 281 | $stages = Ecommerce\Cart\Stage::getList(); |
282 | 282 | if (empty($this->module->config['sell_over_warehouse']) && $price->offer->warehouseCount() < $count) { |
283 | - $result->success = false; |
|
284 | - $result->content = 'На складе недостаточно товара! Доступно: ' . $price->offer->warehouseCount(); |
|
285 | - $result->send(); |
|
283 | + $result->success = false; |
|
284 | + $result->content = 'На складе недостаточно товара! Доступно: ' . $price->offer->warehouseCount(); |
|
285 | + $result->send(); |
|
286 | 286 | } |
287 | 287 | |
288 | 288 | $isset = false; |
289 | 289 | foreach ($cart->cartItems as $cartItem) { |
290 | - if ($cartItem->item_id == $item->id && $cartItem->item_offer_price_id == $price->id) { |
|
290 | + if ($cartItem->item_id == $item->id && $cartItem->item_offer_price_id == $price->id) { |
|
291 | 291 | $cartItem->count += $count; |
292 | 292 | $cartItem->save(); |
293 | 293 | $isset = true; |
294 | 294 | break; |
295 | - } |
|
295 | + } |
|
296 | 296 | } |
297 | 297 | if (!$isset) { |
298 | - $cart->addItem($price->id, $count); |
|
298 | + $cart->addItem($price->id, $count); |
|
299 | 299 | } |
300 | 300 | $cart->date_last_activ = date('Y-m-d H:i:s'); |
301 | 301 | $cart->calc(); |
302 | 302 | $result->successMsg = '<a href="/ecommerce/view/' . $item->id . '">' . $item->name() . ($price->offer->name() ? ' (' . $price->offer->name() . ')' : '') . '</a> добавлен <a href="/ecommerce/cart">в корзину покупок</a>!'; |
303 | 303 | $result->send(); |
304 | - } |
|
304 | + } |
|
305 | 305 | |
306 | - public function getcartAction() { |
|
306 | + public function getcartAction() { |
|
307 | 307 | $result = new Server\Result(); |
308 | 308 | ob_start(); |
309 | 309 | $this->view->widget('Ecommerce\cart'); |
310 | 310 | $result->content = ob_get_contents(); |
311 | 311 | ob_end_clean(); |
312 | 312 | $result->send(); |
313 | - } |
|
313 | + } |
|
314 | 314 | |
315 | 315 | } |