dce46e80
Alex Savenko
first push project
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
<?php
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
namespace controllers;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
use Phalcon\Mvc\Dispatcher;
class MenuController extends \controllers\ControllerBase
{
public function orderAction()
{
if($this->session->get('special_users_id') != null) {
return $this->response->redirect('dealer/cart');
}
|
6a2e27db
Alex Savenko
price display basket
|
20
21
22
23
|
$lang_url = $this->seoUrl->getChangeLangUrl();
$in_cart = $this->session->get('in_cart', []);
$customer_id = $this->session->get('id');
$customer_email = $this->session->get('customer_email');
|
dce46e80
Alex Savenko
first push project
|
24
|
$session_promo_code = $this->session->get('promo_code');
|
6a2e27db
Alex Savenko
price display basket
|
25
|
$customer = !empty( $customer_id ) ? $this->models->getCustomers()->getCustomer( $customer_id ) : [];
|
dce46e80
Alex Savenko
first push project
|
26
|
|
6a2e27db
Alex Savenko
price display basket
|
27
|
$this->session->set( 'return_url', 'basket' ); // для redirect после авторизации на соц сетях
|
dce46e80
Alex Savenko
first push project
|
28
|
|
6a2e27db
Alex Savenko
price display basket
|
29
30
31
32
|
$items = [];
$total_price = 0;
$err = 0;
$cities_ = $this->novaposhta->city();
|
dce46e80
Alex Savenko
first push project
|
33
34
35
|
foreach( $cities_->item as $c )
{
|
dce46e80
Alex Savenko
first push project
|
36
37
38
|
$cities[strval($c->CityID)] = strval($c->Description);
}
|
3c014fd3
Alex Savenko
delete from DB af...
|
39
|
// применение скидок, промокода
|
dce46e80
Alex Savenko
first push project
|
40
41
42
43
|
if ( !empty( $in_cart ) )
{
$cart = $this->common->getCartItems($in_cart, $this->lang_id);
|
6a2e27db
Alex Savenko
price display basket
|
44
|
//promocode
|
dce46e80
Alex Savenko
first push project
|
45
46
47
48
49
50
|
if(!empty($session_promo_code)) {
if($this->common->applyPromoCode($session_promo_code, $cart['items'])) {
$this->common->countOrderSum($cart);
$cart['total_price'] = $cart['total_sum'];
}
}
|
dce46e80
Alex Savenko
first push project
|
51
|
|
6a2e27db
Alex Savenko
price display basket
|
52
53
54
55
|
//discount
$discount = $this->getDi()->get('models')->getDiscount()->getActiveData();
if (!empty($discount)) {
$discount = $discount[0];
|
6a2e27db
Alex Savenko
price display basket
|
56
57
58
59
60
61
62
63
64
|
}
if ($this->common->applyPromoCode($discount, $cart['items'])) {
$this->common->countOrderSum($cart);
$cart['total_price'] = $cart['total_sum'];
}
$total_price = $cart['total_price'];
$items = $cart['items'];
$items_ = $cart['items_'];
|
dce46e80
Alex Savenko
first push project
|
65
66
|
}
|
3c014fd3
Alex Savenko
delete from DB af...
|
67
|
//оформление заказа
|
dce46e80
Alex Savenko
first push project
|
68
69
70
71
|
if ( $this->request->isPost() )
{
$order['email'] = $this->request->getPost('login_email', 'string', NULL );
$order['passwd'] = $this->request->getPost('login_passwd', 'string', NULL );
|
dce46e80
Alex Savenko
first push project
|
72
73
74
75
76
77
78
79
80
81
82
83
|
$promo_code = $this->request->getPost('promo_code', 'string', NULL );
if(empty($session_promo_code)) {
$promo_code = $this->models->getPromoCodes()->getOneDataByCode($promo_code);
} else {
$promo_code = [$session_promo_code];
}
$order['promo_code'] = !empty($promo_code) ? $promo_code[0]['code'] : null;
$order_items = $this->request->getPost('count_items', NULL, [] );
$order_color = $this->request->getPost('color', NULL, [] );
|
6a2e27db
Alex Savenko
price display basket
|
84
85
|
$order_size = $this->request->getPost('size', NULL, [] );
$order_is = $this->request->getPost('is', NULL, [] );
|
dce46e80
Alex Savenko
first push project
|
86
87
88
89
90
91
92
93
|
$order['total_sum'] = 0;
foreach( $order_items as $key => $val )
{
$items_[$key]['count'] = $val;
$items_[$key]['total_price'] = round($val*$items_[$key]['price2'], 1);
if(isset($order_color[$key]))
|
6a2e27db
Alex Savenko
price display basket
|
94
|
$items_[$key]['color'] = $order_color[$key];
|
dce46e80
Alex Savenko
first push project
|
95
|
|
6a2e27db
Alex Savenko
price display basket
|
96
97
|
$items_[$key]['size'] = $order_size[$key];
$items_[$key]['is'] = $order_is[$key];
|
dce46e80
Alex Savenko
first push project
|
98
99
|
$order['items'][] = $items_[$key];
$order['total_sum'] += $items_[$key]['total_price'];
|
dce46e80
Alex Savenko
first push project
|
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
$item_id_in_cart = $this->common->array_column( $in_cart, 'item_id' );
if( in_array( $key, $item_id_in_cart ) )
{
foreach( $in_cart as &$c )
{
if( $c['item_id'] == $key )
{
$c['count_items'] = $val;
}
}
}
}
|
6a2e27db
Alex Savenko
price display basket
|
114
|
$order['total_sum'] = round( $order['total_sum'], 1 );
|
dce46e80
Alex Savenko
first push project
|
115
116
|
$this->session->set( 'in_cart', $in_cart );
|
6a2e27db
Alex Savenko
price display basket
|
117
|
|
dce46e80
Alex Savenko
first push project
|
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
if ( !empty( $order['email'] ) && !empty( $order['passwd'] ) )
{
$order['passwd'] = $this->common->hashPasswd( $order['passwd'] );
switch( $this->models->getCustomers()->customerLogin( $order ) )
{
case 1:
// OK
// redirect
$this->session->set( 'customer_email', NULL );
$this->session->remove('customer_email');
return $this->response->redirect([ 'for' => 'basket', 'language' => $this->lang_name ]);
case -1:
$this->flash->error($this->languages->getTranslation()->_("incorrect_login_or_password"));
$this->session->set( 'customer_email', $order['email'] );
return $this->response->redirect([ 'for' => 'basket', 'language' => $this->lang_name ]);
case 2: // user with status 0
default:
$this->flash->success($this->languages->getTranslation()->_("please_change_the_password"));
$this->session->set( 'customer_email', $order['email'] );
return $this->response->redirect([ 'for' => 'finish_registration', 'language' => $this->lang_name ]);
|
dce46e80
Alex Savenko
first push project
|
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
}
}
unset($order['email']);
unset($order['passwd']);
$order['name'] = $this->request->getPost('order_name', 'string', NULL );
$order['phone'] = $this->request->getPost('order_phone', 'string', NULL );
$order['delivery'] = $this->request->getPost('order_delivery', 'string', NULL );
$order['pay'] = $this->request->getPost('order_pay', 'string', NULL );
foreach ($order['items'] as $key => $o)
{
if (empty($o))
{
$err = 1;
}
$order['items'][$key]['cover'] = $this->storage->getPhotoURL($o['item_cover'], 'avatar', '400x');
$order['items'][$key]['alias'] = $o['catalog_alias'].'/'.$o['group_alias'].'-'.$o['id'];
}
// submit order
if( empty( $err ) )
{
$order['city'] =
( $order['delivery'] == 3 || $order['delivery'] == 4 )
?
$this->request->getPost('order_city_novaposhta', 'string', NULL )
:
$this->request->getPost('order_city', 'string', NULL );
$order['city_ref'] = $this->request->getPost('order_city_ref', 'string', NULL );
$order['store_address'] = $this->request->getPost('store_address', 'string', NULL );
$order['store_ref'] = $this->request->getPost('order_store_address_ref', 'string', NULL );
$address = $this->request->getPost('order_address', 'string', NULL );
$order['address'] = !empty( $address ) ? $address : $order['store_address'];
$order['email'] = $this->request->getPost('order_email', 'string', NULL );
$order['email'] = $order['email'] ? $order['email'] : NULL;
$order_get_info = $this->request->getPost('order_get_info', 'string', NULL );
$order['subscribed'] = empty( $order_get_info ) ? 0 : 1;
$order['comments'] = $this->request->getPost('order_comments', 'string', NULL );
$passwd_ = $this->common->generatePasswd(10);
$order['passwd_'] = $passwd_;
$order['passwd'] = $this->common->hashPasswd( $passwd_ );
|
0526f97a
Alex Savenko
price display basket
|
185
|
//promocode
|
6821735c
Alex Savenko
price display db+sms
|
186
187
188
189
|
if(!empty($promo_code)) {
if($this->common->applyPromoCode($promo_code[0], $order['items']))
$this->common->countOrderSum($order);
}
|
dce46e80
Alex Savenko
first push project
|
190
|
|
0526f97a
Alex Savenko
price display basket
|
191
192
193
194
195
196
197
198
199
|
//discount
$discount = $this->getDi()->get('models')->getDiscount()->getActiveData();
if (!empty($discount)) {
$discount = $discount[0];
}
if ($this->common->applyPromoCode($discount, $order['items'])) {
$this->common->countOrderSum($order);
}
|
6821735c
Alex Savenko
price display db+sms
|
200
201
202
203
204
205
206
207
208
|
// save order
$proposal_number = $this->models->getOrders()->addOrder($order);
$order['proposal_number'] = $proposal_number['proposal_number'];
$order['confirmed'] = $proposal_number['confirmed'];
$order['customer_new'] = $proposal_number['new'];
$sms_text = "Vash zakaz prinyat. #:".$proposal_number['proposal_number']." V blijayshee vremya menedjer svyajetsya s Vami (044) 581-67-15";
$this->sms->sendSMS($order['phone'], $sms_text);
|
3c014fd3
Alex Savenko
delete from DB af...
|
209
210
211
212
213
214
|
//чистим корзину в бд
if ($this->session->get('isAuth')) {
$user_id = $this->session->get('id');
$this->models->getBasket()->deleteBasket($user_id);
}
|
dce46e80
Alex Savenko
first push project
|
215
216
217
218
219
|
// novaposhta
if (!empty($proposal_number['novaposhta_tnn']))
{
$order['novaposhta_tnn'] = $proposal_number['novaposhta_tnn'];
}
|
dce46e80
Alex Savenko
first push project
|
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
|
if( !empty( $order['email'] ) )
{
$this->sendmail->addCustomer( 1, $order );
if( empty( $order['confirmed'] ) && !empty( $order['customer_new'] ) ) // new customer
{
$this->sendmail->addCustomer( 3, $order );
}
}
if( !empty( $order['proposal_number'] ) )
{
/**
* single use promo code logic
*/
if(!empty($session_promo_code)){
$user = $this->models->getCustomers()->getOneData($this->session->get('id'))['0'];
if($session_promo_code['single_use'] && !empty($user)){
if(!empty($user['email'])){
$data['code'] = $session_promo_code['code'];
$data['email'] = $user['email'];
$this->models->getPromoToUser()->addData($data);
}
}
}
$this->sendmail->addCustomer( 2, $order );
$this->session->set( 'in_cart', []);
$this->session->remove('promo_code');
$this->session->set( 'order_data', array(
'oid' => $order['proposal_number'],
'pay' => $order['pay'],
'amount' => $total_price,
'items'=>$items,
));
return $this->response->redirect([ 'for' => 'basket_completed', 'language' => $this->lang_name ]);
}
else
{
$this->flash->error( $this->languages->getTranslation()->_("error_send_message") );
return $this->response->redirect([ 'for' => 'basket', 'language' => $this->lang_name ]);
}
}
|
dce46e80
Alex Savenko
first push project
|
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
|
}
$static_page_alias = '/basket'. $this->lang_name;
$meta_title = 'Кошик | '.\config::get( 'global#title' );
$this->view->setVars([
'change_lang_url' => $lang_url,
'items' => $items,
'total_price' => $total_price,
'static_page_alias' => $static_page_alias,
'meta_title' => $meta_title,
'customer' => !empty($customer['0']) ? $customer['0'] : '' ,
'customer_email' => $customer_email,
'cities' => $cities,
'no_robots' => 1,
'promo_code' => $session_promo_code
]);
}
|
dce46e80
Alex Savenko
first push project
|
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
|
public function orderCompletedAction() {
$completed = $this->languages->getTranslation()->_("successfully_realized_order");
// order data
if ($data = $this->session->get('order_data'))
{
// type / liqpay
if ($data['pay'] == 2)
{
$completed = '';
$result = $this->liqpay->api("payment/status", array('order_id' => $data['oid']));
if (!empty($result->status) && $result->status == 'success')
{
setcookie("order", '1', time()+3600);
$this->session->remove('order_data');
return $this->response->redirect([ 'for' => 'homepage' , 'language' => $this->lang_name ]);
}
else
{
$liqpay = $this->liqpay->cnb_form(array(
'amount' => $data['amount'],
'currency' => 'UAH',
'description' => 'Оплата заказа №' . $data['oid'] . ' | ' . \config::get( 'global#domains/www' ),
'order_id' => $data['oid'],
'return_url' => 'http://semena.dev.artwebua.com.ua/basket/completed',
'language' => 'ru',
'type' => 'buy'
));
}
}
}
else
{
$this->dispatcher->forward([
'controller' => 'page',
'action' => 'error404'
]);
}
// vars
$this->lang_id = 1;
$static_page_alias = '/basket/completed';
$meta_title = 'Кошик | '.\config::get( 'global#title' );
// output
$this->view->setVars([
'data'=>$data,
'static_page_alias' => $static_page_alias,
'completed' => sprintf($completed,$data['oid']),
'liqpay' => !empty($liqpay) ? $liqpay : '' ,
'meta_title' => $meta_title,
'no_robots' => 1
]);
}
|
dce46e80
Alex Savenko
first push project
|
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
|
public function getCitiesAction( )
{
header('Content-Type: application/json; charset=utf8');
$term = $this->request->getPost('term', 'string', '' );
$length = strlen($term);
$cities_ = $this->novaposhta->city();
foreach( $cities_->item as $c )
{
$cities[strval($c->CityID)] = strval($c->Description);
if( mb_strtolower( substr( strval($c->Description), 0, $length ), 'utf-8' ) == mb_strtolower( $term, 'utf-8' ) )
{
$selected_cities[] =
[
'label' => strval($c->Description),
'value' => strval($c->Ref),
'id' => strval($c->CityID),
'ref' => strval($c->Ref)
];
}
}
die( json_encode( $selected_cities ) );
}
|
dce46e80
Alex Savenko
first push project
|
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
|
public function getOfficesAction( )
{
header('Content-Type: application/json; charset=utf8');
$city = $this->request->getPost('city', 'string', '' );
$offices_ = $this->novaposhta->warenhouse( $city );
foreach( $offices_->item as $c )
{
$offices[] =
[
'number' => strval($c->Number),
'address' => strval($c->Description),
'store_ref' => strval($c->Ref)
];
}
die( json_encode( $offices ) );
}
|
dce46e80
Alex Savenko
first push project
|
396
397
398
399
400
401
402
403
404
405
406
407
408
|
public function addProductBasketAction(){
$item_id = $_GET['productID'];
$count_items = $_GET['productCount'];
$in_cart[] =
[
'item_id' => $item_id,
'count_items' => $count_items
];
$this->session->set( 'in_cart', $in_cart );
return $this->response->redirect([ 'for' => 'basket']);
}
public function getCartItemsAction() {
|
882a91f6
Alex Savenko
price display basket
|
409
|
|
dce46e80
Alex Savenko
first push project
|
410
411
412
413
|
$this->view->disable();
$in_cart = $this->session->get('in_cart', []);
|
dce46e80
Alex Savenko
first push project
|
414
415
|
$cart_items = $this->common->getCartItems($in_cart, $this->lang_id);
|
dce46e80
Alex Savenko
first push project
|
416
417
418
419
420
|
if($this->session->get('special_users_id') != null) {
$special_users_id = $this->session->get('special_users_id');
$special_user = $this->models->getSpecialUsers()->getOneData($special_users_id)[0];
}
|
d95a040a
Alex Savenko
vip prices tests
|
421
422
423
|
//vip
$users_group_id = $this->session->get('users_group_id');
if (isset($users_group_id) && $users_group_id == 37) {
|
dd724469
Alex Savenko
vip prices tests
|
424
|
if ($this->common->applyDiscount(5, $cart_items['items'])) {
|
d95a040a
Alex Savenko
vip prices tests
|
425
426
427
428
429
|
$this->common->countOrderSum($cart_items);
$cart_items['total_price'] = $cart_items['total_sum'];
}
}
|
882a91f6
Alex Savenko
price display basket
|
430
|
//discount
|
746d54c8
Alex Savenko
price display basket
|
431
|
|
bfab52c2
Alex Savenko
price display basket
|
432
433
434
435
436
437
438
439
|
$discount = $this->models->getDiscount()->getActiveData();
if (!empty($discount)) {
$discount = $discount[0];
}
if ($this->common->applyPromoCode($discount, $cart_items['items'])) {
$this->common->countOrderSum($cart_items);
$cart_items['total_price'] = $cart_items['total_sum'];
}
|
dce46e80
Alex Savenko
first push project
|
440
|
|
746d54c8
Alex Savenko
price display basket
|
441
|
/************************/
|
ed35b843
Alex Savenko
price display
|
442
|
|
746d54c8
Alex Savenko
price display basket
|
443
|
foreach($cart_items['items'] as $k => $item) {
|
9ef66198
Alex Savenko
price display
|
444
|
|
dce46e80
Alex Savenko
first push project
|
445
446
447
448
449
450
451
452
453
454
455
|
$cart_items['items'][$k]['group_sizes'] = $this->models->getItems()->getSizesByGroupId( $this->lang_id, $item['group_id'] );
$cart_items['items'][$k]['prices'] = $this->common->getPricesArray($item);
$cart_items['new_total_price'] = 0;
if(isset($special_user)) {
$cart_items['items'][$k]['price'] = number_format(
isset($cart_items['items'][$k]['prices'][$special_user['status']])
? $cart_items['items'][$k]['prices'][$special_user['status']]
: $item['price2'], 2, '.', ''
);
|
dce46e80
Alex Savenko
first push project
|
456
457
458
459
460
461
462
463
|
$cart_items['items'][$k]['total_price'] = $cart_items['items'][$k]['price'] * $item['count'];
$cart_items['new_total_price'] += $cart_items['items'][$k]['total_price'];
$cart_items['total_price'] = $cart_items['new_total_price'];
} else {
$cart_items['items'][$k]['price'] = $item['price2'];
|
746d54c8
Alex Savenko
price display basket
|
464
465
|
}
|
dce46e80
Alex Savenko
first push project
|
466
467
468
469
470
|
}
echo json_encode($cart_items);
}
|
dce46e80
Alex Savenko
first push project
|
471
472
473
474
475
476
477
478
479
480
481
482
483
484
|
public function addToBasketAction()
{
$count = 0;
if( $this->request->isAjax() && $this->request->isPost() )
{
$item_id = $this->request->getPost( 'item_id', 'int', '' );
$count_items = $this->request->getPost( 'count_items', 'int', '' );
$in_cart = $this->session->get('in_cart', []);
$item_id_in_cart = $this->common->array_column( $in_cart, 'item_id' );
if( in_array( $item_id, $item_id_in_cart ) )
{
|
21bd2cce
Alex Savenko
die fix
|
485
|
die( json_encode( 0 ) );
|
dce46e80
Alex Savenko
first push project
|
486
487
488
489
490
491
492
493
|
}
$in_cart[] =
[
'item_id' => $item_id,
'count_items' => $count_items
];
$this->session->set( 'in_cart', $in_cart );
|
c83df947
Alex Savenko
id => email
|
494
495
496
|
$count = count($in_cart);
|
f723ca00
Alex Savenko
test
|
497
|
//save basket in DB
|
f0646224
Alex Savenko
pushing data to m...
|
498
|
if ($this->session->get('isAuth')) {
|
c99e7b14
Alex Savenko
debugging
|
499
500
|
$user_id = $this->session->get('id');
$this->models->getBasket()->updateBasket($user_id, $in_cart, 0);
|
f0646224
Alex Savenko
pushing data to m...
|
501
|
}
|
f0646224
Alex Savenko
pushing data to m...
|
502
|
|
dce46e80
Alex Savenko
first push project
|
503
504
|
}
|
21bd2cce
Alex Savenko
die fix
|
505
|
die (json_encode($count));
|
6a6b3c4f
Alex Savenko
id => email
|
506
|
|
dce46e80
Alex Savenko
first push project
|
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
|
}
///////////////////////////////////////////////////////////////////////////
public function deleteFromBasketAction()
{
$count = 0;
if( $this->request->isAjax() && $this->request->isPost() )
{
$item_id = $this->request->getPost( 'item_id', 'int', '' );
$in_cart = $this->session->get('in_cart', []);
foreach( $in_cart as $key => $value )
{
if( $value['item_id'] == $item_id )
{
unset( $in_cart[$key] );
}
}
$this->session->set( 'in_cart', $in_cart );
$count = count($in_cart);
|
a487dfdd
Alex Savenko
update record usi...
|
531
|
//save basket in DB
|
a487dfdd
Alex Savenko
update record usi...
|
532
|
if ($this->session->get('isAuth')) {
|
c99e7b14
Alex Savenko
debugging
|
533
|
$user_id = $this->session->get('id');
|
8440206a
Alex Savenko
debugging
|
534
|
$this->models->getBasket()->updateBasket($user_id, $in_cart, 0);
|
a487dfdd
Alex Savenko
update record usi...
|
535
|
}
|
dce46e80
Alex Savenko
first push project
|
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
|
}
die( json_encode( $count ) );
}
///////////////////////////////////////////////////////////////////////////
public function changeCountBasketAction()
{
$count = 0;
if( $this->request->isAjax() && $this->request->isPost() )
{
$item_id = $this->request->getPost( 'item_id', 'int', '' );
$count_items = $this->request->getPost( 'count_items', 'int', '' );
$in_cart = $this->session->get('in_cart', []);
foreach( $in_cart as $k => $v )
{
if( $v['item_id'] == $item_id )
{
$in_cart[$k]['count_items'] = $count_items;
}
}
$this->session->set( 'in_cart', $in_cart );
|
c99e7b14
Alex Savenko
debugging
|
562
|
|
b504d880
Alex Savenko
update record usi...
|
563
|
//save basket in DB
|
b504d880
Alex Savenko
update record usi...
|
564
|
if ($this->session->get('isAuth')) {
|
c99e7b14
Alex Savenko
debugging
|
565
566
|
$user_id = $this->session->get('id');
$this->models->getBasket()->updateBasket($user_id, $in_cart, 0);
|
b504d880
Alex Savenko
update record usi...
|
567
|
}
|
dce46e80
Alex Savenko
first push project
|
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
|
}
die( json_encode( $in_cart ) );
}
///////////////////////////////////////////////////////////////////////////
public function staticPageAction( )
{
$params = $this->dispatcher->getParams();
$page_id = $params['page_id'];
$lang_url = $this->seoUrl->getChangeLangUrl();
$page = $this->models->getPages()->getPage( $page_id, $this->lang_id );
if( !empty( $page ) )
{
$meta_title = $page['0']['meta_title'];
$meta_keywords = $page['0']['meta_keywords'];
$meta_description = $page['0']['meta_description'];
$this->view->setVars([
'change_lang_url' => $lang_url,
'page' => $page['0'],
'meta_title' => $meta_title,
'meta_keywords' => $meta_keywords,
'meta_description' => $meta_description,
]);
}
else
{
$this->dispatcher->forward([
'controller' => 'page',
'action' => 'error404'
]);
}
}
///////////////////////////////////////////////////////////////////////////
public function newsAction()
{
$meta_title =
[
'1' => 'Новини та акції | Інтернет магазин насіння Semena.in.ua',
'2' => 'Новости и акции | Интернет магазин семян Semena.in.ua'
];
$meta_description =
[
'1' => 'Останні новини та актуальні акції інтернет магазину насіння Semena.in.ua',
'2' => 'Последние новости и актуальные акции интернет магазина семян Semena.in.ua'
];
$css = [
'https://fonts.googleapis.com/css?family=Ubuntu:400,700,400italic',
'/landing_sales/animation.css',
'/landing_sales/style.css'
];
$js = [
'/landing_sales/script.js'
];
$lang_url = $this->seoUrl->getChangeLangUrl();
$active_sales = $this->models->getSales()->getActiveSales($this->lang_id);
$future_sales = $this->models->getSales()->getFutureSales($this->lang_id);
$recent_sales = array_merge($active_sales, $future_sales);
foreach( $recent_sales as $k => $n )
{
$recent_sales[$k]['link'] = $this->url->get([ 'for' => 'one_news', 'news_id' => $n['id'], 'news_alias' => $n['alias'] ]);
}
$active_seasonal = $this->models->getSales()->getActiveSeasonalSales($this->lang_id);
$future_seasonal = $this->models->getSales()->getFutureSeasonalSales($this->lang_id);
$seasonal_sales = array_merge($active_seasonal, $future_seasonal);
foreach( $seasonal_sales as $k => $n )
{
$seasonal_sales[$k]['link'] = $this->url->get([ 'for' => 'one_news', 'news_id' => $n['id'], 'news_alias' => $n['alias'] ]);
}
$reviews = $this->models->getReviews()->getActiveReviews();
$this->view->setVars([
'css' => $css,
'js' => $js,
'change_lang_url' => $lang_url,
'meta_title' => $meta_title[$this->lang_id],
'meta_description' => $meta_description[$this->lang_id],
'classic_sales' => $recent_sales,
'seasonal_sales' => $seasonal_sales,
'reviews' => $reviews
]);
$this->view->pick('menu/sales');
/*
$lang_url = $this->seoUrl->getChangeLangUrl();
$params = $this->dispatcher->getParams();
$page = isset($params['page']) && !empty($params['page']) ? $params['page'] : 1;
$this->lang_id = $this->seoUrl->getLangId();
$news = $this->models->getNews()->getNews( $this->lang_id, $page );
foreach( $news as $k => $n )
{
$news[$k]['image'] = !empty( $n['cover'] ) ? $this->storage->getPhotoUrl( $n['cover'], 'news', '180x120' ) : '';
$news[$k]['link'] = $this->url->get([ 'for' => 'one_news', 'news_id' => $n['id'], 'news_alias' => $n['alias'] ]);
}
$total = $this->models->getNews()->getTotalNews( $this->lang_id );
if( $total['0']['count'] > \config::get( 'limits/news') )
{
$paginate = $this->common->paginate(
[
'page' => $page,
'items_per_page' => \config::get( 'limits/news', 5),
'total_items' => $total['0']['count'],
'url_for' => [ 'for' => 'news_paginate', 'page' => $page ],
'index_page' => 'news'
], true
);
}
$meta_link_next =
[
'1' =>isset($paginate['meta_link_next']) ? $paginate['meta_link_next'] : ''
];
$meta_link_prev =
[
'1' =>isset($paginate['meta_link_prev']) ? $paginate['meta_link_prev'] : ''
];
$this->view->setVars([
'change_lang_url' => $lang_url,
'news' => $news,
'page' => $page,
'total' => $total['0']['count'],
'page_title' => 'news',
'meta_title' => $meta_title[$this->lang_id],
'meta_description' => $meta_description[$this->lang_id],
'meta_link_next' => $meta_link_next[1],
'meta_link_prev' => $meta_link_prev[1],
'paginate' => !empty($paginate['output']) ? $paginate['output'] : '' ,
]);*/
}
public function oneNewsAction($news_alias, $news_id)
{
$meta_title =
[
'1' => 'Новини та акції | Інтернет магазин насіння Semena.in.ua',
'2' => 'Новости и акции | Интернет магазин семян Semena.in.ua'
];
$meta_description =
[
'1' => 'Останні новини та актуальні акції інтернет магазину насіння Semena.in.ua',
'2' => 'Последние новости и актуальные акции интернет магазина семян Semena.in.ua'
];
$css = [
'https://fonts.googleapis.com/css?family=Ubuntu:400,700,400italic',
'/landing_sales/style.css',
'/landing_sales/flipclock.css'
];
$js = [
'/landing_sales/flipclock.min.js',
'/landing_sales/script.js'
];
$lang_url = $this->seoUrl->getChangeLangUrl();
$current_sale = $this->models->getSales()->getOneDataByLang($news_id, $this->lang_id)[0];
$current_sale['link'] = $this->url->get([ 'for' => 'one_news', 'news_id' => $current_sale['id'], 'news_alias' => $current_sale['alias'] ]);
$current_sale['group_ids'] = $this->common->parseArray($current_sale['group_ids']);
$sale_groups = $this->models->getItems()->getGroupsByGroups($this->lang_id, $current_sale['group_ids']);
$sale_groups = $this->common->explodeAlias($sale_groups);
$sale_groups_ = $this->common->getGroups1( $this->lang_id, $sale_groups );
$now = time();
$current_year = date('Y');
$current_month = date('m');
$current_day = date('d');
$left_date = $current_sale['active']
? (new \DateTime($current_sale['end_date']))->add(new \DateInterval('P1D'))
: new \DateTime($current_sale['start_date']);
$d = $left_date->format('d');
$m = $left_date->format('m');
if($current_month > $m || ($current_month == $m && $current_day > $d))
$current_year++;
$left_date->setDate($current_year , $m , $d);
$timestamp_left = $left_date->getTimestamp();
$seconds_left = $timestamp_left - $now;
$active_sales = $this->models->getSales()->getActiveSalesExceptCurrent($this->lang_id, $current_sale['id']);
$future_sales = $this->models->getSales()->getFutureSalesExceptCurrent($this->lang_id, $current_sale['id']);
$recent_sales = array_merge($active_sales, $future_sales);
foreach( $recent_sales as $k => $n )
{
$recent_sales[$k]['link'] = $this->url->get([ 'for' => 'one_news', 'news_id' => $n['id'], 'news_alias' => $n['alias'] ]);
}
$this->view->setVars([
'css' => $css,
'js' => $js,
'change_lang_url' => $lang_url,
'meta_title' => $meta_title[$this->lang_id],
'meta_description' => $meta_description[$this->lang_id],
'classic_sales' => $recent_sales,
'current_sale' => $current_sale,
'time_left' => $seconds_left,
'groups' => $sale_groups_
]);
$this->view->pick('menu/oneSale');
/*$this->lang_id = $this->seoUrl->getLangId();
$params = $this->dispatcher->getParams();
$news_id = $params['news_id'];
$one_news = $this->models->getNews()->getOneNews( $this->lang_id, $news_id );
if( !empty( $one_news ) )
{
$one_news['0']['link'] = $this->url->get([ 'for' => 'one_news', 'news_id' => $one_news['0']['id'], 'news_alias' => $one_news['0']['alias'] ]);
$one_news['0']['image'] = $this->storage->getPhotoUrl( $one_news['0']['cover'], 'news', '400x265' );
$news2groups_ids_ = $this->etc->int2arr($one_news['0']['group_id']);
$news2groups = [];
$pages_news2groups = '';
if( !empty( $news2groups_ids_ ) )
{
$news2groups_ids = array_chunk( $news2groups_ids_, \config::get( 'limits/groups2news' ) );
$news2groups_ = $this->models->getItems()->getNews2Groups( $this->lang_id, $news2groups_ids['0'] );
$news2groups = $this->common->getGroups( $this->lang_id, $news2groups_ );
$total_groups = count($news2groups_ids_);
$pages_news2groups =
$total_groups%\config::get( 'limits/groups2news' )==0
?
$total_groups/\config::get( 'limits/groups2news' )
:
floor( $total_groups/\config::get( 'limits/groups2news' ) )+1;
}
if( !empty( $one_news['0']['photogallery'] ) )
{
$one_news['0']['photos'] = $this->etc->int2arr($one_news['0']['photogallery']);
}
$meta_title =
[
'1' => $one_news['0']['title'].' | Інтернет магазин насіння Semena.in.ua',
'2' => $one_news['0']['title'].' | Интернет магазин семян Semena.in.ua '
];
$meta_description =
[
'1' => $one_news['0']['title'].' Актуально на Semena.in.ua.',
'2' => $one_news['0']['title'].' Актуально на Semena.in.ua. '
];
$this->view->setVars([
'one_news' => $one_news['0'],
'meta_title' => $meta_title[$this->lang_id],
'meta_description' => $meta_description[$this->lang_id],
'news2groups' => $news2groups,
'pages_news2groups' => $pages_news2groups,
]);
}
else
{
$this->dispatcher->forward([
'controller' => 'page',
'action' => 'error404'
]);
}*/
}
public function oneNewsItemsAction($news_alias, $news_id)
{
$meta_title =
[
'1' => 'Новини та акції | Інтернет магазин насіння Semena.in.ua',
'2' => 'Новости и акции | Интернет магазин семян Semena.in.ua'
];
$meta_description =
[
'1' => 'Останні новини та актуальні акції інтернет магазину насіння Semena.in.ua',
'2' => 'Последние новости и актуальные акции интернет магазина семян Semena.in.ua'
];
$lang_url = $this->seoUrl->getChangeLangUrl();
$current_sale = $this->models->getSales()->getOneDataByLang($news_id, $this->lang_id)[0];
$current_sale['link'] = $this->url->get([ 'for' => 'one_news', 'news_id' => $current_sale['id'], 'news_alias' => $current_sale['alias'] ]);
$current_sale['group_ids'] = $this->common->parseArray($current_sale['group_ids']);
$sale_groups = $this->models->getItems()->getGroupsByGroups($this->lang_id, $current_sale['group_ids']);
$sale_groups = $this->common->explodeAlias($sale_groups);
$sale_groups_ = $this->common->getGroups1( $this->lang_id, $sale_groups );
$this->view->setVars([
'change_lang_url' => $lang_url,
'meta_title' => $meta_title[$this->lang_id],
'meta_description' => $meta_description[$this->lang_id],
'current_sale' => $current_sale,
'items' => $sale_groups_
]);
$this->view->pick('menu/oneSaleItems');
}
public function videoAction( )
{
$lang_url = $this->seoUrl->getChangeLangUrl();
$params = $this->dispatcher->getParams();
$page = isset($params['page']) && !empty($params['page']) ? $params['page'] : 1;
$rub = isset($params['rub']) && !empty($params['rub']) ? $params['rub'] : 0;
$this->lang_id = $this->seoUrl->getLangId();
$tips = $this->models->getNews()->getVideo( $this->lang_id, $page, $rub, \config::get( 'dealer_rubric' ) );
foreach( $tips as $k => $n )
{
$tips[$k]['image'] = !empty( $n['cover'] ) ? $this->storage->getPhotoUrl( $n['cover'], 'news', '180x120' ) : '';
$tips[$k]['link'] = $this->url->get([ 'for' => 'one_tips', 'tips_id' => $n['id'], 'tips_alias' => $n['alias'] ]);
}
$total = $this->models->getNews()->getTotalVideo( $this->lang_id, $rub );
$meta_title =
[
'1' => 'Відео | Інтернет магазин насіння Semena.in.ua',
'2' => 'Видео | Интернет магазин семян Semena.in.ua'
];
$meta_description =
[
'1' => 'Відео агрономів та фермерів на сайті Semena.in.ua.',
'2' => 'Видео агрономов и фермеров на сайте Semena.in.ua.'
];
if(empty($params['rub']))$params['rub'] = '';
$paginate = $this->common->paginate(
[
'page' => $page,
'items_per_page' => \config::get( 'limits/news', 5),
'total_items' => $total['0']['count'],
'url_for' => [ 'for' => 'video_paginate', 'page' => $page,'rub'=>$params['rub'] ],
'index_page' => 'video'
], true
);
$meta_link_next =
[
'1' =>isset($paginate['meta_link_next']) ? $paginate['meta_link_next'] : ''
];
$meta_link_prev =
[
'1' =>isset($paginate['meta_link_prev']) ? $paginate['meta_link_prev'] : ''
];
$this->view->setVars([
'change_lang_url' => $lang_url,
'rubrics' => $this->models->getRubricsNews()->getAllRubrics($this->lang_id),
'tips' => $tips,
'page' => $page,
'total' => $total['0']['count'],
'meta_title' => $meta_title[$this->lang_id],
'meta_description' => $meta_description[$this->lang_id],
'meta_link_next' => $meta_link_next[1],
'meta_link_prev' => $meta_link_prev[1],
'paginate' => !empty($paginate['output']) ? $paginate['output'] : '' ,
]);
}
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
public function profTipsAction( )
{
$lang_url = $this->seoUrl->getChangeLangUrl();
$params = $this->dispatcher->getParams();
$page = isset($params['page']) && !empty($params['page']) ? $params['page'] : 1;
$rub = isset($params['rub']) && !empty($params['rub']) ? $params['rub'] : 0;
$this->lang_id = $this->seoUrl->getLangId();
$tips = $this->models->getNews()->getTips( $this->lang_id, $page, $rub, \config::get( 'dealer_rubric' ) );
foreach( $tips as $k => $n )
{
$tips[$k]['image'] = !empty( $n['cover'] ) ? $this->storage->getPhotoUrl( $n['cover'], 'news', '180x120' ) : '';
$tips[$k]['link'] = $this->url->get([ 'for' => 'one_tips', 'tips_id' => $n['id'], 'tips_alias' => $n['alias'] ]);
}
$total = $this->models->getNews()->getTotalTips( $this->lang_id,$rub );
$meta_title =
[
'1' => 'Поради професіоналів | Інтернет магазин насіння Semena.in.ua',
'2' => 'Советы профессионалов | Интернет магазин семян Semena.in.ua'
];
$meta_description =
[
'1' => 'Поради професійних агрономів та фермерів на сайті Semena.in.ua.',
'2' => 'Советы профессиональных агрономов и фермеров на сайте Semena.in.ua.'
];
if(empty($params['rub']))$params['rub'] = '';
$paginate = $this->common->paginate(
[
'page' => $page,
'items_per_page' => \config::get( 'limits/news', 5),
'total_items' => $total['0']['count'],
'url_for' => [ 'for' => ((!empty($params['rub'])) ? 'prof_tips_rubric_paginate' : 'prof_tips_paginate'), 'page' => $page,'rub'=>$params['rub'] ],
'index_page' => 'prof_tips'
], true
);
$meta_link_next =
[
'1' =>isset($paginate['meta_link_next']) ? $paginate['meta_link_next'] : ''
];
$meta_link_prev =
[
'1' =>isset($paginate['meta_link_prev']) ? $paginate['meta_link_prev'] : ''
];
$this->view->setVars([
'change_lang_url' => $lang_url,
'rubrics' => $this->models->getRubricsNews()->getAllRubrics($this->lang_id),
'tips' => $tips,
'page' => $page,
'total' => $total['0']['count'],
'meta_title' => $meta_title[$this->lang_id],
'meta_description' => $meta_description[$this->lang_id],
'meta_link_next' => $meta_link_next[1],
'meta_link_prev' => $meta_link_prev[1],
'paginate' => !empty($paginate['output']) ? $paginate['output'] : '' ,
]);
}
public function oneTipsAction( $tips_alias, $tips_id )
{
$this->lang_id = $this->seoUrl->getLangId();
$params = $this->dispatcher->getParams();
$tips_id = $params['tips_id'];
$one_news = $this->models->getNews()->getOneNews( $this->lang_id, $tips_id, \config::get( 'dealer_rubric' ) );
if( !empty( $one_news ) )
{
$one_news['0']['link'] = $this->url->get([ 'for' => 'one_tips', 'tips_id' => $one_news['0']['id'], 'tips_alias' => $one_news['0']['alias'] ]);
$one_news['0']['image'] = $this->storage->getPhotoUrl( $one_news['0']['cover'], 'news', '400x265' );
$news2groups_ids_ = $this->etc->int2arr($one_news['0']['group_id']);
$news2groups = [];
$pages_news2groups = '';
if( !empty( $news2groups_ids_ ) )
{
$news2groups_ids = array_chunk( $news2groups_ids_, \config::get( 'limits/groups2news' ) );
$total_groups = count($news2groups_ids_);
$news2groups_ = $this->models->getItems()->getNews2Groups( $this->lang_id, $news2groups_ids['0'] );
$news2groups = $this->common->getGroups( $this->lang_id, $news2groups_ );
$pages_news2groups =
$total_groups%\config::get( 'limits/groups2news' )==0
?
$total_groups/\config::get( 'limits/groups2news' )
:
floor( $total_groups/\config::get( 'limits/groups2news' ) )+1;
}
if( !empty( $one_news['0']['photogallery'] ) )
{
$one_news['0']['photos'] = $this->etc->int2arr($one_news['0']['photogallery']);
}
$meta_title =
[
'1' => $one_news['0']['title'].' | Інтернет магазин насіння Semena.in.ua',
'2' => $one_news['0']['title'].' | Интернет магазин семян Semena.in.ua '
];
$meta_description =
[
'1' => $one_news['0']['title'].' Актуально на Semena.in.ua.',
'2' => $one_news['0']['title'].' Актуально на Semena.in.ua.'
];
$this->view->setVars([
'one_news' => $one_news['0'],
'meta_title' => $meta_title[$this->lang_id],
'meta_description' => $meta_description[$this->lang_id],
'news2groups' => $news2groups,
'pages_news2groups' => $pages_news2groups,
]);
}
else
{
$this->dispatcher->forward([
'controller' => 'page',
'action' => 'error404'
]);
}
}
///////////////////////////////////////////////////////////////////////////
public function partnersAction( )
{
$this->lang_id = $this->seoUrl->getLangId();
$partners = $this->models->getPartners()->getPartners( $this->lang_id );
foreach( $partners as $p )
{
$partners_[$p['shop_type']][] = $p;
}
$internet_shops = $partners_['1'];
foreach( $partners_['2'] as $p )
{
$dillers[$p['district']][] = $p;
}
$meta_title =
[
'1' => 'Партнери та дилери | Інтернет магазин насіння Semena.in.ua',
'2' => 'Партнеры и дилеры | Интернет магазин семян Semena.in.ua'
];
$meta_description =
[
'1' => 'Контактна інформація, телефони дилерів та партнерів нашого магазину',
'2' => 'Контактная информация, телефоны дилеров и партнеров нашего магазина'
];
$this->view->setVars([
'internet_shops' => $internet_shops,
'dillers' => $dillers,
'meta_title' => $meta_title[$this->lang_id],
'meta_description' => $meta_description[$this->lang_id],
'page_title' => 'partners'
]);
}
///////////////////////////////////////////////////////////////////////////
public function contactsAction()
{
$this->lang_id = $this->seoUrl->getLangId();
$shops = $this->models->getPartners()->getContactsShops( $this->lang_id );
$lang_url = $this->seoUrl->getChangeLangUrl();
$meta_title =
[
'1' => 'Контакти, адреса, телефон ТМ «Професійне насіння» | Інтернет магазин насіння Semena.in.ua',
'2' => 'Контакты, адрес, телефон ТМ «Профессиональное семян» | Интернет магазин семян Semena.in.ua'
];
$meta_description =
[
'1' => 'Контактна інформація, та як до нас доїхати.',
'2' => 'Контактная информация и как к нам доехать.'
];
$this->view->setVars([
'change_lang_url' => $lang_url,
'shops' => $shops,
'meta_title' => $meta_title[$this->lang_id],
'meta_description' => $meta_description[$this->lang_id],
'page_title' => 'partners'
]);
}
///////////////////////////////////////////////////////////////////////////
public function callbackAction( )
{
$this->lang_id = $this->seoUrl->getLangId();
$callback['id'] = $this->session->get('id');
$callback['id'] = !empty( $callback['id'] ) ? $callback['id'] : 0;
$customer = [];
if( !empty( $callback['id'] ) )
{
$customer = $this->models->getCustomers()->getCustomer($callback['id']);
}
if( $this->request->isPost() )
{
$callback['name'] = $this->request->getPost('name', 'string', NULL );
$email = $this->request->getPost('email', 'string', NULL );
$callback['comments'] = $this->request->getPost('comments', 'string', NULL );
$callback['email'] = filter_var( $email, FILTER_VALIDATE_EMAIL );
$callback['phone'] = empty( $callback['email'] ) ? $email : NULL;
$callback['email'] = !empty( $callback['email'] ) ? $callback['email'] : NULL;
if( !empty( $callback['name'] ) && !empty( $callback['comments'] ) && ( !empty( $callback['email'] ) || !empty( $callback['phone'] ) ) )
{
if( $callback_id = $this->models->getCallback()->addCallback($callback) )
{
$callback['callback_id'] = $callback_id['0']['id'];
if( !empty( $callback['email'] ) )
{
$this->sendmail->addCustomer( 8, $callback );
}
$this->sendmail->addCustomer( 7, $callback );
setcookie("callback", '1', time()+3600);
return $this->response->redirect([ 'for' => 'homepage', 'language' => $this->lang_name ]);
}
}
else
{
$this->session->set( 'callback', $callback );
$this->flash->error( $this->languages->getTranslation()->_("required_error"));
return $this->response->redirect([ 'for' => 'callback_errors', 'language' => $this->lang_name ]);
}
}
$this->view->disableLevel(\Phalcon\Mvc\View::LEVEL_MAIN_LAYOUT);
$this->view->setVars([
'customer' => $customer,
'no_robots' => 1
]);
}
///////////////////////////////////////////////////////////////////////////
public function callbackErrorsAction( )
{
$callback_session = $this->session->get( 'callback' );
$callback['id'] = $this->session->get('id');
$customer = [];
if( !empty( $callback['id'] ) )
{
$customer = $this->models->getCustomers()->getCustomer($callback['id']);
}
if( $this->request->isPost() )
{
$callback['name'] = $this->request->getPost('name', 'string', NULL );
$email = $this->request->getPost('email', 'string', NULL );
$callback['comments'] = $this->request->getPost('comments', 'string', NULL );
$callback['email'] = filter_var( $email, FILTER_VALIDATE_EMAIL );
$callback['phone'] = empty( $callback['email'] ) ? $email : NULL;
$callback['email'] = !empty( $callback['email'] ) ? $callback['email'] : NULL;
if( !empty( $callback['name'] ) && !empty( $callback['comments'] ) && ( !empty( $callback['email'] ) || !empty( $callback['phone'] ) ) )
{
if( $callback_id = $this->models->getCallback()->addCallback($callback) )
{
$callback['callback_id'] = $callback_id['0']['id'];
if( !empty( $callback['email'] ) )
{
$this->sendmail->addCustomer( 8, $callback );
}
$this->sendmail->addCustomer( 7, $callback );
setcookie("callback", '1', time()+3600);
return $this->response->redirect([ 'for' => 'homepage', 'language' => $this->lang_name ]);
}
}
}
$this->view->setVars([
'callback_session' => $callback_session,
'customer' => $customer,
'no_robots' => 1
]);
}
///////////////////////////////////////////////////////////////////////////
}
|