Completed
Push — master ( c3dfe8...100a0b )
by Alexey
05:48
created
system/modules/Ecommerce/widgets/cart/delivery.php 1 patch
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -2,57 +2,57 @@
 block discarded – undo
2 2
   <div class="col-md-4">
3 3
     <ul class="nav nav-pills nav-stacked">
4 4
       <?php
5
-      $hiddenId = Tools::randomString();
6
-      foreach ($deliverys as $delivery) {
5
+        $hiddenId = Tools::randomString();
6
+        foreach ($deliverys as $delivery) {
7 7
         if ((!empty($_POST['delivery']) && $_POST['delivery'] == $delivery->id) || ($cart->delivery && $delivery->id == $cart->delivery->id)) {
8
-          $checked = 'checked';
8
+            $checked = 'checked';
9 9
         } else {
10
-          $checked = '';
10
+            $checked = '';
11 11
         }
12 12
         echo '<li' . ($checked ? ' class="active"' : '') . '><a href = "#" onclick = "document.getElementById(\'' . $hiddenId . '\').value=\'' . $delivery->id . '\';inji.Ecommerce.Cart.calcSum();return false;">';
13 13
         echo $delivery->name;
14 14
         echo '</a></li>';
15
-      }
16
-      $form->input('hidden', "delivery", '', [
17
-          'value' => $cart->delivery_id,
18
-          'attributes' => [
19
-              'id' => $hiddenId
20
-          ],
21
-      ]);
22
-      ?>
15
+        }
16
+        $form->input('hidden', "delivery", '', [
17
+            'value' => $cart->delivery_id,
18
+            'attributes' => [
19
+                'id' => $hiddenId
20
+            ],
21
+        ]);
22
+        ?>
23 23
     </ul>
24 24
   </div>
25 25
   <div class="col-md-8">
26 26
     <?php
27 27
     if ($cart->delivery) {
28
-      echo "<h4>Информация о доставке</h4>";
29
-      if ($cart->delivery->price_text || $cart->delivery->price) {
28
+        echo "<h4>Информация о доставке</h4>";
29
+        if ($cart->delivery->price_text || $cart->delivery->price) {
30 30
         echo "<div>Стоимость доставки: <b>" . ($cart->delivery->price_text ? $cart->delivery->price_text : ( $cart->delivery->price . ' ' . ($cart->delivery->currency ? $cart->delivery->currency->acronym() : 'руб.') )) . '</b></div>';
31
-      }
32
-      if ((float) $cart->delivery->max_cart_price) {
31
+        }
32
+        if ((float) $cart->delivery->max_cart_price) {
33 33
         echo '<div>При заказе товаров на сумму от ' . $cart->delivery->max_cart_price . ' руб - бесплатно</div>';
34
-      }
35
-      echo $cart->delivery->info;
36
-      if ($cart->delivery->fields) {
34
+        }
35
+        echo $cart->delivery->info;
36
+        if ($cart->delivery->fields) {
37 37
         echo '<hr />';
38 38
         foreach ($cart->delivery->fields as $field) {
39
-          $options = ['required' => $field->required];
40
-          if ($field->type == 'radio') {
39
+            $options = ['required' => $field->required];
40
+            if ($field->type == 'radio') {
41 41
             $values = $field->fieldItems(['forSelect' => true]);
42 42
             foreach ($values as $key => $value) {
43
-              $options['value'] = $key;
44
-              $form->input($field->type, "deliveryFields[{$field->id}]", $value, $options);
43
+                $options['value'] = $key;
44
+                $form->input($field->type, "deliveryFields[{$field->id}]", $value, $options);
45 45
             }
46
-          } else {
46
+            } else {
47 47
             if ($field->type == 'select') {
48
-              $options['values'] = $field->fieldItems(['forSelect' => true]);
48
+                $options['values'] = $field->fieldItems(['forSelect' => true]);
49 49
             }
50 50
             $form->input($field->type, "deliveryFields[{$field->id}]", $field->name, $options);
51
-          }
51
+            }
52
+        }
52 53
         }
53
-      }
54 54
     } else {
55
-      echo "<h4>Выберите способ доставки</h4>";
55
+        echo "<h4>Выберите способ доставки</h4>";
56 56
     }
57 57
     ?>
58 58
   </div>
Please login to merge, or discard this patch.
system/modules/Ecommerce/models/Cart.php 1 patch
Indentation   +205 added lines, -205 removed lines patch added patch discarded remove patch
@@ -13,9 +13,9 @@  discard block
 block discarded – undo
13 13
 
14 14
 class Cart extends \Model {
15 15
 
16
-  public static $objectName = 'Корзины';
16
+    public static $objectName = 'Корзины';
17 17
 
18
-  public static function indexes() {
18
+    public static function indexes() {
19 19
     return [
20 20
         'ecommerce_cartStatusBlock' => [
21 21
             'type' => 'INDEX',
@@ -37,9 +37,9 @@  discard block
 block discarded – undo
37 37
             ]
38 38
         ],
39 39
     ];
40
-  }
40
+    }
41 41
 
42
-  public static function relations() {
42
+    public static function relations() {
43 43
     return [
44 44
         'user' => [
45 45
             'model' => 'Users\User',
@@ -97,279 +97,279 @@  discard block
 block discarded – undo
97 97
             'model' => 'Ecommerce\Discount',
98 98
         ]
99 99
     ];
100
-  }
100
+    }
101 101
 
102
-  public function beforeDelete() {
102
+    public function beforeDelete() {
103 103
     foreach ($this->cartItems as $cartItem) {
104
-      $cartItem->delete();
104
+        $cartItem->delete();
105 105
     }
106 106
     foreach ($this->infos as $info) {
107
-      $info->delete();
107
+        $info->delete();
108 108
     }
109 109
     foreach ($this->extras as $extra) {
110
-      $extra->delete();
110
+        $extra->delete();
111 111
     }
112 112
     foreach ($this->events as $event) {
113
-      $event->delete();
113
+        $event->delete();
114
+    }
114 115
     }
115
-  }
116 116
 
117
-  public static $labels = [
118
-      'user_id' => 'Пользователь',
119
-      'cart_status_id' => 'Статус',
120
-      'delivery_id' => 'Доставка',
121
-      'comment' => 'Комментарий',
122
-      'bonus_used' => 'Выгодные рубли',
123
-      'complete_data' => 'Время заказа',
124
-      'info' => 'Информация',
125
-      'items' => 'Товары',
126
-      'paytype_id' => 'Способ оплаты',
127
-      'payed' => 'Оплачен',
128
-      'exported' => 'Выгружено',
129
-      'warehouse_block' => 'Блокировка товаров',
130
-      'extra' => 'Доп.',
131
-      'card_item_id' => 'Дисконтная карта',
132
-      'info' => 'Информация',
133
-      'contacts' => 'Информация',
134
-      'pay' => 'Счета',
135
-      'sums' => 'Суммы',
136
-      'deliveryInfo' => 'Для доставки',
137
-      'discount' => 'Скидки',
138
-  ];
139
-  public static $cols = [
140
-      //Основные параметры
141
-      'user_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'user'],
142
-      'cart_status_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'status'],
143
-      'delivery_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'delivery'],
144
-      'paytype_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'payType'],
145
-      'card_item_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'card'],
146
-      'warehouse_block' => ['type' => 'bool'],
147
-      'payed' => ['type' => 'bool'],
148
-      'comment' => ['type' => 'textarea'],
149
-      //Системные
150
-      'exported' => ['type' => 'bool'],
151
-      'complete_data' => ['type' => 'dateTime'],
152
-      'date_status' => ['type' => 'dateTime'],
153
-      'date_last_activ' => ['type' => 'dateTime'],
154
-      'date_create' => ['type' => 'dateTime'],
155
-      //Виджеты
156
-      'sums' => [
157
-          'type' => 'void',
158
-          'view' => [
159
-              'type' => 'widget',
160
-              'widget' => 'Ecommerce\adminSums',
161
-          ],
162
-      ],
163
-      'contacts' => [
164
-          'type' => 'void',
165
-          'view' => [
166
-              'type' => 'widget',
167
-              'widget' => 'Ecommerce\admin/contacts',
168
-          ],
169
-      ],
170
-      //Менеджеры
171
-      'extra' => ['type' => 'dataManager', 'relation' => 'extras'],
172
-      'pay' => ['type' => 'dataManager', 'relation' => 'pays'],
173
-      'items' => ['type' => 'dataManager', 'relation' => 'cartItems'],
174
-      'info' => ['type' => 'dataManager', 'relation' => 'infos'],
175
-      'deliveryInfo' => ['type' => 'dataManager', 'relation' => 'deliveryInfos'],
176
-      'discount' => ['type' => 'dataManager', 'relation' => 'discounts'],
177
-  ];
178
-  public static $dataManagers = [
179
-      'manager' => [
180
-          'cols' => [
181
-              'contacts',
182
-              'items',
183
-              'extra',
184
-              'discount',
185
-              'sums',
186
-              'cart_status_id',
187
-              'delivery_id',
188
-              'deliveryInfo',
189
-              'payed',
190
-              'pay',
191
-              'complete_data',
192
-          ],
193
-          'sortable' => [
194
-              'cart_status_id',
195
-              'delivery_id',
196
-              'payed',
197
-              'complete_data',
198
-          ],
199
-          'filters' => [
200
-              'cart_status_id',
201
-              'delivery_id',
202
-              'payed',
203
-              'complete_data',
204
-          ],
205
-          'preSort' => [
206
-              'complete_data' => 'desc'
207
-          ],
208
-          'actions' => [
209
-              'Ecommerce\CloseCartBtn', 'Open', 'Edit', 'Delete'
210
-          ]
211
-      ]
212
-  ];
117
+    public static $labels = [
118
+        'user_id' => 'Пользователь',
119
+        'cart_status_id' => 'Статус',
120
+        'delivery_id' => 'Доставка',
121
+        'comment' => 'Комментарий',
122
+        'bonus_used' => 'Выгодные рубли',
123
+        'complete_data' => 'Время заказа',
124
+        'info' => 'Информация',
125
+        'items' => 'Товары',
126
+        'paytype_id' => 'Способ оплаты',
127
+        'payed' => 'Оплачен',
128
+        'exported' => 'Выгружено',
129
+        'warehouse_block' => 'Блокировка товаров',
130
+        'extra' => 'Доп.',
131
+        'card_item_id' => 'Дисконтная карта',
132
+        'info' => 'Информация',
133
+        'contacts' => 'Информация',
134
+        'pay' => 'Счета',
135
+        'sums' => 'Суммы',
136
+        'deliveryInfo' => 'Для доставки',
137
+        'discount' => 'Скидки',
138
+    ];
139
+    public static $cols = [
140
+        //Основные параметры
141
+        'user_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'user'],
142
+        'cart_status_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'status'],
143
+        'delivery_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'delivery'],
144
+        'paytype_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'payType'],
145
+        'card_item_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'card'],
146
+        'warehouse_block' => ['type' => 'bool'],
147
+        'payed' => ['type' => 'bool'],
148
+        'comment' => ['type' => 'textarea'],
149
+        //Системные
150
+        'exported' => ['type' => 'bool'],
151
+        'complete_data' => ['type' => 'dateTime'],
152
+        'date_status' => ['type' => 'dateTime'],
153
+        'date_last_activ' => ['type' => 'dateTime'],
154
+        'date_create' => ['type' => 'dateTime'],
155
+        //Виджеты
156
+        'sums' => [
157
+            'type' => 'void',
158
+            'view' => [
159
+                'type' => 'widget',
160
+                'widget' => 'Ecommerce\adminSums',
161
+            ],
162
+        ],
163
+        'contacts' => [
164
+            'type' => 'void',
165
+            'view' => [
166
+                'type' => 'widget',
167
+                'widget' => 'Ecommerce\admin/contacts',
168
+            ],
169
+        ],
170
+        //Менеджеры
171
+        'extra' => ['type' => 'dataManager', 'relation' => 'extras'],
172
+        'pay' => ['type' => 'dataManager', 'relation' => 'pays'],
173
+        'items' => ['type' => 'dataManager', 'relation' => 'cartItems'],
174
+        'info' => ['type' => 'dataManager', 'relation' => 'infos'],
175
+        'deliveryInfo' => ['type' => 'dataManager', 'relation' => 'deliveryInfos'],
176
+        'discount' => ['type' => 'dataManager', 'relation' => 'discounts'],
177
+    ];
178
+    public static $dataManagers = [
179
+        'manager' => [
180
+            'cols' => [
181
+                'contacts',
182
+                'items',
183
+                'extra',
184
+                'discount',
185
+                'sums',
186
+                'cart_status_id',
187
+                'delivery_id',
188
+                'deliveryInfo',
189
+                'payed',
190
+                'pay',
191
+                'complete_data',
192
+            ],
193
+            'sortable' => [
194
+                'cart_status_id',
195
+                'delivery_id',
196
+                'payed',
197
+                'complete_data',
198
+            ],
199
+            'filters' => [
200
+                'cart_status_id',
201
+                'delivery_id',
202
+                'payed',
203
+                'complete_data',
204
+            ],
205
+            'preSort' => [
206
+                'complete_data' => 'desc'
207
+            ],
208
+            'actions' => [
209
+                'Ecommerce\CloseCartBtn', 'Open', 'Edit', 'Delete'
210
+            ]
211
+        ]
212
+    ];
213 213
 
