Completed
Push — master ( 0d4988...d79a7d )
by Alexey
05:18
created

EcommerceController::newOrdersSubscribeAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 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
    {
15
        $this->view->setTitle('Онлайн магазин');
16
        $this->view->page();
17
    }
18
19
    public function configureAction()
1 ignored issue
show
Coding Style introduced by
configureAction uses the super-global variable $_POST which is generally not recommended.

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:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
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::save('module', $config, 'Ecommerce');
32
            Tools::redirect('/admin/ecommerce/configure', 'Настройки были изменены', 'success');
33
        }
34
        $managers = [
35
            'Ecommerce\Delivery',
36
            'Ecommerce\PayType',
37
            'Ecommerce\Warehouse',
38
            'Ecommerce\Unit',
39
            'Ecommerce\Card',
40
            'Ecommerce\Discount',
41
            'Ecommerce\Cart\Stage',
42
            'Ecommerce\Item\Type',
43
            'Ecommerce\Item\Option',
44
            'Ecommerce\Item\Offer\Price\Type',
45
            'Ecommerce\UserAdds\Field',
46
            'Ecommerce\Cart\Status',
47
            'Ecommerce\Delivery\Field',
48
        ];
49
        $this->view->setTitle('Настройки магазина');
50
        $this->view->page(['data' => compact('managers')]);
51
    }
52
53
    public function reBlockIndexAction()
54
    {
55
        set_time_limit(0);
56
        $carts = Cart::getList();
57
        foreach ($carts as $cart) {
58
            $cart->save();
59
        }
60
        Tools::redirect('/admin/ecommerce/configure', 'Данные о блокировках обновлены');
61
    }
62
63
    public function reSearchIndexAction($i = 0)
64
    {
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
    {
84
        $this->Notifications->subscribe('Ecommerce-orders');
85
    }
86
87
    public function closeCartAction($cartId = 0)
88
    {
89
        $cart = Ecommerce\Cart::get((int) $cartId);
90
        $result = new Server\Result();
91
        if ($cart && $cart->cart_status_id != 5) {
92
            $cart->cart_status_id = 5;
93
            $cart->save();
94
            $result->successMsg = 'Заказ был завершен';
95
            $result->send();
96
        }
97
        $result->success = false;
98
        $result->content = 'Такая корзина не найдена';
99
        $result->send();
100
    }
101
102
}
103