Completed
Push — master ( 97b00d...004fa5 )
by Alexey
07:14
created

EcommerceController::processParseWebAction()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 7
rs 9.4285
cc 2
eloc 4
nc 2
nop 2
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::save('module', $config, 'Ecommerce');
31
            Tools::redirect('/admin/ecommerce/configure', 'Настройки были изменены', 'success');
32
        }
33
        $managers = [
34
            'Ecommerce\Delivery',
35
            'Ecommerce\PayType',
36
            'Ecommerce\Warehouse',
37
            'Ecommerce\Unit',
38
            'Ecommerce\Card',
39
            'Ecommerce\Discount',
40
            'Ecommerce\Item\Type',
41
            'Ecommerce\Item\Option',
42
            'Ecommerce\Item\Offer\Price\Type',
43
            'Ecommerce\UserAdds\Field',
44
        ];
45
        $this->view->setTitle('Настройки магазина');
46
        $this->view->page(['data' => compact('managers')]);
47
    }
48
49
    public function reBlockIndexAction()
50
    {
51
        set_time_limit(0);
52
        $carts = Cart::getList();
53
        foreach ($carts as $cart) {
54
            $cart->save();
55
        }
56
        Tools::redirect('/admin/ecommerce/configure', 'Данные о блокировках обновлены');
57
    }
58
59
    public function reSearchIndexAction($i = 0)
60
    {
61
        set_time_limit(0);
62
        $count = 100;
63
        $items = Ecommerce\Item::getList(['start' => $i * $count, 'limit' => $count]);
64
        if (!$items) {
1 ignored issue
show
Bug Best Practice introduced by
The expression $items of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
65
            Tools::redirect('/admin/ecommerce/configure', 'Поисковый индекс обновлен');
66
        } else {
67
            $i++;
68
            foreach ($items as $key => $item) {
69
                $item->save();
70
                unset($items[$key]);
71
                unset($item);
72
            }
73
            echo 'Происходит процесс индексации: проиндексировано ' . $i * $count;
74
            Tools::redirect('/admin/ecommerce/reSearchIndex/' . $i);
75
        }
76
    }
77
78
    public function newOrdersSubscribeAction()
79
    {
80
        $this->Notifications->subscribe('Ecommerce-orders');
81
    }
82
83
    public function closeCartAction($cartId = 0)
84
    {
85
        $cart = Ecommerce\Cart::get((int) $cartId);
86
        $result = new Server\Result();
87
        if ($cart && $cart->cart_status_id != 5) {
88
            $cart->cart_status_id = 5;
89
            $cart->save();
90
            $result->successMsg = 'Заказ был завершен';
91
            $result->send();
92
        }
93
        $result->success = false;
94
        $result->content = 'Такая корзина не найдена';
95
        $result->send();
96
    }
97
98
}
99