コード例 #1
0
ファイル: index.php プロジェクト: wardvanderput/SumoStore
 public function index()
 {
     $this->document->setTitle(Sumo\Language::getVar('APP_SHIPPINGPRODUCT_TITLE'));
     $this->document->addBreadcrumbs(array('href' => $this->url->link('common/apps', '', 'SSL'), 'text' => Sumo\Language::getVar('SUMO_ADMIN_APPS_DASHBOARD')));
     $this->document->addBreadcrumbs(array('text' => Sumo\Language::getVar('APP_SHIPPINGPRODUCT_TITLE')));
     $this->document->addScript('view/js/jquery/jquery.parsley.js');
     $this->data['stores'] = $this->model_settings_stores->getStores();
     $this->data['current_store'] = isset($this->request->get['store_id']) ? $this->request->get['store_id'] : 0;
     Sumo\Logger::info('Loading model settings');
     $this->load->appModel('Settings');
     if ($this->request->server['REQUEST_METHOD'] == 'POST') {
         $this->shippingproduct_model_settings->setSettings($this->data['current_store'], $this->request->post['settings']);
         $this->redirect($this->url->link('app/shippingproduct', '', 'SSL'));
     }
     $this->data['settings'] = $this->shippingproduct_model_settings->getSettings($this->data['current_store']);
     $this->load->model('localisation/geo_zone');
     $this->data['zones'] = $this->model_localisation_geo_zone->getGeoZones();
     $this->data['geo_zone_id'] = isset($this->request->get['geo_zone_id']) ? $this->request->get['geo_zone_id'] : $this->config->get('zone_id');
     $this->load->model('settings/stores');
     $this->data['tax'] = $this->model_settings_stores->getSettings($this->data['current_store'], 'tax_percentage');
     if (!is_array($this->data['tax']) || !count($this->data['tax']) || !isset($this->data['tax']['default'])) {
         $this->data['tax'] = $this->model_settings_general->getSetting('tax_percentage');
     }
     $this->template = 'index.tpl';
     $this->children = array('common/header', 'common/footer');
     $this->response->setOutput($this->render());
 }
コード例 #2
0
ファイル: index.php プロジェクト: wardvanderput/SumoStore
$registry->set('weight', new Sumo\Weight($registry));
Sumo\Logger::info('Weight created');
// Length
$registry->set('length', new Sumo\Length($registry));
Sumo\Logger::info('Lenght created');
// User
$registry->set('user', new User($registry));
Sumo\Logger::info('User created');
// Front Controller
$controller = new Front($registry);
Sumo\Logger::info('Front created');
// Login
$controller->addPreAction(new Sumo\Action('common/home/login'));
Sumo\Logger::info('Front pre-action common/home/login added');
// Permission
$controller->addPreAction(new Sumo\Action('common/home/permission'));
Sumo\Logger::info('Front pre-action common/home/permission added');
// Router
if (isset($request->get['route'])) {
    $route = strtolower($request->get['route']);
    $action = new Sumo\Action($route);
    Sumo\Logger::info('Action created with route ' . htmlentities($route));
} else {
    $action = new Sumo\Action('common/home');
    Sumo\Logger::info('Action created with route common/home');
}
// Dispatch
$controller->dispatch($action, new Sumo\Action('error/not_found'));
Sumo\Logger::info('Dispatching action with fallback error/not_found');
// Output
$output = $response->output();
コード例 #3
0
ファイル: products.php プロジェクト: wardvanderput/SumoStore
 public function getProducts($data)
 {
     Sumo\Logger::info('getProducts: ' . print_r($data, true));
     $result = $search = array();
     if (isset($data['path'])) {
         $categories = explode('_', $data['path']);
         $category_id = end($categories);
     }
     if (!empty($data['data']['filter_category_id'])) {
         $category_id = $data['data']['filter_category_id'];
     }
     if (empty($data['data']['start'])) {
         $data['data']['start'] = 0;
     }
     if (empty($data['data']['limit'])) {
         $data['data']['limit'] = 15;
     }
     if (empty($data['data']['sort'])) {
         $data['data']['sort'] = 'p.sort_order';
     }
     if (empty($data['data']['order']) || !in_array($data['data']['order'], array('ASC', 'DESC'))) {
         $data['data']['order'] = 'ASC';
     }
     $cache = 'wsp_plist_product_category_' . md5(json_encode($data));
     $result = Sumo\Cache::find($cache);
     if (is_array($result) && count($result)) {
         Sumo\Logger::info('Got products from cache: ' . print_r($result, true));
         return $result;
     }
     if ($data['type'] == 'category') {
         $sql = 'SELECT p.product_id
         FROM PREFIX_product AS p';
         if ($data['data']['sort'] == 'pd.name') {
             $sql .= ' LEFT JOIN PREFIX_product_description pd
             ON (p.product_id = pd.product_id)';
         }
         $sql .= '
         LEFT JOIN PREFIX_product_to_category AS ptc
             ON ptc.product_id = p.product_id
         WHERE ptc.category_id = :category_id
             AND p.status = 1
         GROUP BY p.product_id';
         if ($data['data']['sort'] == 'pd.name') {
             $sql .= ' ORDER BY pd.name ' . $data['data']['order'];
         }
         $values = array('category_id' => $category_id);
     }
     if (!empty($sql)) {
         $total = $this->fetchAll($sql, $values);
         $result['total'] = count($total);
         $sql .= ' LIMIT ' . $data['data']['start'] . ',' . $data['data']['limit'];
         $products = $this->fetchAll($sql, $values);
     }
     if (is_array($products)) {
         foreach ($products as $p) {
             $product = $this->getProduct($p['product_id']);
             $result[] = $product;
         }
     }
     Sumo\Cache::set($cache, $result);
     Sumo\Logger::info('Put products in cache: ' . print_r($result, true));
     return $result;
 }
