Passed
Push — v5 ( e348bf...8a8f01 )
by Alexey
06:35
created

EcommerceController::configureAction()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 179
Code Lines 119

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 119
nc 4
nop 0
dl 0
loc 179
rs 8.1935
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
        $options = [
20
            [
21
                'type' => 'checkbox',
22
                'name' => 'view_empty_warehouse',
23
                'label' => 'Продавать отсутствующие товары',
24
                'options' => [
25
                    'value' => Tools::defValue(App::$cur->ecommerce->config['sell_over_warehouse'], false)
0 ignored issues
show
Bug introduced by
The type Tools was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
26
                ]
27
            ],
28
            [
29
                'type' => 'checkbox',
30
                'name' => 'view_empty_image',
31
                'label' => 'Показывать товары без изображения',
32
                'options' => [
33
                    'value' => Tools::defValue(App::$cur->ecommerce->config['view_empty_image'], false)
34
                ]
35
            ],
36
            [
37
                'type' => 'checkbox',
38
                'name' => 'sell_empty_warehouse',
39
                'label' => 'Продавать без остатоков на складе',
40
                'options' => [
41
                    'value' => Tools::defValue(App::$cur->ecommerce->config['sell_empty_warehouse'], false)
42
                ]
43
            ],
44
            [
45
                'type' => 'checkbox',
46
                'name' => 'sell_over_warehouse',
47
                'label' => 'Продавать сверх остатоков на складе',
48
                'options' => [
49
                    'value' => Tools::defValue(App::$cur->ecommerce->config['sell_over_warehouse'], false)
50
                ]
51
            ],
52
            [
53
                'type' => 'checkbox',
54
                'label' => 'Показывать товары с нулевой ценой',
55
                'name' => 'show_zero_price',
56
                'options' => [
57
                    'value' => Tools::defValue(App::$cur->ecommerce->config['show_zero_price'], false)
58
                ]
59
            ],
60
            [
61
                'type' => 'checkbox',
62
                'name' => 'show_without_price',
63
                'label' => 'Показывать товары без цен',
64
                'options' => [
65
                    'value' => Tools::defValue(App::$cur->ecommerce->config['show_without_price'], false)
66
                ]
67
            ],
68
            [
69
                'type' => 'checkbox',
70
                'name' => 'filtersInLast',
71
                'label' => 'Показывать Фильтры только текущей и дочерних категорий',
72
                'options' => [
73
                    'value' => Tools::defValue(App::$cur->ecommerce->config['filtersInLast'], false)
74
                ]
75
            ],
76
            [
77
                'type' => 'checkbox',
78
                'name' => 'isset_sort',
79
                'label' => 'Возможность сортировки по наличию',
80
                'options' => [
81
                    'value' => Tools::defValue(App::$cur->ecommerce->config['isset_sort'], false)
82
                ]
83
            ],
84
            [
85
                'type' => 'checkbox',
86
                'name' => 'list_all',
87
                'label' => 'Возможность вывести все товары',
88
                'options' => [
89
                    'value' => Tools::defValue(App::$cur->ecommerce->config['list_all'], false)
90
                ]
91
            ],
92
            [
93
                'type' => 'checkbox',
94
                'name' => 'cartAddToggle',
95
                'label' => 'Удаление из корзины при повторном добавлении товара',
96
                'options' => [
97
                    'value' => Tools::defValue(App::$cur->ecommerce->config['cartAddToggle'], false)
98
                ]
99
            ],
100
            [
101
                'type' => 'checkbox',
102
                'name' => 'defaultNeedDelivery',
103
                'label' => 'По умолчанию для всех товаров доставка осуществляется',
104
                'options' => [
105
                    'value' => Tools::defValue(App::$cur->ecommerce->config['defaultNeedDelivery'], false)
106
                ]
107
            ],
108
            [
109
                'type' => 'checkbox',
110
                'name' => 'catalogPresentPage',
111
                'label' => 'Заглавная страница магазина',
112
                'options' => [
113
                    'value' => Tools::defValue(App::$cur->ecommerce->config['catalogPresentPage'], false)
114
                ]
115
            ],
116
            [
117
                'type' => 'text',
118
                'name' => 'notify_mail',
119
                'label' => 'E-mail оповещений о новых заказах',
120
                'options' => [
121
                    'value' => Tools::defValue(App::$cur->ecommerce->config['notify_mail'], '')
122
                ]
123
            ],
124
            [
125
                'type' => 'select',
126
                'name' => 'defaultCategoryView',
127
                'label' => 'Стандартный вид категории',
128
                'options' => [
129
                    'value' => Tools::defValue(App::$cur->ecommerce->config['defaultCategoryView'], 'itemList'),
130
                    'values' => App::$cur->ecommerce->viewsCategoryList()
131
                ]
132
            ],
133
            [
134
                'type' => 'text',
135
                'name' => 'orderPrefix',
136
                'label' => 'Префикс для номеров заказов',
137
                'options' => [
138
                    'value' => Tools::defValue(App::$cur->ecommerce->config['orderPrefix'], '')
139
                ]
140
            ],
141
            [
142
                'type' => 'number',
143
                'name' => 'default_limit',
144
                'label' => 'Товаров на страницу',
145
                'options' => [
146
                    'value' => Tools::defValue(App::$cur->ecommerce->config['default_limit'], 18)
147
                ]
148
            ],
149
            [
150
                'type' => 'text',
151
                'name' => 'defaultCategoryTemplate',
152
                'label' => 'Шаблон магазина',
153
                'options' => [
154
                    'value' => Tools::defValue(App::$cur->ecommerce->config['defaultCategoryTemplate'], 'current')
155
                ]
156
            ],
157
        ];
