Test Failed
Push — master ( 61f61c...455e4b )
by Alexey
04:03
created

EcommerceController::dashboardAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
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
        $this->view->setTitle('Онлайн магазин');
15
        $this->view->page();
16
    }
17
18
    public function configureAction() {
19
        if (!empty($_POST['config'])) {
20
            $config = App::$cur->ecommerce->config;
21
            $config['view_empty_warehouse'] = empty($_POST['config']['view_empty_warehouse']) ? false : true;
22
            $config['view_empty_image'] = empty($_POST['config']['view_empty_image']) ? false : true;
23
            $config['sell_empty_warehouse'] = empty($_POST['config']['sell_empty_warehouse']) ? false : true;
24
            $config['sell_over_warehouse'] = empty($_POST['config']['sell_over_warehouse']) ? false : true;
25
            $config['notify_mail'] = $_POST['config']['notify_mail'];
26
            $config['defaultCategoryView'] = $_POST['config']['defaultCategoryView'];
27
            $config['defaultCurrency'] = $_POST['config']['defaultCurrency'];
28
            $config['orderPrefix'] = $_POST['config']['orderPrefix'];
29
            $config['show_zero_price'] = empty($_POST['config']['show_zero_price']) ? false : true;
30
            $config['show_without_price'] = empty($_POST['config']['show_without_price']) ? false : true;
31
            $config['filtersInLast'] = empty($_POST['config']['filtersInLast']) ? false : true;
32
            Config::save('module', $config, 'Ecommerce');
33
            Tools::redirect('/admin/ecommerce/configure', 'Настройки были изменены', 'success');
34
        }
35
        $managers = [
36
            'Ecommerce\Delivery',
37
            'Ecommerce\PayType',
38
            'Ecommerce\Warehouse',
39
            'Ecommerce\Unit',
40
            'Ecommerce\Card',
41
            'Ecommerce\Discount',
42
            'Ecommerce\Cart\Stage',
43
            'Ecommerce\Item\Type',
44
            'Ecommerce\Item\Option',
45
            'Ecommerce\Item\Offer\Option',
46
            'Ecommerce\Item\Offer\Price\Type',
47
            'Ecommerce\UserAdds\Field',
48
            'Ecommerce\Cart\Status',
49
            'Ecommerce\Delivery\Field',
50
        ];
51
        $this->view->setTitle('Настройки магазина');
52
        $this->view->page(['data' => compact('managers')]);
53
    }
54
55
    public function reBlockIndexAction() {
56
        set_time_limit(0);
57
        $carts = Cart::getList();
58
        foreach ($carts as $cart) {
59
            $cart->save();
60
        }
61
        Tools::redirect('/admin/ecommerce/configure', 'Данные о блокировках обновлены');
62
    }
63
64
    public function reSearchIndexAction($i = 0) {
65
        set_time_limit(0);
66
        $count = 100;
67
        $items = Ecommerce\Item::getList(['start' => $i * $count, 'limit' => $count]);
68
        if (!$items) {
69
            Tools::redirect('/admin/ecommerce/configure', 'Поисковый индекс обновлен');
70
        } else {
71
            $i++;
72
            foreach ($items as $key => $item) {
73
                $item->save();
74
                unset($items[$key]);
75
                unset($item);
76
            }
77
            echo 'Происходит процесс индексации: проиндексировано ' . $i * $count;
78
            Tools::redirect('/admin/ecommerce/reSearchIndex/' . $i);
79
        }
80
    }
81
82
    public function newOrdersSubscribeAction() {
83
        $this->Notifications->subscribe('Ecommerce-orders');
84
    }
85
86
    public function closeCartAction($cartId = 0) {
87
        $cart = Ecommerce\Cart::get((int) $cartId);
88
        $result = new Server\Result();
89
        if ($cart && $cart->cart_status_id != 5) {
90
            $cart->cart_status_id = 5;
91
            $cart->save();
92
            $result->successMsg = 'Заказ был завершен';
93
            $result->send();
94
        }
95
        $result->success = false;
96
        $result->content = 'Такая корзина не найдена';
97
        $result->send();
98
    }
99
100
}