コード例 #4
0
 protected final function render()
 {
     Sumo\Logger::info('rendering app now');
     foreach ($this->children as $child) {
         $this->data[basename($child)] = $this->getChild($child);
     }
     $this->registry->set('currentApp', $this->getCurrentApp());
     $dir = 'apps/' . strtolower($this->registry->get('currentApp'));
     $template = $this->template;
     $this->template = DIR_TEMPLATE . $this->config->get('template') . '/template/' . $dir . '/' . $this->template;
     // First try if the full/exact path is given
     if (!file_exists($this->template)) {
         //trigger_error('Error 1: Could not load template ' . $this->template . '!', E_USER_ERROR);
         $this->template = str_replace($this->config->get('template') . '/template/', 'base/template/', $this->template);
     }
     if (!file_exists($this->template)) {
         //trigger_error('Error 2: Could not load template ' . $this->template . '!', E_USER_ERROR);
         $dir = DIR_HOME . $dir;
         $test = explode('/', trim(DIR_APPLICATION, '/'));
         $test = end($test);
         if ($test == 'admin') {
             $dir .= '/admin/';
         } else {
             $dir .= '/catalog/';
         }
         $dir .= 'view/template/';
         $this->template = $dir . $template;
     }
     if (file_exists($this->template)) {
         extract($this->data);
         ob_start();
         require $this->template;
         $this->output = ob_get_contents();
         ob_end_clean();
         Sumo\Logger::info('Rendering for ' . strtolower($this->registry->get('currentApp')) . ' finished; loaded template ' . $this->template);
         return str_replace('</head>', '<meta name="generator" content="SumoStore" /></head>', $this->output);
     } else {
         trigger_error('Error: Could not load template ' . $this->template . ' for ' . strtolower($this->registry->get('currentApp')) . '!', E_USER_ERROR);
         if (isset($this->data['header'])) {
             $this->output .= $this->data['header'];
         }
         if (isset($this->data['footer'])) {
             $this->output .= $this->data['footer'];
         }
         return $this->output;
     }
 }
