1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Ecommerce admin controller |
5
|
|
|
* |
6
|
|
|
* @author Alexey Krupskiy <[email protected]> |
7
|
|
|
* @link http://inji.ru/ |
8
|
|
|
* @copyright 2015 Alexey Krupskiy |
9
|
|
|
* @license https://github.com/injitools/cms-Inji/blob/master/LICENSE |
10
|
|
|
*/ |
11
|
|
|
class EcommerceController extends adminController |
12
|
|
|
{ |
13
|
|
|
public function dashboardAction() |
14
|
|
|
{ |
15
|
|
|
$this->view->setTitle('Онлайн магазин'); |
16
|
|
|
$this->view->page(); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function configureAction() |
|
|
|
|
20
|
|
|
{ |
21
|
|
|
if (!empty($_POST['config'])) { |
22
|
|
|
$config = App::$cur->ecommerce->config; |
23
|
|
|
$config['view_empty_warehouse'] = empty($_POST['config']['view_empty_warehouse']) ? false : true; |
24
|
|
|
$config['view_empty_image'] = empty($_POST['config']['view_empty_image']) ? false : true; |
25
|
|
|
$config['sell_empty_warehouse'] = empty($_POST['config']['sell_empty_warehouse']) ? false : true; |
26
|
|
|
$config['sell_over_warehouse'] = empty($_POST['config']['sell_over_warehouse']) ? false : true; |
27
|
|
|
$config['notify_mail'] = $_POST['config']['notify_mail']; |
28
|
|
|
$config['defaultCategoryView'] = $_POST['config']['defaultCategoryView']; |
29
|
|
|
$config['defaultCurrency'] = $_POST['config']['defaultCurrency']; |
30
|
|
|
$config['orderPrefix'] = $_POST['config']['orderPrefix']; |
31
|
|
|
$config['show_zero_price'] = empty($_POST['config']['show_zero_price']) ? false : true; |
32
|
|
|
$config['show_without_price'] = empty($_POST['config']['show_without_price']) ? false : true; |
33
|
|
|
Config::save('module', $config, 'Ecommerce'); |
34
|
|
|
Tools::redirect('/admin/ecommerce/configure', 'Настройки были изменены', 'success'); |
35
|
|
|
} |
36
|
|
|
$managers = [ |
37
|
|
|
'Ecommerce\Delivery', |
38
|
|
|
'Ecommerce\PayType', |
39
|
|
|
'Ecommerce\Warehouse', |
40
|
|
|
'Ecommerce\Unit', |
41
|
|
|
'Ecommerce\Card', |
42
|
|
|
'Ecommerce\Discount', |
43
|
|
|
'Ecommerce\Cart\Stage', |
44
|
|
|
'Ecommerce\Item\Type', |
45
|
|
|
'Ecommerce\Item\Option', |
46
|
|
|
'Ecommerce\Item\Offer\Option', |
47
|
|
|
'Ecommerce\Item\Offer\Price\Type', |
48
|
|
|
'Ecommerce\UserAdds\Field', |
49
|
|
|
'Ecommerce\Cart\Status', |
50
|
|
|
'Ecommerce\Delivery\Field', |
51
|
|
|
]; |
52
|
|
|
$this->view->setTitle('Настройки магазина'); |
53
|
|
|
$this->view->page(['data' => compact('managers')]); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function reBlockIndexAction() |
57
|
|
|
{ |
58
|
|
|
set_time_limit(0); |
59
|
|
|
$carts = Cart::getList(); |
60
|
|
|
foreach ($carts as $cart) { |
61
|
|
|
$cart->save(); |
62
|
|
|
} |
63
|
|
|
Tools::redirect('/admin/ecommerce/configure', 'Данные о блокировках обновлены'); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function reSearchIndexAction($i = 0) |
67
|
|
|
{ |
68
|
|
|
set_time_limit(0); |
69
|
|
|
$count = 100; |
70
|
|
|
$items = Ecommerce\Item::getList(['start' => $i * $count, 'limit' => $count]); |
71
|
|
|
if (!$items) { |
72
|
|
|
Tools::redirect('/admin/ecommerce/configure', 'Поисковый индекс обновлен'); |
73
|
|
|
} else { |
74
|
|
|
$i++; |
75
|
|
|
foreach ($items as $key => $item) { |
76
|
|
|
$item->save(); |
77
|
|
|
unset($items[$key]); |
78
|
|
|
unset($item); |
79
|
|
|
} |
80
|
|
|
echo 'Происходит процесс индексации: проиндексировано ' . $i * $count; |
81
|
|
|
Tools::redirect('/admin/ecommerce/reSearchIndex/' . $i); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function newOrdersSubscribeAction() |
86
|
|
|
{ |
87
|
|
|
$this->Notifications->subscribe('Ecommerce-orders'); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function closeCartAction($cartId = 0) |
91
|
|
|
{ |
92
|
|
|
$cart = Ecommerce\Cart::get((int) $cartId); |
93
|
|
|
$result = new Server\Result(); |
94
|
|
|
if ($cart && $cart->cart_status_id != 5) { |
95
|
|
|
$cart->cart_status_id = 5; |
96
|
|
|
$cart->save(); |
97
|
|
|
$result->successMsg = 'Заказ был завершен'; |
98
|
|
|
$result->send(); |
99
|
|
|
} |
100
|
|
|
$result->success = false; |
101
|
|
|
$result->content = 'Такая корзина не найдена'; |
102
|
|
|
$result->send(); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
} |
106
|
|
|
|
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: