Exemple #1
0
 /**
  * Get customer
  *
  * @return array|mixed|Customers
  */
 protected function getCustomer()
 {
     $session_id = DIContainer::build('Core\\Session')->getId();
     $customer = Customers::findBySession_id($session_id);
     if (empty($customer)) {
         try {
             //if not found customer add customer
             $customer = new Customers();
             $customer->active = 0;
             $customer->session_id = $session_id;
             $customer->save();
         } catch (\PDOException $e) {
         }
     }
     return $customer;
 }
Exemple #2
0
 /**
  * Render Products list
  *
  * @param array $filter
  * @param int $page_id
  * @return Response
  * @throws \Exception
  */
 private function renderProductsList(array $filter, $page_id)
 {
     $categories = !empty($filter['categories']) ? $filter['categories'] : array();
     $price_asc = is_bool($filter['price_asc']) ? $filter['price_asc'] : null;
     $url_template = !empty($filter['url_template']) ? $filter['url_template'] : '';
     $config = DIContainer::build('config');
     $products_per_page = $config['products_per_page'];
     $num_per_page = $config['nums_per_page'];
     $active_page = $page_id ? $page_id : 1;
     $asc = is_null($price_asc) ? true : $price_asc;
     $order_column = is_null($price_asc) ? 'id' : 'Price';
     $base_join_product_array = array('table2' => 'Categories_has_Products', 'joined_columns' => array('id', 'Products_id'), 'values' => array('2@Categories_id' => array_map(function ($el) {
         return (int) $el;
     }, $categories)), 'asc' => $asc, 'order_column' => $order_column);
     if (count($categories)) {
         $products = Products::find('join', array_merge($base_join_product_array, array('limit' => $products_per_page, 'offset' => ($active_page - 1) * $products_per_page)));
         $count_products_per_cat = Products::find('join', array_merge($base_join_product_array, array('select_columns' => 'count')))->count;
         $count_pages = ceil((int) $count_products_per_cat / $products_per_page);
     } else {
         $products = Products::find('offset', array('limit' => $products_per_page, 'offset' => ((int) $active_page - 1) * (int) $products_per_page, 'order_column' => $order_column, 'asc' => $asc));
         $count_products = Products::find('all', array('select_columns' => 'count'))->count;
         $count_pages = ceil((int) $count_products / $products_per_page);
     }
     $cats_data = $this->genCatMetaData($categories, $price_asc);
     return $this->render('index.html', array('cats' => $this->getAllCategories(), 'cats_data' => $cats_data, 'products' => $products, 'active_page' => $active_page, 'prods_per_page' => $products_per_page, 'count_pages' => $count_pages, 'count_show_pages' => $num_per_page, 'url_page' => $url_template, 'selected_categories' => $categories));
 }