214
-  public static function itemName($item) {
214
+    public static function itemName($item) {
215 215
     return $item->pk() . '. ' . $item->name();
216
-  }
216
+    }
217 217
 
218
-  public static $forms = [
219
-      'manager' => [
220
-          'inputs' => [
221
-              'userSearch' => [
222
-                  'type' => 'search',
223
-                  'source' => 'relation',
224
-                  'relation' => 'user',
225
-                  'label' => 'Покупатель',
226
-                  'cols' => [
227
-                      'info:first_name',
228
-                      'info:last_name',
229
-                      'info:middle_name',
230
-                      'mail'
231
-                  ],
232
-                  'col' => 'user_id',
233
-                  'required' => true,
234
-                  'showCol' => [
235
-                      'type' => 'staticMethod',
236
-                      'class' => 'Ecommerce\Cart',
237
-                      'method' => 'itemName',
238
-                  ],
239
-              ],
240
-              'cardSearch' => [
241
-                  'type' => 'search',
242
-                  'source' => 'relation',
243
-                  'relation' => 'card',
244
-                  'label' => 'Дисконтная карта',
245
-                  'cols' => [
246
-                      'code',
247
-                      'user:info:first_name',
248
-                      'user:info:last_name',
249
-                      'user:info:middle_name',
250
-                      'user:mail'
251
-                  ],
252
-                  'col' => 'card_item_id',
253
-              ],
254
-          ],
255
-          'map' => [
256
-              ['userSearch', 'cart_status_id'],
257
-              ['paytype_id', 'delivery_id'],
258
-              ['cardSearch', 'comment'],
259
-              ['warehouse_block', 'complete_data'],
260
-              ['payed'],
261
-              ['items'],
262
-              ['extra'],
263
-              ['pay'],
264
-              ['info'],
265
-              ['deliveryInfo']
266
-          ]
267
-      ],
268
-  ];
218
+    public static $forms = [
219
+        'manager' => [
220
+            'inputs' => [
221
+                'userSearch' => [
222
+                    'type' => 'search',
223
+                    'source' => 'relation',
224
+                    'relation' => 'user',
225
+                    'label' => 'Покупатель',
226
+                    'cols' => [
227
+                        'info:first_name',
228
+                        'info:last_name',
229
+                        'info:middle_name',
230
+                        'mail'
231
+                    ],
232
+                    'col' => 'user_id',
233
+                    'required' => true,
234
+                    'showCol' => [
235
+                        'type' => 'staticMethod',
236
+                        'class' => 'Ecommerce\Cart',
237
+                        'method' => 'itemName',
238
+                    ],
239
+                ],
240
+                'cardSearch' => [
241
+                    'type' => 'search',
242
+                    'source' => 'relation',
243
+                    'relation' => 'card',
244
+                    'label' => 'Дисконтная карта',
245
+                    'cols' => [
246
+                        'code',
247
+                        'user:info:first_name',
248
+                        'user:info:last_name',
249
+                        'user:info:middle_name',
250
+                        'user:mail'
251
+                    ],
252
+                    'col' => 'card_item_id',
253
+                ],
254
+            ],
255
+            'map' => [
256
+                ['userSearch', 'cart_status_id'],
257
+                ['paytype_id', 'delivery_id'],
258
+                ['cardSearch', 'comment'],
259
+                ['warehouse_block', 'complete_data'],
260
+                ['payed'],
261
+                ['items'],
262
+                ['extra'],
263
+                ['pay'],
264
+                ['info'],
265
+                ['deliveryInfo']
266
+            ]
267
+        ],
268
+    ];
269 269
 
270
-  public function checkStage() {
270
+    public function checkStage() {
271 271
     $sum = $this->itemsSum();
272 272
     $stages = Cart\Stage::getList(['order' => ['sum', 'asc']]);
273 273
     $groups = [];
274 274
     foreach ($stages as $stage) {
275
-      if ($sum->greater(new \Money\Sums([$stage->currency_id => $stage->sum])) || $sum->equal(new \Money\Sums([$stage->currency_id => $stage->sum]))) {
275
+        if ($sum->greater(new \Money\Sums([$stage->currency_id => $stage->sum])) || $sum->equal(new \Money\Sums([$stage->currency_id => $stage->sum]))) {
276 276
         $groups[$stage->group] = $stage;
277
-      }
277
+        }
278 278
     }
279 279
     $discounts = Cart\Discount::getList(['where' => ['cart_id', $this->id]]);
280 280
     foreach ($discounts as $discount) {
281
-      if (!isset($groups[$discount->group]) && $discount->auto) {
281
+        if (!isset($groups[$discount->group]) && $discount->auto) {
282 282
         $discount->delete();
283
-      }
284
-      if (isset($groups[$discount->group]) && $groups[$discount->group]->type == 'discount') {
283
+        }
284
+        if (isset($groups[$discount->group]) && $groups[$discount->group]->type == 'discount') {
285 285
         $discount->discount_id = $groups[$discount->group]->value;
286 286
         $discount->save();
287 287
         unset($groups[$discount->group]);
288
-      }
288
+        }
289 289
     }
290 290
     foreach ($groups as $group) {
291
-      if ($group && $group->type == 'discount') {
291
+        if ($group && $group->type == 'discount') {
292 292
         $rel = $this->addRelation('discounts', $group->value);
293 293
         $rel->auto = true;
294 294
         $rel->group = 'discount';
295 295
         $rel->save();
296
-      }
296
+        }
297
+    }
297 298
     }
298
-  }
299 299
 
300
-  public function needDelivery() {
300
+    public function needDelivery() {
301 301
     foreach ($this->cartItems as $cartItem) {
302
-      if ($cartItem->item->type && $cartItem->item->type->delivery) {
302
+        if ($cartItem->item->type && $cartItem->item->type->delivery) {
303 303
         return true;
304
-      }
304
+        }
305 305
     }
306 306
     return false;
307
-  }
307
+    }
308 308
 
309
-  public function deliverySum() {
309
+    public function deliverySum() {
310 310
     $sum = new \Money\Sums([]);
311 311
     if ($this->delivery && $this->needDelivery()) {
312
-      $sums = $this->itemsSum();
313
-      $deliveryPrice = new \Money\Sums([$this->delivery->currency_id => $this->delivery->max_cart_price]);
314
-      if ($this->delivery->max_cart_price && $sums->greater($deliveryPrice) || $sums->equal($deliveryPrice)) {
312
+        $sums = $this->itemsSum();
313
+        $deliveryPrice = new \Money\Sums([$this->delivery->currency_id => $this->delivery->max_cart_price]);
314
+        if ($this->delivery->max_cart_price && $sums->greater($deliveryPrice) || $sums->equal($deliveryPrice)) {
315 315
         $sum->sums = [$this->delivery->currency_id => 0];
316
-      } else if ($this->delivery->prices) {
316
+        } else if ($this->delivery->prices) {
317 317
         foreach ($this->delivery->prices(['order' => ['cart_price', 'asc']]) as $delPrice) {
318
-          $deliveryPrice = new \Money\Sums([$delPrice->currency_id => $delPrice->cart_price]);
319
-          if ($sums->greater($deliveryPrice) || $sums->equal($deliveryPrice)) {
318
+            $deliveryPrice = new \Money\Sums([$delPrice->currency_id => $delPrice->cart_price]);
319
+            if ($sums->greater($deliveryPrice) || $sums->equal($deliveryPrice)) {
320 320
             $sum->sums = [$delPrice->currency_id => $delPrice->price];
321
-          }
321
+            }
322 322
         }
323 323
         if (!$sum->sums) {
324
-          $sum->sums = [$this->delivery->currency_id => $this->delivery->price];
324
+            $sum->sums = [$this->delivery->currency_id => $this->delivery->price];
325 325
         }
326
-      } else {
326
+        } else {
327 327
         $sum->sums = [$this->delivery->currency_id => $this->delivery->price];
328
-      }
328
+        }
329 329
     }
330 330
     return $sum;
331
-  }
331
+    }
332 332
 
333
-  public function hasDiscount() {
333
+    public function hasDiscount() {
334 334
     return (bool) $this->card || $this->discounts;
335
-  }
335
+    }
336 336
 
337
-  public function discountSum() {
337
+    public function discountSum() {
338 338
     $sums = [];
339 339
     foreach ($this->cartItems as $cartItem) {
340
-      $sums[$cartItem->price->currency_id] = isset($sums[$cartItem->price->currency_id]) ? $sums[$cartItem->price->currency_id] + $cartItem->discount() * $cartItem->count : $cartItem->discount() * $cartItem->count;
340
+        $sums[$cartItem->price->currency_id] = isset($sums[$cartItem->price->currency_id]) ? $sums[$cartItem->price->currency_id] + $cartItem->discount() * $cartItem->count : $cartItem->discount() * $cartItem->count;
341 341
     }
342 342
     return new \Money\Sums($sums);
343
-  }
343
+    }
344 344
 
345
-  public function finalSum() {
345
+    public function finalSum() {
346 346
     $sums = $this->itemsSum();
347 347
     $sums = $sums->minus($this->discountSum());
348 348
     $sums = $sums->plus($this->deliverySum());
349 349
     return $sums;
350
-  }
350
+    }
351 351
 
352
-  public function itemsSum() {
352
+    public function itemsSum() {
353 353
     $cart = Cart::get($this->id);
354 354
     $sums = [];
355 355
     foreach ($cart->cartItems as $cartItem) {
356
-      if (!$cartItem->price) {
356
+        if (!$cartItem->price) {
357 357
         continue;
358
-      }
359
-      $sums[$cartItem->price->currency_id] = isset($sums[$cartItem->price->currency_id]) ? $sums[$cartItem->price->currency_id] + $cartItem->price->price * $cartItem->count : $cartItem->price->price * $cartItem->count;
358
+        }
359
+        $sums[$cartItem->price->currency_id] = isset($sums[$cartItem->price->currency_id]) ? $sums[$cartItem->price->currency_id] + $cartItem->price->price * $cartItem->count : $cartItem->price->price * $cartItem->count;
360 360
     }
361 361
     return new \Money\Sums($sums);
362
-  }
362
+    }
363 363
 
364
-  public function addItem($offer_price_id, $count = 1, $final_price = 0) {
364
+    public function addItem($offer_price_id, $count = 1, $final_price = 0) {
365 365
     $price = Item\Offer\Price::get((int) $offer_price_id);
366 366
 
367 367
     if (!$price) {
368
-      return false;
368
+        return false;
369 369
     }
370 370
 
371 371
     if ($count <= 0) {
372
-      $count = 1;
372
+        $count = 1;
373 373
     }
374 374
 
375 375
     $cartItem = new Cart\Item();
@@ -380,12 +380,12 @@  discard block
 block discarded – undo
380 380
     $cartItem->final_price = $final_price ? $final_price : $price->price;
381 381
     $cartItem->save();
382 382
     return true;
383
-  }
383
+    }
384 384
 
385
-  public function calc($save = true) {
385
+    public function calc($save = true) {
386 386
     if ($save) {
387
-      $this->save();
387
+        $this->save();
388
+    }
388 389
     }
389
-  }
390 390
 
391 391
 }
Please login to merge, or discard this patch.
system/modules/Ecommerce/models/Delivery/Field.php 1 patch
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -13,44 +13,44 @@  discard block
 block discarded – undo
13 13
 
14 14
 class Field extends \Model {
15 15
 
16
-  public static $objectName = 'Поле доставки';
17
-  public static $cols = [
18
-      //Основные параметры
19
-      'name' => ['type' => 'text'],
20
-      'type' => ['type' => 'text'],
21
-      'userfield' => ['type' => 'text'],
22
-      'required' => ['type' => 'bool'],
23
-      'save' => ['type' => 'bool'],
24
-      'fieldItem'=>['type'=>'dataManager','relation'=>'fieldItems'],
25
-      //Системные
26
-      'date_create' => ['type' => 'dateTime'],
27
-  ];
28
-  public static $labels = [
29
-      'name' => 'Название',
30
-      'type' => 'Тип',
31
-      'userfield' => 'Связь с данными пользователя',
32
-      'required' => 'Обязательно',
33
-      'save' => 'Сохраняется',
34
-      'fieldItem' => 'Значения для списка',
35
-  ];
36
-  public static $dataManagers = [
37
-      'manager' => [
38
-          'cols' => [
39
-              'name', 'type', 'userfield', 'required','fieldItem',  'save'
40
-          ],
41
-      ]
42
-  ];
43
-  public static $forms = [
44
-      'manager' => [
45
-          'map' => [
46
-              ['name', 'type'],
47
-              ['required', 'save'],
48
-              [ 'userfield']
49
-          ]
50
-      ]
51
-  ];
16
+    public static $objectName = 'Поле доставки';
17
+    public static $cols = [
18
+        //Основные параметры
19
+        'name' => ['type' => 'text'],
20
+        'type' => ['type' => 'text'],
21
+        'userfield' => ['type' => 'text'],
22
+        'required' => ['type' => 'bool'],
23
+        'save' => ['type' => 'bool'],
24
+        'fieldItem'=>['type'=>'dataManager','relation'=>'fieldItems'],
25
+        //Системные
26
+        'date_create' => ['type' => 'dateTime'],
27
+    ];
28
+    public static $labels = [
29
+        'name' => 'Название',
30
+        'type' => 'Тип',
31
+        'userfield' => 'Связь с данными пользователя',
32
+        'required' => 'Обязательно',
33
+        'save' => 'Сохраняется',
34
+        'fieldItem' => 'Значения для списка',
35
+    ];
36
+    public static $dataManagers = [
37
+        'manager' => [
38
+            'cols' => [
39
+                'name', 'type', 'userfield', 'required','fieldItem',  'save'
40
+            ],
41
+        ]
42
+    ];
43
+    public static $forms = [
44
+        'manager' => [
45
+            'map' => [
46
+                ['name', 'type'],
47
+                ['required', 'save'],
48
+                [ 'userfield']
49
+            ]
50
+        ]
51
+    ];
52 52
 
53
-  public static function relations() {
53
+    public static function relations() {
54 54
     return [
55 55
         'fieldItems' => [
56 56
             'model' => 'Ecommerce\Delivery\Field\Item',
@@ -58,6 +58,6 @@  discard block
 block discarded – undo
58 58
             'type' => 'many'
59 59
         ],
60 60
     ];
61
-  }
61
+    }
62 62
 
63 63
 }
Please login to merge, or discard this patch.
system/modules/Ecommerce/models/Delivery/DeliveryFieldLink.php 1 patch
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -13,31 +13,31 @@  discard block
 block discarded – undo
13 13
 
14 14
 class DeliveryFieldLink extends \Model {
15 15
 
16
-  public static $labels = [
17
-      'delivery_id' => 'Тип доставки',
18
-      'delivery_field_id' => 'Поле доставки'
19
-  ];
20
-  public static $cols = [
21
-      'delivery_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'delivery'],
22
-      'delivery_field_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'field'],
23
-      'weight' => ['type' => 'number'],
24
-      'date_create' => ['type' => 'dateTime']
25
-  ];
26
-  public static $dataManagers = [
27
-      'manager' => [
28
-          'name' => 'Поля для доставки',
29
-          'cols' => ['delivery_id', 'delivery_field_id', 'date_create'],
30
-      ]
31
-  ];
32
-  public static $forms = [
33
-      'manager' => [
34
-          'map' => [
35
-              ['delivery_id', 'delivery_field_id'],
36
-          ]
37
-      ]
38
-  ];
16
+    public static $labels = [
17
+        'delivery_id' => 'Тип доставки',
18
+        'delivery_field_id' => 'Поле доставки'
19
+    ];
20
+    public static $cols = [
21
+        'delivery_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'delivery'],
22
+        'delivery_field_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'field'],
23
+        'weight' => ['type' => 'number'],
24
+        'date_create' => ['type' => 'dateTime']
25
+    ];
26
+    public static $dataManagers = [
27
+        'manager' => [
28
+            'name' => 'Поля для доставки',
29
+            'cols' => ['delivery_id', 'delivery_field_id', 'date_create'],
30
+        ]
31
+    ];
32
+    public static $forms = [
33
+        'manager' => [
34
+            'map' => [
35
+                ['delivery_id', 'delivery_field_id'],
36
+            ]
37
+        ]
38
+    ];
39 39
 
40
-  public static function relations() {
40
+    public static function relations() {
41 41
     return [
42 42
         'field' => [
43 43
             'model' => 'Ecommerce\Delivery\Field',
@@ -48,6 +48,6 @@  discard block
 block discarded – undo
48 48
             'col' => 'delivery_id'
49 49
         ],
50 50
     ];
51
-  }
51
+    }
52 52
 
53 53
 }
Please login to merge, or discard this patch.
system/modules/Ecommerce/models/Delivery/Price.php 1 patch
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -13,35 +13,35 @@  discard block
 block discarded – undo
13 13
 
14 14
 class Price extends \Model {
15 15
 
16
-  public static $labels = [
17
-      'delivery_id' => 'Тип доставки',
18
-      'cart_price' => 'Сумма корзины',
19
-      'price' => 'Стоимость доставки',
20
-      'currency_id' => 'Валюта',
21
-  ];
22
-  public static $cols = [
23
-      'delivery_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'delivery'],
24
-      'cart_price' => ['type' => 'number'],
25
-      'price' => ['type' => 'number'],
26
-      'currency_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'currency'],
27
-      'date_create' => ['type' => 'dateTime']
28
-  ];
29
-  public static $dataManagers = [
30
-      'manager' => [
31
-          'name' => 'Цены для стоимости корзин',
32
-          'cols' => ['delivery_id', 'cart_price', 'price', 'currency_id'],
33
-      ]
34
-  ];
35
-  public static $forms = [
36
-      'manager' => [
37
-          'map' => [
38
-              ['delivery_id', 'currency_id'],
39
-              ['cart_price', 'price'],
40
-          ]
41
-      ]
42
-  ];
16
+    public static $labels = [
17
+        'delivery_id' => 'Тип доставки',
18
+        'cart_price' => 'Сумма корзины',
19
+        'price' => 'Стоимость доставки',
20
+        'currency_id' => 'Валюта',
21
+    ];
22
+    public static $cols = [
23
+        'delivery_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'delivery'],
24
+        'cart_price' => ['type' => 'number'],
25
+        'price' => ['type' => 'number'],
26
+        'currency_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'currency'],
27
+        'date_create' => ['type' => 'dateTime']
28
+    ];
29
+    public static $dataManagers = [
30
+        'manager' => [
31
+            'name' => 'Цены для стоимости корзин',
32
+            'cols' => ['delivery_id', 'cart_price', 'price', 'currency_id'],
33
+        ]
34
+    ];
35
+    public static $forms = [
36
+        'manager' => [
37
+            'map' => [
38
+                ['delivery_id', 'currency_id'],
39
+                ['cart_price', 'price'],
40
+            ]
41
+        ]
42
+    ];
43 43
 
44
-  public static function relations() {
44
+    public static function relations() {
45 45
     return [
46 46
         'delivery' => [
47 47
             'model' => 'Ecommerce\Delivery',
@@ -52,6 +52,6 @@  discard block
 block discarded – undo
52 52
             'col' => 'currency_id'
53 53
         ],
54 54
     ];
55
-  }
55
+    }
56 56
 
57 57
 }
Please login to merge, or discard this patch.
system/modules/Ecommerce/appControllers/EcommerceController.php 1 patch
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -10,42 +10,42 @@  discard block
 block discarded – undo
10 10
  */