158
        if (App::$cur->money) {
159
            $options[] = [
160
                'type' => 'select',
161
                'name' => 'defaultCurrency',
162
                'label' => 'Валюта по умолчанию',
163
                'options' => [
164
                    'value' => Tools::defValue(App::$cur->ecommerce->config['defaultCategoryView'], ''),
165
                    'values' => ['' => 'Выберите'] + \Money\Currency::getList()
166
                ]
167
            ];
168
        }
169
        if (!empty($_POST['config'])) {
170
            $config = App::$cur->ecommerce->config;
171
            foreach ($options as $option) {
172
                $config[$option['name']] = Tools::defValue($_POST['config'][$option['name']], false);
173
            }
174
            Config::save('module', $config, 'Ecommerce');
175
            Tools::redirect('/admin/ecommerce/configure', 'Настройки были изменены', 'success');
176
        }
177
178
        $managers = [
179
            'Ecommerce\Delivery',
180
            'Ecommerce\PayType',
181
            'Ecommerce\Warehouse',
182
            'Ecommerce\Unit',
183
            'Ecommerce\Card',
184
            'Ecommerce\Discount',
185
            'Ecommerce\Cart\Stage',
186
            'Ecommerce\Item\Type',
187
            'Ecommerce\Item\Option',
188
            'Ecommerce\Item\Offer\Option',
189
            'Ecommerce\Item\Offer\Price\Type',
190
            'Ecommerce\UserAdds\Field',
191
            'Ecommerce\Cart\Status',
192
            'Ecommerce\Delivery\Field',
193
            'Ecommerce\Delivery\Provider',
194
        ];
195
        $this->view->setTitle('Настройки магазина');
196
        $this->view->page(['data' => compact('managers', 'options')]);
197
    }
198
199
    public function reCalcCategoriesAction() {
200
        set_time_limit(0);
201
        Model::$logging = false;
202
        ini_set('memory_limit', '-1');
203
        $categories = \Ecommerce\Category::getList();
204
        foreach ($categories as $category) {
205
            if (!$category->catalogs) {
206
                $time = microtime(true);
207
                echo $category->id . " start->";
208
                flush();
209
                $category->calcItemsCount(true, false);
210
                echo round(microtime(true) - $time, 2) . "<br />";
211
                flush();
212
            }
213
        }
214
        Tools::redirect('/admin/ecommerce/configure', 'Данные о кол-ве обновлены');
215
    }
216
217
    public function reSearchIndexAction($i = 0) {
218
        set_time_limit(0);
219
        Model::$logging = false;
220
        ini_set('memory_limit', '-1');
221
        $count = 100;
222
        $items = Ecommerce\Item::getList(['start' => $i * $count, 'limit' => $count]);
223
        if (!$items) {
224
            Tools::redirect('/admin/ecommerce/configure', 'Поисковый индекс обновлен');
225
        } else {
226
            $i++;
227
            foreach ($items as $key => $item) {
228
                $item->save();
229
                unset($items[$key]);
230
                unset($item);
231
            }
232
            echo 'Происходит процесс индексации: проиндексировано ' . $i * $count;
233
            echo '<script>setTimeout(function(){window.location="/admin/ecommerce/reSearchIndex/' . $i . '"},100)</script>';
234
        }
235
    }
236
237
    public function newOrdersSubscribeAction() {
238
        $this->Notifications->subscribe('Ecommerce-orders');
239
    }
240
241
    public function closeCartAction($cartId = 0) {
242
        $cart = Ecommerce\Cart::get((int) $cartId);
243
        $result = new Server\Result();
244
        if ($cart && $cart->cart_status_id != 5) {
245
            $cart->cart_status_id = 5;
246
            $cart->save();
247
            $result->successMsg = 'Заказ был завершен';
248
            $result->send();
249
        }
250
        $result->success = false;
251
        $result->content = 'Такая корзина не найдена';
252
        $result->send();
253
    }
254
255
}