Blame view

src/app/frontend/controllers/ControllerBase.php 3.58 KB
1ea3b987   Administrator   maby first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
  <?php
  
  namespace controllers;
  
  
  use Phalcon\Mvc\Dispatcher;
  
  class ControllerBase extends \Phalcon\Mvc\Controller
  {
      public $lang_id;
      public $lang_name;
      public $t;
      public $count_cart;
  
      public function init() {
          $this->lang_id = $this->seoUrl->getLangId();
          $this->lang_name = $this->seoUrl->getLangName();
          $this->t = $this->languages->getTranslation();
  
          $this->count_cart = 0;
          if($this->session->has('in_cart') && $cart = $this->session->get('in_cart')) {
              foreach ($cart as $item) {
                  $this->count_cart += $item['count_items'];
              }
          }
  
      }
  
      public function beforeExecuteRoute(Dispatcher $dispatcher) {
  
          $this->init();
  
          if($this->session->has('id')) {
              $customer = $this->models->getCustomers()->getOneData($this->session->get('id'))['0'];
              $this->view->setVar('customer', $customer);
          }
  
          if($this->session->get('special_users_id') != null) {
  
              $orders = $this->models->getOrders()->getOrdersByCustomerId( $this->session->get('id') );
  
              foreach($orders as $key => $value) {
                  $orders[$key]['created_date'] = date('d', strtotime($value['created_date'])).'.'.
                      date('m', strtotime($value['created_date'])).'.'.
                      date('Y', strtotime($value['created_date']));
                  $orders_sum = !empty($this->models->getOrders()->getOrdersSumById( $value['id'] )[0]) ? $this->models->getOrders()->getOrdersSumById( $value['id'] )[0] : 0;
                  $orders[$key]['price'] = $orders_sum['price'];
                  $orders[$key]['status'] = \config::get( 'global#status/'.$this->lang_id.'/'.$value['status'] );
              }
  
              $this->view->setVar('orders', $orders);
          }
  
          $compare        = $this->session->get('compare', []);
          $count          = 0;
  
          if( !empty( $compare ) )
          {
              foreach( $compare as $key => $comp )
              {
                  $type_ids[] = $key;
  
                  foreach( $comp as $k => $c )
                  {
                      $subtype_ids[] = $k;
  
                      $count += count($c);
                  }
              }
  
              $catalogs = $this->common->getTypeSubtype2( $this->lang_id );
  
              foreach( $compare as $key => $comp )
              {
                  if( !empty($catalogs[$key] ) )
                  {
                      foreach( $comp as $k => $c )
                      {
                          $compare_[$key][$k] =
                              [
                                  'title' => $catalogs[$k]['title'],
                                  'count' => count($c),
                                  'items' => $c,
                                  'url'       => $this->url->get([ 'for' => 'compare_items',  'subtype' => $catalogs[$k]['alias'], 'compare_ids' => join('-', $c) ]),
                                  'url_del'   => $this->url->get([ 'for' => 'compare_items_del',  'subtype' => $catalogs[$k]['alias'], 'compare_ids' => join('-', $c) ])
  
                              ];
  
                      }
                  }
              }
          }
          $this->view->setVar('count_cart', $this->count_cart);
          $this->view->setVar('t', $this->t);
          $this->view->setVar('lang_id', $this->lang_id);
          $this->view->setVar('lang', explode( '/', $this->request->get('_url')));
          $this->view->setVar('month_names', $this->t->_("month_list"));
          $this->view->setVar('compare', $compare);
          $this->view->setVar('compare_', !empty($compare_) ? $compare_ : null);
          $this->view->setVar('count', $count);
      }
  }