11 11
 class ecommerceController extends Controller {
12 12
 
13
-  public function buyCardAction() {
13
+    public function buyCardAction() {
14 14
     $this->view->setTitle('Покупка карты');
15 15
     $bread = [];
16 16
     $bread[] = ['text' => 'Покупка карты'];
17 17
     $user = Users\User::$cur;
18 18
     if (!empty($_POST) && !empty($_POST['card_id'])) {
19
-      $error = false;
20
-      $card = \Ecommerce\Card::get((int) $_POST['card_id']);
21
-      if (!$card) {
19
+        $error = false;
20
+        $card = \Ecommerce\Card::get((int) $_POST['card_id']);
21
+        if (!$card) {
22 22
         $error = true;
23 23
         Msg::add('Такой карты не существует', 'danger');
24
-      }
24
+        }
25 25
 
26
-      if (!Users\User::$cur->id) {
26
+        if (!Users\User::$cur->id) {
27 27
         $user_id = $this->Users->registration($_POST, true);
28 28
         if (!$user_id) {
29
-          $error = true;
30
-          $user = null;
29
+            $error = true;
30
+            $user = null;
31 31
         } else {
32
-          $user = Users\User::get($user_id);
32
+            $user = Users\User::get($user_id);
33
+        }
33 34
         }
34
-      }
35
-      $userCard = \Ecommerce\Card\Item::get([['card_id', $card->id], ['user_id', $user->id]]);
36
-      if ($userCard) {
35
+        $userCard = \Ecommerce\Card\Item::get([['card_id', $card->id], ['user_id', $user->id]]);
36
+        if ($userCard) {
37 37
         $error = true;
38 38
         Msg::add('У вас уже есть такая карта', 'danger');
39
-      }
39
+        }
40 40
 
41
-      $fields = \Ecommerce\UserAdds\Field::getList();
42
-      foreach ($fields as $field) {
41
+        $fields = \Ecommerce\UserAdds\Field::getList();
42
+        foreach ($fields as $field) {
43 43
         if (empty($_POST['userAdds']['fields'][$field->id]) && $field->required) {
44
-          $error = 1;
45
-          Msg::add('Вы не указали: ' . $field->name);
44
+            $error = 1;
45
+            Msg::add('Вы не указали: ' . $field->name);
46
+        }
46 47
         }
47
-      }
48
-      if (!$error) {
48
+        if (!$error) {
49 49
         $cardItem = new \Ecommerce\Card\Item();
50 50
         $cardItem->card_id = $card->id;
51 51
         $cardItem->user_id = $user->id;
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
         $cart->date_status = date('Y-m-d H:i:s');
59 59
         $cart->complete_data = date('Y-m-d H:i:s');
60 60
         if (!empty($_SESSION['cart']['cart_id'])) {
61
-          $cart->card_item_id = $cardItem->id;
61
+            $cart->card_item_id = $cardItem->id;
62 62
         }
63 63
         $cart->save();
64 64
 
@@ -73,69 +73,69 @@  discard block
 block discarded – undo
73 73
         $extra->info = 'card:' . $card->id . '|cardItem:' . $cardItem->id;
74 74
         $extra->save();
75 75
         Tools::redirect('/ecommerce/cart/success');
76
-      }
76
+        }
77 77
     }
78 78
     $this->view->page(['data' => compact('bread')]);
79
-  }
79
+    }
80 80
 
81
-  public function autoCompleteAction() {
81
+    public function autoCompleteAction() {
82 82
     $return = Cache::get('itemsAutocomplete');
83 83
     if (!$return) {
84
-      $items = $this->ecommerce->getItems();
85
-      $return = [];
86
-      foreach ($items as $item) {
84
+        $items = $this->ecommerce->getItems();
85
+        $return = [];
86
+        foreach ($items as $item) {
87 87
         $return[] = ['name' => $item->name(), 'search' => $item->search_index . ' ' . $item->name];
88
-      }
89
-      $return = json_encode($return);
90
-      Cache::set('itemsAutocomplete', [], $return);
88
+        }
89
+        $return = json_encode($return);
90
+        Cache::set('itemsAutocomplete', [], $return);
91 91
     }
92 92
     echo $return;
93
-  }
93
+    }
94 94
 
95
-  public function indexAction() {
95
+    public function indexAction() {
96 96
     if (empty($this->module->config['catalogPresentPage'])) {
97
-      Tools::redirect('/ecommerce/itemList');
97
+        Tools::redirect('/ecommerce/itemList');
98 98
     }
99 99
     //$this->view->setTitle('Каталог');
100 100
     $this->view->page();
101
-  }
101
+    }
102 102
 
103
-  public function itemListAction($category_id = 0) {
103
+    public function itemListAction($category_id = 0) {
104 104
     //search
105 105
     if (!empty($_GET['search'])) {
106
-      if (!empty($_GET['inCatalog'])) {
106
+        if (!empty($_GET['inCatalog'])) {
107 107
         $category_id = (int) $_GET['inCatalog'];
108
-      }
109
-      $search = $_GET['search'];
108
+        }
109
+        $search = $_GET['search'];
110 110
     } else {
111
-      $search = '';
111
+        $search = '';
112 112
     }
113 113
 
114 114
     //sort
115 115
     if (!empty($_GET['sort'])) {
116
-      $sort = $_GET['sort'];
116
+        $sort = $_GET['sort'];
117 117
     } elseif (!empty($this->ecommerce->config['defaultSort'])) {
118
-      $sort = $this->ecommerce->config['defaultSort'];
118
+        $sort = $this->ecommerce->config['defaultSort'];
119 119
     } else {
120
-      $sort = ['name' => 'asc'];
120
+        $sort = ['name' => 'asc'];
121 121
     }
122 122
 
123 123
     //category
124 124
     $category = null;
125 125
     if ($category_id) {
126
-      if (is_numeric($category_id)) {
126
+        if (is_numeric($category_id)) {
127 127
         $category = \Ecommerce\Category::get($category_id);
128
-      }
129
-      if (!$category) {
128
+        }
129
+        if (!$category) {
130 130
         $category = \Ecommerce\Category::get($category_id, 'alias');
131
-      }
132
-      if ($category) {
131
+        }
132
+        if ($category) {
133 133
         $category_id = $category->id;
134
-      } else {
134
+        } else {
135 135
         $category_id = 0;
136
-      }
136
+        }
137 137
     } else {
138
-      $category_id = 0;
138
+        $category_id = 0;
139 139
     }
140 140
     $active = $category_id;
141 141
 
@@ -151,17 +151,17 @@  discard block
 block discarded – undo
151 151
     //bread
152 152
     $bread = [];
153 153
     if (!$category || !$category->name) {
154
-      $bread[] = array('text' => 'Каталог');
155
-      $this->view->setTitle('Каталог');
154
+        $bread[] = array('text' => 'Каталог');
155
+        $this->view->setTitle('Каталог');
156 156
     } else {
157
-      $bread[] = array('text' => 'Каталог', 'href' => '/ecommerce');
158
-      $categoryIds = array_values(array_filter(explode('/', $category->tree_path)));
159
-      foreach ($categoryIds as $id) {
157
+        $bread[] = array('text' => 'Каталог', 'href' => '/ecommerce');
158
+        $categoryIds = array_values(array_filter(explode('/', $category->tree_path)));
159
+        foreach ($categoryIds as $id) {
160 160
         $cat = Ecommerce\Category::get($id);
161 161
         $bread[] = array('text' => $cat->name, 'href' => '/ecommerce/itemList/' . $cat->id);
162
-      }
163
-      $bread[] = array('text' => $category->name);
164
-      $this->view->setTitle($category->name);
162
+        }
163
+        $bread[] = array('text' => $category->name);
164
+        $this->view->setTitle($category->name);
165 165
     }
166 166
 
167 167
     //items
@@ -176,30 +176,30 @@  discard block
 block discarded – undo
176 176
 
177 177
     //params 
178 178
     if (empty(App::$cur->ecommerce->config['filtersInLast'])) {
179
-      $options = \Ecommerce\Item\Option::getList(['where' => ['item_option_searchable', 1]]);
179
+        $options = \Ecommerce\Item\Option::getList(['where' => ['item_option_searchable', 1]]);
180 180
     } else {
181
-      $params = $this->ecommerce->getItemsParams([
182
-          'parent' => $category_id,
183
-          'search' => trim($search),
184
-          'filters' => !empty($_GET['filters']) ? $_GET['filters'] : []
185
-      ]);
186
-      $ids = [];
187
-      foreach ($params as $param) {
181
+        $params = $this->ecommerce->getItemsParams([
182
+            'parent' => $category_id,
183
+            'search' => trim($search),
184
+            'filters' => !empty($_GET['filters']) ? $_GET['filters'] : []
185
+        ]);
186
+        $ids = [];
187
+        foreach ($params as $param) {
188 188
         $ids[] = $param->item_option_id;
189
-      }
190
-      if ($ids) {
189
+        }
190
+        if ($ids) {
191 191
         $options = \Ecommerce\Item\Option::getList(['where' => ['id', $ids, 'IN']]);
192
-      } else {
192
+        } else {
193 193
         $options = [];
194
-      }
194
+        }
195 195
     }
196 196
 
197 197
 
198 198
     //child categorys
199 199
     if ($category) {
200
-      $categorys = $category->catalogs;
200
+        $categorys = $category->catalogs;
201 201
     } else {
202
-      $categorys = \Ecommerce\Category::getList(['where' => ['parent_id', 0]]);
202
+        $categorys = \Ecommerce\Category::getList(['where' => ['parent_id', 0]]);
203 203
     }
204 204
 
205 205
     //view content
@@ -207,12 +207,12 @@  discard block
 block discarded – undo
207 207
         'page' => $category ? $category->resolveTemplate() : (!empty(App::$cur->ecommerce->config['defaultCategoryTemplate']) ? App::$cur->ecommerce->config['defaultCategoryTemplate'] : 'current'),
208 208
         'content' => $category ? $category->resolveViewer() : (!empty(App::$cur->ecommerce->config['defaultCategoryView']) ? App::$cur->ecommerce->config['defaultCategoryView'] : 'itemList'),
209 209
         'data' => compact('active', 'category', 'sort', 'search', 'pages', 'items', 'categorys', 'bread', 'options')]);
210
-  }
210
+    }
211 211
 
212
-  public function viewAction($id = '') {
212
+    public function viewAction($id = '') {
213 213
     $item = \Ecommerce\Item::get((int) $id);
214 214
     if (!$item) {
215
-      Tools::redirect('/ecommerce/', 'Такой товар не найден');
215
+        Tools::redirect('/ecommerce/', 'Такой товар не найден');
216 216
     }
217 217
     $active = $item->category_id;
218 218
     $catalog = $item->category;
@@ -221,10 +221,10 @@  discard block
 block discarded – undo
221 221
 
222 222
     $catalogIds = array_values(array_filter(explode('/', $item->tree_path)));
223 223
     foreach ($catalogIds as $id) {
224
-      $cat = Ecommerce\Category::get($id);
225
-      if ($cat) {
224
+        $cat = Ecommerce\Category::get($id);
225
+        if ($cat) {
226 226
         $bread[] = ['text' => $cat->name, 'href' => '/ecommerce/itemList/' . $cat->id];
227
-      }
227
+        }
228 228
     }
229 229
     $bread[] = ['text' => $item->name()];
230 230
     $this->view->setTitle($item->name());
@@ -233,17 +233,17 @@  discard block
 block discarded – undo
233 233
         'content' => $item->view ? $item->view : 'view'
234 234
     ];
235 235
     if (isset($_GET['quickview'])) {
236
-      $options['page'] = 'blank';
236
+        $options['page'] = 'blank';
237 237
     }
238 238
 
239 239
     $this->view->addMetaTag(['property' => 'og:title', 'content' => $item->name]);
240 240
     $this->view->addMetaTag(['property' => 'og:description', 'content' => $item->description]);
241 241
     if ($item->image) {
242
-      $this->view->addMetaTag(['property' => 'og:image', 'content' => 'http://' . INJI_DOMAIN_NAME . $item->image->path]);
242
+        $this->view->addMetaTag(['property' => 'og:image', 'content' => 'http://' . INJI_DOMAIN_NAME . $item->image->path]);
243 243
     }
244 244
     $this->view->addMetaTag(['property' => 'og:url', 'content' => 'http://' . INJI_DOMAIN_NAME . '/view/' . $item->id]);
245 245
 
246 246
     $this->view->page($options);
247
-  }
247
+    }
248 248
 
249 249
 }
Please login to merge, or discard this patch.
system/modules/Ecommerce/models/Category.php 1 patch
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -13,50 +13,50 @@  discard block
 block discarded – undo
13 13
 