コード例 #5
0
ファイル: products.php プロジェクト: wardvanderput/SumoStore
 public function getProducts($data)
 {
     $result = $search = array();
     if (isset($data['path'])) {
         $categories = explode('_', $data['path']);
         $category_id = end($categories);
     }
     if (!empty($data['data']['filter_category_id'])) {
         $category_id = $data['data']['filter_category_id'];
     }
     if (empty($data['data']['start'])) {
         $data['data']['start'] = 0;
     }
     if (empty($data['data']['limit'])) {
         $data['data']['limit'] = 15;
     }
     if (empty($data['data']['sort'])) {
         $data['data']['sort'] = 'p.sort_order';
     }
     if (empty($data['data']['order']) || !in_array($data['data']['order'], array('ASC', 'DESC'))) {
         $data['data']['order'] = 'ASC';
     }
     $cache = 'wsp_plist_product_category_' . md5(json_encode($data));
     $result = Sumo\Cache::find($cache);
     if (is_array($result) && count($result)) {
         Sumo\Logger::info('Got products from cache: ');
         return $result;
     }
     if ($data['type'] == 'category') {
         $sql = 'SELECT p.product_id, COUNT(*) AS total
         FROM PREFIX_product AS p';
         if ($data['data']['sort'] == 'pd.name') {
             $sql .= ' LEFT JOIN PREFIX_product_description pd
             ON (p.product_id = pd.product_id)';
         }
         if (!empty($data['data']['filter_filter'])) {
             $sql .= ' LEFT JOIN PREFIX_product_attribute AS pa ON pa.product_id = p.product_id ';
         }
         $sql .= '
         LEFT JOIN PREFIX_product_to_category AS ptc
             ON ptc.product_id = p.product_id
         WHERE ptc.category_id = :category_id
             AND p.status = 1 ';
         if (!empty($data['data']['filter_filter'])) {
             $filter = array();
             if (is_array($data['data']['filter_filter'])) {
                 foreach ($data['data']['filter_filter'] as $id => $unused) {
                     if (!is_numeric($id) || empty($id)) {
                         continue;
                     }
                     $filter[] = $id;
                 }
             } else {
                 if (is_numeric($data['data']['filter_filter']) && !empty($data['data']['filter_filter'])) {
                     $filter[] = $data['data']['filter_filter'];
                 }
             }
             if (count($filter)) {
                 $sql .= ' AND pa.attribute_id IN (' . implode(',', $filter) . ') ';
             }
         }
         $sql .= '
         GROUP BY p.product_id ';
         switch ($data['data']['sort']) {
             case 'pd.name':
                 $sql .= 'ORDER BY pd.name ' . $data['data']['order'];
                 break;
             case 'p.price':
                 $sql .= 'ORDER BY p.price ' . $data['data']['order'];
                 break;
             case 'p.model':
                 $sql .= 'ORDER BY p.model_2 ' . $data['data']['order'];
                 break;
             default:
                 $sql .= 'ORDER BY p.sort_order ' . $data['data']['order'];
                 break;
         }
         $values = array('category_id' => $category_id);
     }
     if ($data['type'] == 'category_path') {
         $categoriesData = $this->fetchAll("SELECT category_id FROM PREFIX_category_path WHERE path_id = :id", array('id' => $category_id));
         $categories = array();
         foreach ($categoriesData as $item) {
             $categories[] = $item['category_id'];
         }
         $sql = 'SELECT p.product_id, COUNT(*) AS total
         FROM PREFIX_product AS p';
         if ($data['data']['sort'] == 'pd.name') {
             $sql .= ' LEFT JOIN PREFIX_product_description pd
             ON (p.product_id = pd.product_id)';
         }
         if (!empty($data['data']['filter_filter'])) {
             $sql .= ' LEFT JOIN PREFIX_product_attribute AS pa ON pa.product_id = p.product_id ';
         }
         $sql .= '
         LEFT JOIN PREFIX_product_to_category AS ptc
             ON ptc.product_id = p.product_id
         WHERE ';
         if (count($categories)) {
             $sql .= 'ptc.category_id IN(' . implode(',', $categories) . ')
             AND p.status = 1 ';
         } else {
             $sql .= 'p.status = 1 ';
         }
         if (!empty($data['data']['filter_filter'])) {
             $filter = array();
             if (is_array($data['data']['filter_filter'])) {
                 foreach ($data['data']['filter_filter'] as $id => $unused) {
                     if (!is_numeric($id) || empty($id)) {
                         continue;
                     }
                     $filter[] = $id;
                 }
             } else {
                 if (is_numeric($data['data']['filter_filter']) && !empty($data['data']['filter_filter'])) {
                     $filter[] = $data['data']['filter_filter'];
                 }
             }
             if (count($filter)) {
                 $sql .= ' AND pa.attribute_id IN (' . implode(',', $filter) . ') ';
             }
         }
         $sql .= '
         GROUP BY p.product_id ';
         switch ($data['data']['sort']) {
             case 'pd.name':
                 $sql .= 'ORDER BY pd.name ' . $data['data']['order'];
                 break;
             case 'p.price':
                 $sql .= 'ORDER BY p.price ' . $data['data']['order'];
                 break;
             case 'p.model':
                 $sql .= 'ORDER BY p.model_2 ' . $data['data']['order'];
                 break;
             default:
                 $sql .= 'ORDER BY p.sort_order ' . $data['data']['order'];
                 break;
         }
         $values = array();
     }
     if ($data['type'] == 'manufacturer') {
         $sql = 'SELECT p.product_id, COUNT(*) AS total
         FROM PREFIX_product AS p';
         if ($data['data']['sort'] == 'pd.name') {
             $sql .= ' LEFT JOIN PREFIX_product_description pd
             ON (p.product_id = pd.product_id)';
         }
         if (!empty($data['data']['filter_filter'])) {
             $sql .= ' LEFT JOIN PREFIX_product_attribute AS pa ON pa.product_id = p.product_id ';
         }
         $sql .= '
         LEFT JOIN PREFIX_product_to_category AS ptc
             ON ptc.product_id = p.product_id
         WHERE p.manufacturer_id = :manufacturer_id
             AND p.status = 1 ';
         if (!empty($data['data']['filter_filter'])) {
             $filter = array();
             if (is_array($data['data']['filter_filter'])) {
                 foreach ($data['data']['filter_filter'] as $id => $unused) {
                     if (!is_numeric($id) || empty($id)) {
                         continue;
                     }
                     $filter[] = $id;
                 }
             } else {
                 if (is_numeric($data['data']['filter_filter']) && !empty($data['data']['filter_filter'])) {
                     $filter[] = $data['data']['filter_filter'];
                 }
             }
             if (count($filter)) {
                 $sql .= ' AND pa.attribute_id IN (' . implode(',', $filter) . ') ';
             }
         }
         $sql .= '
         GROUP BY p.product_id ';
         switch ($data['data']['sort']) {
             case 'pd.name':
                 $sql .= 'ORDER BY pd.name ' . $data['data']['order'];
                 break;
             case 'p.price':
                 $sql .= 'ORDER BY p.price ' . $data['data']['order'];
                 break;
             case 'p.model':
                 $sql .= 'ORDER BY p.model_2 ' . $data['data']['order'];
                 break;
             default:
                 $sql .= 'ORDER BY p.sort_order ' . $data['data']['order'];
                 break;
         }
         $values = array('manufacturer_id' => $data['data']['filter_manufacturer_id']);
     }
     if (!empty($sql)) {
         $total = $this->query($sql, $values)->fetch();
         $result['total'] = $total['total'];
         $sql .= ' LIMIT ' . $data['data']['start'] . ',' . $data['data']['limit'];
         if ($data['type'] == 'category_path') {
             if (!$total || !count($total)) {
                 Sumo\Logger::warning('total query failed');
                 return;
             }
             Sumo\Logger::warning(print_r($total, true));
         }
         $products = $this->fetchAll($sql, $values);
         Sumo\Logger::info('Total products count: ' . $result['total'] . ', fetchAll with limit: ' . print_r($products, true));
     }
     if (is_array($products) && count($products)) {
         $count = 1;
         foreach ($products as $p) {
             if (empty($p['product_id'])) {
                 continue;
             }
             $product = $this->getProduct($p['product_id']);
             if ((!$product['stock_visible'] || $product['stock_visible'] == 2 && !$this->config->get('display_stock_empty')) && $product['quantity'] <= 0) {
                 Sumo\Logger::info('Product ' . $p['product_id'] . ' has no stock and may not be visible, or shop is set to disable low quantity products');
                 continue;
             }
             $result[$count++] = $product;
         }
     }
     if (!$result['total'] && $data['type'] == 'category') {
         $data['type'] = 'category_path';
         return $this->getProducts($data);
     }
     Sumo\Cache::set($cache, $result);
     Sumo\Logger::info('Put products in cache');
     return $result;
 }