14 14
 class Category extends \Model {
15 15
 
16
-  public static $objectName = 'Категория магазина';
17
-  public static $treeCategory = 'Ecommerce\Item';
18
-  public static $cols = [
19
-      //Основные параметры
20
-      'parent_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'parent'],
21
-      'name' => ['type' => 'text'],
22
-      'alias' => ['type' => 'text'],
23
-      'viewer' => ['type' => 'select', 'source' => 'method', 'method' => 'viewsCategoryList', 'module' => 'Ecommerce'],
24
-      'template' => ['type' => 'select', 'source' => 'method', 'method' => 'templatesCategoryList', 'module' => 'Ecommerce'],
25
-      'description' => ['type' => 'html'],
26
-      'image_file_id' => ['type' => 'image'],
27
-      'options_inherit' => ['type' => 'bool'],
28
-      //Системные
29
-      'imported' => ['type' => 'bool'],
30
-      'weight' => ['type' => 'number'],
31
-      'user_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'user'],
32
-      'tree_path' => ['type' => 'text'],
33
-      'date_create' => ['type' => 'dateTime'],
34
-      //Менеджеры
35
-      'options' => ['type' => 'dataManager', 'relation' => 'options'],
36
-  ];
37
-  public static $labels = [
38
-      'name' => 'Название',
39
-      'alias' => 'Алиас',
40
-      'parent_id' => 'Родительская категория',
41
-      'image_file_id' => 'Изображение',
42
-      'description' => 'Описание',
43
-      'options_inherit' => 'Наследовать набор свойств',
44
-      'options' => 'Свойства товаров',
45
-  ];
46
-  public static $forms = [
47
-      'manager' => [
48
-          'map' => [
49
-              ['name', 'alias'],
50
-              ['parent_id', 'image_file_id'],
51
-              ['viewer', 'template'],
52
-              ['options_inherit'],
53
-              ['options'],
54
-              ['description']
55
-          ]
56
-      ]
57
-  ];
16
+    public static $objectName = 'Категория магазина';
17
+    public static $treeCategory = 'Ecommerce\Item';
18
+    public static $cols = [
19
+        //Основные параметры
20
+        'parent_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'parent'],
21
+        'name' => ['type' => 'text'],
22
+        'alias' => ['type' => 'text'],
23
+        'viewer' => ['type' => 'select', 'source' => 'method', 'method' => 'viewsCategoryList', 'module' => 'Ecommerce'],
24
+        'template' => ['type' => 'select', 'source' => 'method', 'method' => 'templatesCategoryList', 'module' => 'Ecommerce'],
25
+        'description' => ['type' => 'html'],
26
+        'image_file_id' => ['type' => 'image'],
27
+        'options_inherit' => ['type' => 'bool'],
28
+        //Системные
29
+        'imported' => ['type' => 'bool'],
30
+        'weight' => ['type' => 'number'],
31
+        'user_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'user'],
32
+        'tree_path' => ['type' => 'text'],
33
+        'date_create' => ['type' => 'dateTime'],
34
+        //Менеджеры
35
+        'options' => ['type' => 'dataManager', 'relation' => 'options'],
36
+    ];
37
+    public static $labels = [
38
+        'name' => 'Название',
39
+        'alias' => 'Алиас',
40
+        'parent_id' => 'Родительская категория',
41
+        'image_file_id' => 'Изображение',
42
+        'description' => 'Описание',
43
+        'options_inherit' => 'Наследовать набор свойств',
44
+        'options' => 'Свойства товаров',
45
+    ];
46
+    public static $forms = [
47
+        'manager' => [
48
+            'map' => [
49
+                ['name', 'alias'],
50
+                ['parent_id', 'image_file_id'],
51
+                ['viewer', 'template'],
52
+                ['options_inherit'],
53
+                ['options'],
54
+                ['description']
55
+            ]
56
+        ]
57
+    ];
58 58
 
59
-  public static function indexes() {
59
+    public static function indexes() {
60 60
     return [
61 61
         'ecommerce_category_category_parent_id' => [
62 62
             'type' => 'INDEX',
@@ -71,9 +71,9 @@  discard block
 block discarded – undo
71 71
             ]
72 72
         ],
73 73
     ];
74
-  }
74
+    }
75 75
 
76
-  public static function relations() {
76
+    public static function relations() {
77 77
     return [
78 78
         'items' => [
79 79
             'type' => 'many',
@@ -103,50 +103,50 @@  discard block
 block discarded – undo
103 103
             'col' => 'parent_id',
104 104
         ]
105 105
     ];
106
-  }
106
+    }
107 107
 
108
-  public static $dataManagers = [
109
-      'manager' => [
110
-          'name' => 'Категории товаров',
111
-          'cols' => [
112
-              'name',
113
-              'parent_id',
114
-          ],
115
-          'sortMode' => true
116
-      ]
117
-  ];
108
+    public static $dataManagers = [
109
+        'manager' => [
110
+            'name' => 'Категории товаров',
111
+            'cols' => [
112
+                'name',
113
+                'parent_id',
114
+            ],
115
+            'sortMode' => true
116
+        ]
117
+    ];
118 118
 
119
-  public function beforeSave() {
119
+    public function beforeSave() {
120 120
     if ($this->id && $this->id == $this->parent_id) {
121
-      $this->parent_id = 0;
122
-      \Msg::add('Категория не может быть сама себе родителем');
121
+        $this->parent_id = 0;
122
+        \Msg::add('Категория не может быть сама себе родителем');
123
+    }
123 124
     }
124
-  }
125 125
 
126
-  public function beforeDelete() {
126
+    public function beforeDelete() {
127 127
     foreach ($this->catalogs as $category) {
128
-      $category->delete();
128
+        $category->delete();
129
+    }
129 130
     }
130
-  }
131 131
 
132
-  public function resolveTemplate() {
132
+    public function resolveTemplate() {
133 133
     if ($this->template !== 'inherit') {
134
-      return $this->template;
134
+        return $this->template;
135 135
     } elseif ($this->template == 'inherit' && $this->category) {
136
-      return $this->category->resolveTemplate(true);
136
+        return $this->category->resolveTemplate(true);
137 137
     } else {
138
-      return (!empty(\App::$cur->ecommerce->config['defaultCategoryTemplate']) ? \App::$cur->ecommerce->config['defaultCategoryTemplate'] : 'current');
138
+        return (!empty(\App::$cur->ecommerce->config['defaultCategoryTemplate']) ? \App::$cur->ecommerce->config['defaultCategoryTemplate'] : 'current');
139
+    }
139 140
     }
140
-  }
141 141
 
142
-  public function resolveViewer() {
142
+    public function resolveViewer() {
143 143
     if ($this->viewer !== 'inherit') {
144
-      return $this->viewer;
144
+        return $this->viewer;
145 145
     } elseif ($this->viewer == 'inherit' && $this->category) {
146
-      return $this->category->resolveViewer(true);
146
+        return $this->category->resolveViewer(true);
147 147
     } else {
148
-      return (!empty(\App::$cur->ecommerce->config['defaultCategoryView']) ? \App::$cur->ecommerce->config['defaultCategoryView'] : 'itemList');
148
+        return (!empty(\App::$cur->ecommerce->config['defaultCategoryView']) ? \App::$cur->ecommerce->config['defaultCategoryView'] : 'itemList');
149
+    }
149 150
     }
150
-  }
151 151
 
152 152
 }
Please login to merge, or discard this patch.
system/modules/Ecommerce/Ecommerce.php 1 patch
Indentation   +238 added lines, -238 removed lines patch added patch discarded remove patch
@@ -10,172 +10,172 @@  discard block
 block discarded – undo
10 10
  */
11 11
 class Ecommerce extends Module {
12 12
 
13
-  public function init() {
13
+    public function init() {
14 14
     App::$primary->view->customAsset('js', '/moduleAsset/Ecommerce/js/cart.js');
15
-  }
15
+    }
16 16
 
17
-  public function getPayTypeHandlers($forSelect = false) {
17
+    public function getPayTypeHandlers($forSelect = false) {
18 18
     if (!$forSelect) {
19
-      return $this->getSnippets('payTypeHandler');
19
+        return $this->getSnippets('payTypeHandler');
20 20
     }
21 21
     $handlers = ['' => 'Не выбрано'];
22 22
     foreach ($this->getSnippets('payTypeHandler') as $key => $handler) {
23
-      if (empty($handler)) {
23
+        if (empty($handler)) {
24 24
         continue;
25
-      }
26
-      $handlers[$key] = $handler['name'];
25
+        }
26
+        $handlers[$key] = $handler['name'];
27 27
     }
28 28
     return $handlers;
29
-  }
29
+    }
30 30
 
31
-  public function cartPayRecive($data) {
31
+    public function cartPayRecive($data) {
32 32
     $cart = Ecommerce\Cart::get($data['pay']->data);
33 33
     if ($cart) {
34
-      $payed = true;
35
-      foreach ($cart->pays as $pay) {
34
+        $payed = true;
35
+        foreach ($cart->pays as $pay) {
36 36
         if ($pay->pay_status_id != 2) {
37
-          $payed = false;
38
-          break;
37
+            $payed = false;
38
+            break;
39 39
         }
40
-      }
41
-      $cart->payed = $payed;
42
-      $cart->save();
40
+        }
41
+        $cart->payed = $payed;
42
+        $cart->save();
43
+    }
43 44
     }
44
-  }
45 45
 
46
-  public function parseFields($data, $cart) {
46
+    public function parseFields($data, $cart) {
47 47
     $fields = \Ecommerce\UserAdds\Field::getList();
48 48
     $name = '';
49 49
     foreach ($fields as $field) {
50
-      if ($field->save && !empty($data[$field->id])) {
50
+        if ($field->save && !empty($data[$field->id])) {
51 51
         $name .= htmlspecialchars($data[$field->id]) . ' ';
52
-      }
52
+        }
53 53
     }
54 54
     $name = trim($name);
55 55
 
56 56
     $userAdds = Ecommerce\UserAdds::get([['user_id', $cart->user->id], ['name', $name]]);
57 57
     if (!$userAdds) {
58
-      $userAdds = new Ecommerce\UserAdds();
59
-      $userAdds->user_id = $cart->user->id;
60
-      $userAdds->name = $name;
61
-      $userAdds->save();
62
-      foreach ($fields as $field) {
58
+        $userAdds = new Ecommerce\UserAdds();
59
+        $userAdds->user_id = $cart->user->id;
60
+        $userAdds->name = $name;
61
+        $userAdds->save();
62
+        foreach ($fields as $field) {
63 63
         if (!$field->save) {
64
-          continue;
64
+            continue;
65 65
         }
66 66
         $userAddsValue = new Ecommerce\UserAdds\Value();
67 67
         $userAddsValue->value = htmlspecialchars($data[$field->id]);
68 68
         $userAddsValue->useradds_field_id = $field->id;
69 69
         $userAddsValue->useradds_id = $userAdds->id;
70 70
         $userAddsValue->save();
71
-      }
71
+        }
72 72
     }
73 73
     $user = \Users\User::get($cart->user_id);
74 74
     foreach ($fields as $field) {
75
-      $info = new \Ecommerce\Cart\Info();
76
-      $info->name = $field->name;
77
-      $info->value = htmlspecialchars($data[$field->id]);
78
-      $info->useradds_field_id = $field->id;
79
-      $info->cart_id = $cart->id;
80
-      $info->save();
81
-      $relations = [];
82
-      if ($field->userfield) {
75
+        $info = new \Ecommerce\Cart\Info();
76
+        $info->name = $field->name;
77
+        $info->value = htmlspecialchars($data[$field->id]);
78
+        $info->useradds_field_id = $field->id;
79
+        $info->cart_id = $cart->id;
80
+        $info->save();
81
+        $relations = [];
82
+        if ($field->userfield) {
83 83
         if (strpos($field->userfield, ':')) {
84
-          $path = explode(':', $field->userfield);
85
-          if (!$user->{$path[0]}->{$path[1]}) {
84
+            $path = explode(':', $field->userfield);
85
+            if (!$user->{$path[0]}->{$path[1]}) {
86 86
             $user->{$path[0]}->{$path[1]} = $info->value;
87 87
             $relations[$path[0]] = $path[0];
88
-          }
88
+            }
89 89
         } else {
90
-          if (!$user->{$field->userfield}) {
90
+            if (!$user->{$field->userfield}) {
91 91
             $user->{$field->userfield} = $info->value;
92
-          }
92
+            }
93 93
         }
94
-      }
95
-      foreach ($relations as $rel) {
94
+        }
95
+        foreach ($relations as $rel) {
96 96
         $user->$rel->save();
97
-      }
98
-      $user->save();
97
+        }
98
+        $user->save();
99 99
     }
100 100
     return $userAdds;
101
-  }
101
+    }
102 102
 
103
-  public function parseDeliveryFields($data, $cart, $fields) {
103
+    public function parseDeliveryFields($data, $cart, $fields) {
104 104
     $name = '';
105 105
     foreach ($fields as $field) {
106
-      if ($field->save && !empty($data[$field->id])) {
106
+        if ($field->save && !empty($data[$field->id])) {
107 107
         $name .= htmlspecialchars($data[$field->id]) . ' ';
108
-      }
108
+        }
109 109
     }
110 110
     $name = trim($name);
111 111
 
112 112
     $save = Ecommerce\Delivery\Save::get([['user_id', $cart->user->id], ['name', $name]]);
113 113
     if (!$save) {
114
-      $save = new Ecommerce\Delivery\Save();
115
-      $save->user_id = $cart->user->id;
116
-      $save->name = $name;
117
-      $save->save();
118
-      foreach ($fields as $field) {
114
+        $save = new Ecommerce\Delivery\Save();
115
+        $save->user_id = $cart->user->id;
116
+        $save->name = $name;
117
+        $save->save();
118
+        foreach ($fields as $field) {
119 119
         if (!$field->save) {
120
-          continue;
120
+            continue;
121 121
         }
122 122
         $saveValue = new Ecommerce\Delivery\Value();
123 123
         $saveValue->value = htmlspecialchars($data[$field->id]);
124 124
         $saveValue->delivery_field_id = $field->id;
125 125
         $saveValue->delivery_save_id = $save->id;
126 126
         $saveValue->save();
127
-      }
127
+        }
128 128
     }
129 129
     $user = \Users\User::get($cart->user_id);
130 130
     foreach ($fields as $field) {
131
-      $info = new \Ecommerce\Cart\DeliveryInfo();
132
-      $info->name = $field->name;
133
-      $info->value = htmlspecialchars($data[$field->id]);
134
-      $info->delivery_field_id = $field->id;
135
-      $info->cart_id = $cart->id;
136
-      $info->save();
137
-      $relations = [];
138
-      if ($field->userfield) {
131
+        $info = new \Ecommerce\Cart\DeliveryInfo();
132
+        $info->name = $field->name;
133
+        $info->value = htmlspecialchars($data[$field->id]);
134
+        $info->delivery_field_id = $field->id;
135
+        $info->cart_id = $cart->id;
136
+        $info->save();
137
+        $relations = [];
138
+        if ($field->userfield) {
139 139
         if (strpos($field->userfield, ':')) {
140
-          $path = explode(':', $field->userfield);
141
-          if (!$user->{$path[0]}->{$path[1]}) {
140
+            $path = explode(':', $field->userfield);
141
+            if (!$user->{$path[0]}->{$path[1]}) {
142 142
             $user->{$path[0]}->{$path[1]} = $info->value;
143 143
             $relations[$path[0]] = $path[0];
144
-          }
144
+            }
145 145
         } else {
146
-          if (!$user->{$field->userfield}) {
146
+            if (!$user->{$field->userfield}) {
147 147
             $user->{$field->userfield} = $info->value;
148
-          }
148
+            }
149 149
         }
150
-      }
151
-      foreach ($relations as $rel) {
150
+        }
151
+        foreach ($relations as $rel) {
152 152
         $user->$rel->save();
153
-      }
154
-      $user->save();
153
+        }
154
+        $user->save();
155 155
     }
156 156
     return $save;
157
-  }
157
+    }
158 158
 
159
-  public function getCurCart($create = true) {
159
+    public function getCurCart($create = true) {
160 160
     $cart = false;
161 161
     if (!empty($_SESSION['cart']['cart_id'])) {
162
-      $cart = Ecommerce\Cart::get((int) $_SESSION['cart']['cart_id']);
162
+        $cart = Ecommerce\Cart::get((int) $_SESSION['cart']['cart_id']);
163 163
     }
164 164
     if (!$cart && $create) {
165
-      $cart = new Ecommerce\Cart();
166
-      $cart->cart_status_id = 1;
167
-      $cart->user_id = Users\User::$cur->id;
168
-      $userCard = \Ecommerce\Card\Item::get(\Users\User::$cur->id, 'user_id');
169
-      if ($userCard) {
165
+        $cart = new Ecommerce\Cart();
166
+        $cart->cart_status_id = 1;
167
+        $cart->user_id = Users\User::$cur->id;
168
+        $userCard = \Ecommerce\Card\Item::get(\Users\User::$cur->id, 'user_id');
169
+        if ($userCard) {
170 170
         $cart->card_item_id = $userCard->id;
171
-      }
172
-      $cart->save();
173
-      $_SESSION['cart']['cart_id'] = $cart->id;
171
+        }
172
+        $cart->save();
173
+        $_SESSION['cart']['cart_id'] = $cart->id;
174 174
     }
175 175
     return $cart;
176
-  }
176
+    }
177 177
 
178
-  public function parseOptions($options = []) {
178
+    public function parseOptions($options = []) {
179 179
     $selectOptions = [
180 180
         'where' => !empty($options['where']) ? $options['where'] : [],
181 181
         'distinct' => false,
@@ -186,29 +186,29 @@  discard block
 block discarded – undo
186 186
         'limit' => !empty($options['count']) ? (int) $options['count'] : 0,
187 187
     ];
188 188
     if (!empty($options['sort']) && is_array($options['sort'])) {
189
-      foreach ($options['sort'] as $col => $direction) {
189
+        foreach ($options['sort'] as $col => $direction) {
190 190
         switch ($col) {
191
-          case 'price':
191
+            case 'price':
192 192
             $selectOptions['order'][] = [Ecommerce\Item\Offer\Price::colPrefix() . 'price', strtolower($direction) == 'desc' ? 'desc' : 'asc'];
193 193
             break;
194
-          case 'name':
194
+            case 'name':
195 195
             $selectOptions['order'][] = ['name', strtolower($direction) == 'desc' ? 'desc' : 'asc'];
196 196
             break;
197
-          case 'sales':
197
+            case 'sales':
198 198
             $selectOptions['order'][] = ['sales', strtolower($direction) == 'desc' ? 'desc' : 'asc'];
199 199
             break;
200
-          case 'weight':
200
+            case 'weight':
201 201
             $selectOptions['order'][] = ['weight', strtolower($direction) == 'desc' ? 'desc' : 'asc'];
202 202
             break;
203
-          case 'new':
203
+            case 'new':
204 204
             $selectOptions['order'][] = ['date_create', strtolower($direction) == 'desc' ? 'desc' : 'asc'];
205 205
             break;
206 206
         }
207
-      }
207
+        }
208 208
     }
209 209
     $selectOptions['where'][] = ['deleted', 0];
210 210
     if (empty($this->config['view_empty_image'])) {
211
-      $selectOptions['where'][] = ['image_file_id', 0, '!='];
211
+        $selectOptions['where'][] = ['image_file_id', 0, '!='];
212 212
     }
213 213
 
214 214
     $selectOptions['join'][] = [Ecommerce\Item\Offer::table(), Ecommerce\Item::index() . ' = ' . Ecommerce\Item\Offer::colPrefix() . Ecommerce\Item::index(), 'inner'];
@@ -232,111 +232,111 @@  discard block
 block discarded – undo
232 232
 
233 233
 
234 234
     if (!empty($this->config['view_filter'])) {
235
-      if (!empty($this->config['view_filter']['options'])) {
235
+        if (!empty($this->config['view_filter']['options'])) {
236 236
         foreach ($this->config['view_filter']['options'] as $optionId => $optionValue) {
237
-          $selectOptions['join'][] = [Ecommerce\Item\Param::table(), Ecommerce\Item::index() . ' = ' . 'option' . $optionId . '.' . Ecommerce\Item\Param::colPrefix() . Ecommerce\Item::index() . ' AND ' .
238
-              'option' . $optionId . '.' . Ecommerce\Item\Param::colPrefix() . Ecommerce\Item\Option::index() . ' = "' . (int) $optionId . '" AND ' .
239
-              'option' . $optionId . '.' . Ecommerce\Item\Param::colPrefix() . 'value = "' . (int) $optionValue . '"',
240
-              'inner', 'option' . $optionId];
237
+            $selectOptions['join'][] = [Ecommerce\Item\Param::table(), Ecommerce\Item::index() . ' = ' . 'option' . $optionId . '.' . Ecommerce\Item\Param::colPrefix() . Ecommerce\Item::index() . ' AND ' .
238
+                'option' . $optionId . '.' . Ecommerce\Item\Param::colPrefix() . Ecommerce\Item\Option::index() . ' = "' . (int) $optionId . '" AND ' .
239
+                'option' . $optionId . '.' . Ecommerce\Item\Param::colPrefix() . 'value = "' . (int) $optionValue . '"',
240
+                'inner', 'option' . $optionId];
241
+        }
241 242
         }
242
-      }
243 243
     }
244 244
     //filters
245 245
     if (!empty($options['filters'])) {
246
-      foreach ($options['filters'] as $col => $filter) {
246
+        foreach ($options['filters'] as $col => $filter) {
247 247
         switch ($col) {
248
-          case 'price':
248
+            case 'price':
249 249
             if (!empty($filter['min'])) {
250
-              $selectOptions['where'][] = [Ecommerce\Item\Offer\Price::colPrefix() . 'price', (float) $filter['min'], '>='];
250
+                $selectOptions['where'][] = [Ecommerce\Item\Offer\Price::colPrefix() . 'price', (float) $filter['min'], '>='];
251 251
             }
252 252
             if (!empty($filter['max'])) {
253
-              $selectOptions['where'][] = [Ecommerce\Item\Offer\Price::colPrefix() . 'price', (float) $filter['max'], '<='];
253
+                $selectOptions['where'][] = [Ecommerce\Item\Offer\Price::colPrefix() . 'price', (float) $filter['max'], '<='];
254 254
             }
255 255
             break;
256
-          case 'options':
256
+            case 'options':
257 257
             foreach ($filter as $optionId => $optionValue) {
258
-              $optionId = (int) $optionId;
259
-              if (is_array($optionValue)) {
258
+                $optionId = (int) $optionId;
259
+                if (is_array($optionValue)) {
260 260
                 $optionValueArr = [];
261 261
                 foreach ($optionValue as $val) {
262
-                  $optionValueArr[] = \App::$cur->db->connection->pdo->quote($val);
262
+                    $optionValueArr[] = \App::$cur->db->connection->pdo->quote($val);
263 263
                 }
264 264
                 $qstr = 'IN (' . implode(',', $optionValueArr) . ')';
265
-              } else {
265
+                } else {
266 266
                 $qstr = '= ' . \App::$cur->db->connection->pdo->quote($optionValue);
267
-              }
268
-              $selectOptions['join'][] = [Ecommerce\Item\Param::table(), Ecommerce\Item::index() . ' = ' . 'option' . $optionId . '.' . Ecommerce\Item\Param::colPrefix() . Ecommerce\Item::index() . ' AND ' .
269
-                  'option' . $optionId . '.' . Ecommerce\Item\Param::colPrefix() . Ecommerce\Item\Option::index() . ' = "' . (int) $optionId . '" AND ' .
270
-                  'option' . $optionId . '.' . Ecommerce\Item\Param::colPrefix() . 'value ' . $qstr . '',
271
-                  'inner', 'option' . $optionId];
267
+                }
268
+                $selectOptions['join'][] = [Ecommerce\Item\Param::table(), Ecommerce\Item::index() . ' = ' . 'option' . $optionId . '.' . Ecommerce\Item\Param::colPrefix() . Ecommerce\Item::index() . ' AND ' .
269
+                    'option' . $optionId . '.' . Ecommerce\Item\Param::colPrefix() . Ecommerce\Item\Option::index() . ' = "' . (int) $optionId . '" AND ' .
270
+                    'option' . $optionId . '.' . Ecommerce\Item\Param::colPrefix() . 'value ' . $qstr . '',
271
+                    'inner', 'option' . $optionId];
272 272
             }
273 273
             break;
274
-          case 'offerOptions':
274
+            case 'offerOptions':
275 275
             //$selectOptions['join'][] = [Ecommerce\Item\Offer::table(), Ecommerce\Item::index() . ' = offer.' . Ecommerce\Item\Offer::colPrefix() . Ecommerce\Item::index(), 'left', 'offer'];
276 276
             foreach ($filter as $optionId => $optionValue) {
277
-              $optionId = (int) $optionId;
278
-              if (is_array($optionValue)) {
277
+                $optionId = (int) $optionId;
278
+                if (is_array($optionValue)) {
279 279
                 $optionValueArr = [];
280 280
                 foreach ($optionValue as $val) {
281
-                  $optionValueArr[] = \App::$cur->db->connection->pdo->quote($val);
281
+                    $optionValueArr[] = \App::$cur->db->connection->pdo->quote($val);
282 282
                 }
283 283
                 $qstr = 'IN (' . implode(',', $optionValueArr) . ')';
284
-              } else {
284
+                } else {
285 285
                 $qstr = '= ' . \App::$cur->db->connection->pdo->quote($optionValue);
286
-              }
287
-              $selectOptions['join'][] = [Ecommerce\Item\Offer\Param::table(), Ecommerce\Item\Offer::index() . ' = ' . 'offerOption' . $optionId . '.' . Ecommerce\Item\Offer\Param::colPrefix() . Ecommerce\Item\Offer::index() . ' AND ' .
288
-                  'offerOption' . $optionId . '.' . Ecommerce\Item\Offer\Param::colPrefix() . Ecommerce\Item\Offer\Option::index() . ' = "' . (int) $optionId . '" AND ' .
289
-                  'offerOption' . $optionId . '.' . Ecommerce\Item\Offer\Param::colPrefix() . 'value ' . $qstr,
290
-                  'inner', 'offerOption' . $optionId];
286
+                }
287
+                $selectOptions['join'][] = [Ecommerce\Item\Offer\Param::table(), Ecommerce\Item\Offer::index() . ' = ' . 'offerOption' . $optionId . '.' . Ecommerce\Item\Offer\Param::colPrefix() . Ecommerce\Item\Offer::index() . ' AND ' .
288
+                    'offerOption' . $optionId . '.' . Ecommerce\Item\Offer\Param::colPrefix() . Ecommerce\Item\Offer\Option::index() . ' = "' . (int) $optionId . '" AND ' .
289
+                    'offerOption' . $optionId . '.' . Ecommerce\Item\Offer\Param::colPrefix() . 'value ' . $qstr,
290
+                    'inner', 'offerOption' . $optionId];
291 291
             }
292 292
             break;
293 293
         }
294
-      }
294
+        }
295 295
     }
296 296
     //parents
297 297
     if (!empty($options['parent']) && strpos($options['parent'], ',') !== false) {
298
-      $first = true;
299
-      $where = [];
300
-      foreach (explode(',', $options['parent']) as $categoryId) {
298
+        $first = true;
299
+        $where = [];
300
+        foreach (explode(',', $options['parent']) as $categoryId) {
301 301
         if (!$categoryId) {
302
-          continue;
302
+            continue;
303 303
         }
304 304
         $category = \Ecommerce\Category::get($categoryId);
305 305
         $where[] = ['tree_path', $category->tree_path . (int) $categoryId . '/%', 'LIKE', $first ? 'AND' : 'OR'];
306 306
         $first = false;
307
-      }
308
-      $selectOptions['where'][] = $where;
307
+        }
308
+        $selectOptions['where'][] = $where;
309 309
     } elseif (!empty($options['parent'])) {
310
-      $category = \Ecommerce\Category::get($options['parent']);
311
-      $selectOptions['where'][] = ['tree_path', $category->tree_path . (int) $options['parent'] . '/%', 'LIKE'];
310
+        $category = \Ecommerce\Category::get($options['parent']);
311
+        $selectOptions['where'][] = ['tree_path', $category->tree_path . (int) $options['parent'] . '/%', 'LIKE'];
312 312
     }
313 313
 
314 314
     //search
315 315
     if (!empty($options['search'])) {
316
-      $searchStr = preg_replace('![^A-zА-я0-9 ]!iSu', ' ', $options['search']);
317
-      $searchArr = [];
318
-      foreach (explode(' ', $searchStr) as $part) {
316
+        $searchStr = preg_replace('![^A-zА-я0-9 ]!iSu', ' ', $options['search']);
317
+        $searchArr = [];
318
+        foreach (explode(' ', $searchStr) as $part) {
319 319
         $part = trim($part);
320 320
         if ($part && strlen($part) > 2) {
321
-          $searchArr[] = ['search_index', '%' . $part . '%', 'LIKE'];
321
+            $searchArr[] = ['search_index', '%' . $part . '%', 'LIKE'];
322
+        }
322 323
         }
323
-      }
324
-      if (!empty($searchArr)) {
324
+        if (!empty($searchArr)) {
325 325
         $selectOptions['where'][] = $searchArr;
326
-      }
326
+        }
327 327
     }
328 328
     if (empty($this->config['view_empty_warehouse'])) {
329
-      $warehouseIds = [];
330
-      if (App::$cur->geography && \Geography\City::$cur) {
329
+        $warehouseIds = [];
330
+        if (App::$cur->geography && \Geography\City::$cur) {
331 331
         $warehouses = \Geography\City\Data::get([['code', 'warehouses'], ['city_id', \Geography\City::$cur->id]]);
332 332
         if ($warehouses && $warehouses->data) {
333
-          foreach (explode(',', $warehouses->data) as $id) {
333
+            foreach (explode(',', $warehouses->data) as $id) {
334 334
             $warehouseIds[$id] = $id;
335
-          }
335
+            }
336
+        }
336 337
         }
337
-      }
338
-      $selectOptions['where'][] = [
339
-          '(
338
+        $selectOptions['where'][] = [
339
+            '(
340 340
           (SELECT COALESCE(sum(`' . \Ecommerce\Item\Offer\Warehouse::colPrefix() . 'count`),0) 
341 341
             FROM ' . \App::$cur->db->table_prefix . \Ecommerce\Item\Offer\Warehouse::table() . ' iciw 
342 342
             WHERE iciw.' . \Ecommerce\Item\Offer\Warehouse::colPrefix() . \Ecommerce\Item\Offer::index() . ' = ' . \Ecommerce\Item\Offer::index() . '
@@ -351,28 +351,28 @@  discard block
 block discarded – undo
351 351
             )
352 352
             WHERE iewb.' . \Ecommerce\Warehouse\Block::colPrefix() . \Ecommerce\Item\Offer::index() . ' = ' . \Ecommerce\Item\Offer::index() . ')
353 353
           )',
354
-          0,
355
-          '>'
356
-      ];
354
+            0,
355
+            '>'
356
+        ];
357 357
     }
358 358
 
359 359
     $selectOptions['group'] = Ecommerce\Item::index();
360 360
 
361 361
     return $selectOptions;
362
-  }
363
-
364
-  /**
365
-   * Getting items params with params
366
-   * 
367
-   * @param array $params
368
-   * @return array
369
-   */
370
-  public function getItemsParams($params = []) {
362
+    }
363
+
364
+    /**
365
+     * Getting items params with params
366
+     * 
367
+     * @param array $params
368
+     * @return array
369
+     */
370
+    public function getItemsParams($params = []) {
371 371
     $selectOptions = $this->parseOptions($params);
372 372
 
373 373
     $items = Ecommerce\Item::getList($selectOptions);
374 374
     if (!$items) {
375
-      return [];
375
+        return [];
376 376
     }
377 377
     $items = Ecommerce\Item\Param::getList([
378 378
                 'where' => ['item_id', array_keys($items), 'IN'],
@@ -380,58 +380,58 @@  discard block
 block discarded – undo
380 380
                 'distinct' => \Ecommerce\Item\Option::index()
381 381
     ]);
382 382
     return $items;
383
-  }
384
-
385
-  /**
386
-   * Getting items with params
387
-   * 
388
-   * @param array $params
389
-   * @return array
390
-   */
391
-  public function getItems($params = []) {
383
+    }
384
+
385
+    /**
386
+     * Getting items with params
387
+     * 
388
+     * @param array $params
389
+     * @return array
390
+     */
391
+    public function getItems($params = []) {
392 392
     $selectOptions = $this->parseOptions($params);
393 393
     $items = Ecommerce\Item::getList($selectOptions);
394 394
     return $items;
395
-  }
396
-
397
-  /**
398
-   * Return count of items with params
399
-   * 
400
-   * @param array $params
401
-   * @return int
402
-   */
403
-  public function getItemsCount($params = []) {
395
+    }
396
+
397
+    /**
398
+     * Return count of items with params
399
+     * 
400
+     * @param array $params
401
+     * @return int
402
+     */
403
+    public function getItemsCount($params = []) {
404 404
     $selectOptions = $this->parseOptions($params);
405 405
     $selectOptions['distinct'] = \Ecommerce\Item::index();
406 406
     $counts = Ecommerce\Item::getCount($selectOptions);
407 407
     if (is_array($counts)) {
408
-      $sum = 0;
409
-      foreach ($counts as $count) {
408
+        $sum = 0;
409
+        foreach ($counts as $count) {
410 410
         $sum +=$count['count'];
411
-      }
412
-      return $sum;
411
+        }
412
+        return $sum;
413 413
     }
414 414
     return $counts;
415
-  }
415
+    }
416 416
 
417
-  public function viewsCategoryList($inherit = true) {
417
+    public function viewsCategoryList($inherit = true) {
418 418
     $return = [];
419 419
     if ($inherit) {
420
-      $return['inherit'] = 'Как у родителя';
420
+        $return['inherit'] = 'Как у родителя';
421 421
     }
422 422
     $return['itemList'] = 'Список товаров';
423 423
     $conf = App::$primary->view->template->config;
424 424
     if (!empty($conf['files']['modules']['Ecommerce'])) {
425
-      foreach ($conf['files']['modules']['Ecommerce'] as $file) {
425
+        foreach ($conf['files']['modules']['Ecommerce'] as $file) {
426 426
         if ($file['type'] == 'Category') {
427
-          $return[$file['file']] = $file['name'];
427
+            $return[$file['file']] = $file['name'];
428
+        }
428 429
         }
429
-      }
430 430
     }
431 431
     return $return;
432
-  }
432
+    }
433 433
 
434
-  public function templatesCategoryList() {
434
+    public function templatesCategoryList() {
435 435
     $return = [
436 436
         'inherit' => 'Как у родителя',
437 437
         'current' => 'Текущая тема'
@@ -440,107 +440,107 @@  discard block
 block discarded – undo
440 440
     $conf = App::$primary->view->template->config;
441 441
 
442 442
     if (!empty($conf['files']['aditionTemplateFiels'])) {
443
-      foreach ($conf['files']['aditionTemplateFiels'] as $file) {
443
+        foreach ($conf['files']['aditionTemplateFiels'] as $file) {
444 444
         $return[$file['file']] = '- ' . $file['name'];
445
-      }
445
+        }
446 446
     }
447 447
     return $return;
448
-  }
448
+    }
449 449
 
450
-  public function cartStatusDetector($event) {
450
+    public function cartStatusDetector($event) {
451 451
     $cart = $event['eventObject'];
452 452
     if (!empty($cart->_changedParams['cart_cart_status_id'])) {
453
-      $cart->date_status = date('Y-m-d H:i:s');
454
-      $event = new Ecommerce\Cart\Event(['cart_id' => $cart->id, 'user_id' => \Users\User::$cur->id, 'cart_event_type_id' => 5, 'info' => $cart->cart_status_id]);
455
-      $event->save();
453
+        $cart->date_status = date('Y-m-d H:i:s');
454
+        $event = new Ecommerce\Cart\Event(['cart_id' => $cart->id, 'user_id' => \Users\User::$cur->id, 'cart_event_type_id' => 5, 'info' => $cart->cart_status_id]);
455
+        $event->save();
456 456
 
457
-      $prev_status_id = $cart->_changedParams['cart_cart_status_id'];
458
-      $now_status_id = $cart->cart_status_id;
457
+        $prev_status_id = $cart->_changedParams['cart_cart_status_id'];
458
+        $now_status_id = $cart->cart_status_id;
459 459
 
460
-      $status = Ecommerce\Cart\Status::getList(['where' => ['id', implode(',', [$prev_status_id, $now_status_id]), 'IN']]);
460
+        $status = Ecommerce\Cart\Status::getList(['where' => ['id', implode(',', [$prev_status_id, $now_status_id]), 'IN']]);
461 461
 
462
-      $prefix = isset(App::$cur->ecommerce->config['orderPrefix']) ? $config = App::$cur->ecommerce->config['orderPrefix'] : '';
463
-      \App::$cur->users->AddUserActivity($cart->user_id, 3, "Статус вашего заказа номер {$prefix}{$cart->id} изменился с {$status[$prev_status_id]->name} на {$status[$now_status_id]->name}");
462
+        $prefix = isset(App::$cur->ecommerce->config['orderPrefix']) ? $config = App::$cur->ecommerce->config['orderPrefix'] : '';
463
+        \App::$cur->users->AddUserActivity($cart->user_id, 3, "Статус вашего заказа номер {$prefix}{$cart->id} изменился с {$status[$prev_status_id]->name} на {$status[$now_status_id]->name}");
464 464
 
465
-      if ($cart->cart_status_id == 5) {
465
+        if ($cart->cart_status_id == 5) {
466 466
         Inji::$inst->event('ecommerceCartClosed', $cart);
467
-      }
467
+        }
468 468
     }
469 469
     return $cart;
470
-  }
470
+    }
471 471
 
472
-  public function cardTrigger($event) {
472
+    public function cardTrigger($event) {
473 473
     $cart = $event['eventObject'];
474 474
     if ($cart->card) {
475
-      $sum = 0;
476
-      foreach ($cart->cartItems as $cartItem) {
475
+        $sum = 0;
476
+        foreach ($cart->cartItems as $cartItem) {
477 477
         $sum += $cartItem->final_price * $cartItem->count;
478
-      }
479
-      $cardItemHistory = new Ecommerce\Card\Item\History();
480
-      $cardItemHistory->amount = $sum;
481
-      $cardItemHistory->card_item_id = $cart->card_item_id;
482
-      $cardItemHistory->save();
483
-      $cart->card->sum += $sum;
484
-      $cart->card->save();
478
+        }
479
+        $cardItemHistory = new Ecommerce\Card\Item\History();
480
+        $cardItemHistory->amount = $sum;
481
+        $cardItemHistory->card_item_id = $cart->card_item_id;
482
+        $cardItemHistory->save();
483
+        $cart->card->sum += $sum;
484
+        $cart->card->save();
485 485
     }
486 486
     return $cart;
487
-  }
487
+    }
488 488
 
489
-  public function bonusTrigger($event) {
489
+    public function bonusTrigger($event) {
490 490
     $cart = $event['eventObject'];
491 491
     foreach ($cart->cartItems as $cartItem) {
492
-      foreach ($cartItem->price->offer->bonuses as $bonus) {
492
+        foreach ($cartItem->price->offer->bonuses as $bonus) {
493 493
         if ($bonus->limited && $bonus->left <= 0) {
494
-          continue;
494
+            continue;
495 495
         } elseif ($bonus->limited && $bonus->left > 0) {
496
-          $bonus->left -= 1;
497
-          $bonus->save();
496
+            $bonus->left -= 1;
497
+            $bonus->save();
498 498
         }
499 499
         switch ($bonus->type) {
500
-          case'currency':
500
+            case'currency':
501 501
             $currency = \Money\Currency::get($bonus->value);
502 502
             $wallets = App::$cur->money->getUserWallets($cart->user->id);
503 503
             $wallets[$currency->id]->diff($bonus->count, 'Бонус за покупку');
504 504
             break;
505 505
         }
506
-      }
506
+        }
507 507
     }
508 508
     return $cart;
509
-  }
509
+    }
510 510
 
511
-  function sitemap() {
511
+    function sitemap() {
512 512
     $map = [];
513 513
     $zeroItems = \Ecommerce\Item::getList(['where' => ['category_id', 0]]);
514 514
     foreach ($zeroItems as $item) {
515
-      $map[] = [
516
-          'name' => $item->name,
517
-          'url' => [
518
-              'loc' => (!empty($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . INJI_DOMAIN_NAME . ($item->getHref())
519
-          ],
520
-      ];
515
+        $map[] = [
516
+            'name' => $item->name,
517
+            'url' => [
518
+                'loc' => (!empty($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . INJI_DOMAIN_NAME . ($item->getHref())
519
+            ],
520
+        ];
521 521
     }
522 522
 
523 523
     $categorys = \Ecommerce\Category::getList(['where' => ['parent_id', 0]]);
524 524
     $scan = function($category, $scan) {
525
-      $map = [];
525
+        $map = [];
526 526
 
527
-      foreach ($category->items as $item) {
527
+        foreach ($category->items as $item) {
528 528
         $map[] = [
529 529
             'name' => $item->name,
530 530
             'url' => [
531 531
                 'loc' => (!empty($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . INJI_DOMAIN_NAME . ($item->getHref())
532 532
             ],
533 533
         ];
534
-      }
535
-      foreach ($category->catalogs as $child) {
534
+        }
535
+        foreach ($category->catalogs as $child) {
536 536
         $map = array_merge($map, $scan($child, $scan));
537
-      }
538
-      return $map;
537
+        }
538
+        return $map;
539 539
     };
540 540
     foreach ($categorys as $category) {
541
-      $map = array_merge($map, $scan($category, $scan));
541
+        $map = array_merge($map, $scan($category, $scan));
542 542
     }
543 543
     return $map;
544
-  }
544
+    }
545 545
 
546 546
 }
Please login to merge, or discard this patch.
system/modules/Exchange1c/objects/Parser/Item/Images.php 1 patch
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -13,65 +13,65 @@
 block discarded – undo
13 13
 
14 14
 class Images extends \Migrations\Parser {
15 15
 
16
-  public function parse() {
16
+    public function parse() {
17 17
     if (is_null($this->data)) {
18
-      return;
18
+        return;
19 19
     }
20 20
     $value = $this->data;
21 21
     if (!is_array($value)) {
22
-      $value = [$value];
22
+        $value = [$value];
23 23
     }
24 24
     $ids = [];
25 25
     $dir = pathinfo($this->object->walker->migtarionLog->source, PATHINFO_DIRNAME);
26 26
     $this->model->image_file_id = 0;
27 27
     foreach ($value as $key => $imagePath) {
28
-      if (!$imagePath || !file_exists($dir . '/' . $imagePath)) {
28
+        if (!$imagePath || !file_exists($dir . '/' . $imagePath)) {
29 29
         continue;
30
-      }
31
-      $notEq = true;
32
-      $md5Cur = md5_file($dir . '/' . $imagePath);
33
-      foreach ($this->model->images as $imageId => $image) {
30
+        }
31
+        $notEq = true;
32
+        $md5Cur = md5_file($dir . '/' . $imagePath);
33
+        foreach ($this->model->images as $imageId => $image) {
34 34
         if (!$image->file) {
35
-          $image->delete();
36
-          continue;
35
+            $image->delete();
36
+            continue;
37 37
         }
38 38
         $file = $image->file;
39 39
         $md5File = '';
40 40
         if ($file->md5) {
41
-          $md5File = $file->md5;
41
+            $md5File = $file->md5;
42 42
         } elseif (file_exists($file->getRealPath())) {
43
-          $md5File = $file->md5 = md5_file($file->getRealPath());
44
-          $file->save();
43
+            $md5File = $file->md5 = md5_file($file->getRealPath());
44
+            $file->save();
45 45
         }
46 46
 
47 47
         if ($file && file_exists($file->getRealPath()) && $md5Cur == $md5File) {
48
-          $notEq = false;
49
-          $ids[] = $imageId;
50
-          break;
48
+            $notEq = false;
49
+            $ids[] = $imageId;
50
+            break;
51
+        }
51 52
         }
52
-      }
53
-      if ($notEq) {
53
+        if ($notEq) {
54 54
         $file_id = \App::$primary->files->uploadFromUrl($dir . '/' . $imagePath, ['accept_group' => 'image', 'upload_code' => 'MigrationUpload']);
55 55
         if ($file_id) {
56
-          $image = new \Ecommerce\Item\Image([
57
-              'item_id' => $this->model->pk(),
58
-              'file_id' => $file_id
59
-          ]);
60
-          $image->save();
61
-          $ids[] = $image->id;
56
+            $image = new \Ecommerce\Item\Image([
57
+                'item_id' => $this->model->pk(),
58
+                'file_id' => $file_id
59
+            ]);
60
+            $image->save();
61
+            $ids[] = $image->id;
62 62
         }
63
-      } else {
63
+        } else {
64 64
         $image->weight = $key;
65
-      }
66
-      if ($image && !$this->model->image_file_id) {
65
+        }
66
+        if ($image && !$this->model->image_file_id) {
67 67
         $this->model->image_file_id = $image->file_id;
68
-      }
68
+        }
69 69
     }
70 70
     foreach ($this->model->images as $imageId => $image) {
71
-      if (!in_array($imageId, $ids)) {
71
+        if (!in_array($imageId, $ids)) {
72 72
         $image->delete();
73
-      }
73
+        }
74
+    }
74 75
     }
75
-  }
76 76
 
77 77
 }
Please login to merge, or discard this patch.