public function login($username, $password, $cookie = false) { $data = Sumo\Database::query("SELECT *\n FROM PREFIX_user\n WHERE username = :username\n AND (\n password = SHA1(CONCAT(salt, SHA1(CONCAT(salt, :unsalted))))\n OR password = :hashed\n ) AND status = 1", array('username' => $username, 'unsalted' => sha1($password), 'hashed' => md5($password)))->fetch(); if (count($data)) { if ($cookie) { // some secure way to implement a cookie } $this->session->data['user_id'] = $data['user_id']; $this->session->data['firstname'] = $data['firstname']; $this->session->data['lastname'] = $data['lastname']; $this->session->data['email'] = $data['email']; $this->user_id = $data['user_id']; $this->username = $data['username']; return true; } return false; }
} if (is_array($body)) { $css .= 'body {'; if (isset($body['background-image'])) { $css .= 'background: ' . $body['background-image'] . ' ' . $body['background-repeat'] . ' ' . $body['background-color'] . ';'; } if (isset($body['color'])) { $css .= 'color: ' . $body['color'] . ';'; } $css .= '}'; } } } else { $css .= 'PHP_EOL/= Specific colors could not be found.. =/PHP_EOL'; } $check = Sumo\Database::query("SELECT setting_value FROM PREFIX_settings_stores WHERE setting_name = :template AND store_id = :id", array('id' => $id, 'template' => 'stylesheet_' . $theme['template']))->fetch(); if (count($check) && !empty($check['setting_value'])) { $css .= 'PHP_EOL/= Extra stylesheet, user generated =/PHP_EOL'; $css .= $check['setting_value']; } } catch (\Exception $e) { $css .= 'PHP_EOL/= Could not load extra CSS =/'; } } } $css = preg_replace('#\\s+#', ' ', $css); $css = preg_replace('#/\\*.*?\\*/#s', '', $css); $css = preg_replace('#/=(.*?)=/#s', '/* \\1 */', $css); $css = str_replace('PHP_EOL', "\n", $css); $css = str_replace('; ', ';', $css); $css = str_replace(': ', ':', $css);
require DIR_SYSTEM . 'startup.php'; define('ABS_START', microtime(true)); // Registry $registry = new Registry(); // Loader $loader = new Loader($registry); $registry->set('load', $loader); // Config $config = new Config(); $registry->set('config', $config); // Database *legacy* //$db = new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE); Sumo\Database::setup(array('hostname' => DB_HOSTNAME, 'username' => DB_USERNAME, 'password' => DB_PASSWORD, 'database' => DB_DATABASE, 'prefix' => DB_PREFIX)); //$registry->set('db', Sumo); Sumo\Cache::disableCache(defined('NO_CACHE') ? true : false); $check = Sumo\Database::query("SELECT setting_value FROM PREFIX_settings WHERE setting_name = 'admin_directory'")->fetch(); $stores = Sumo\Database::fetchAll("SELECT base_http, base_https FROM PREFIX_stores"); $tmp = $_SERVER['REQUEST_URI']; foreach ($stores as $list) { foreach ($list as $key => $value) { $list[$key] = explode('/', trim($value, '/')); $list[$key] = end($list[$key]); } $tmp = trim(str_replace($list, '', $tmp), '/'); } $tmp = explode('/', $tmp); $tmp = $tmp[0]; if (!empty($_SERVER['HTTP_HOST']) && !empty($tmp) && !empty($check) && !isset($_GET['resource'])) { if ($tmp == $check['setting_value']) { define('ADMIN_ENABLED', true); require 'admin/index.php';
public function getProducts() { if (!$this->data) { $this->load->model('catalog/product'); foreach ($this->session->data['cart'] as $key => $quantity) { $product = explode(':', $key); $product_id = $product[0]; $stock = true; // Options if (isset($product[1])) { $options = unserialize(base64_decode($product[1])); } else { $options = array(); } // Fetch product, not from cache but realtime $product = Sumo\Database::query("SELECT *\n FROM PREFIX_product p\n LEFT JOIN PREFIX_product_description pd\n ON (p.product_id = pd.product_id)\n WHERE p.product_id = :pid\n AND pd.language_id = :lid\n AND p.date_available <= NOW()\n AND p.status = 1", array('pid' => $product_id, 'lid' => $this->config->get('language_id')))->fetch(); if (is_array($product) && count($product)) { $option_price = 0; $option_points = 0; $option_weight = 0; $option_data = array(); foreach ($options as $option_id => $value_id) { if (!isset($option_data[$option_id])) { $check = Sumo\Database::query("SELECT name FROM PREFIX_product_option_description WHERE option_id = :id AND language_id = :lid", array('id' => $option_id, 'lid' => $this->config->get('language_id')))->fetch(); $option_data[$option_id]['name'] = $check['name']; $option_data[$option_id]['options'] = array(); } $option_data_raw = Sumo\Database::query("SELECT name, quantity, subtract, price, price_prefix, weight, weight_prefix, name\n FROM PREFIX_product_option_value AS pov\n LEFT JOIN PREFIX_product_option_value_description AS povd\n ON pov.value_id = povd.value_id\n WHERE pov.value_id = :value_id\n AND language_id = :lid", array('value_id' => $value_id, 'lid' => $this->config->get('language_id')))->fetch(); $option_data[$option_id]['options'][$value_id] = $option_data_raw; } if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('customer_group_id'); } $price = $product['price']; // Product Discounts $discount_quantity = 0; foreach ($this->session->data['cart'] as $key_2 => $quantity_2) { $product_2 = explode(':', $key_2); if ($product_2[0] == $product_id) { $discount_quantity += $quantity_2; } } $product_discount_query = Sumo\Database::query("SELECT price\n FROM PREFIX_product_discount\n WHERE product_id = :pid\n AND customer_group_id = :cgid\n AND quantity <= :q\n AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW()))\n ORDER BY quantity DESC, priority ASC, price ASC\n LIMIT 1", array('pid' => $product_id, 'cgid' => $customer_group_id, 'q' => $discount_quantity))->fetch(); if (count($product_discount_query) && !empty($product_discount_query['price'])) { $price = $product_discount_query['price']; } // Product Specials $product_special_query = Sumo\Database::query("SELECT price\n FROM PREFIX_product_special\n WHERE product_id = :pid\n AND customer_group_id = :cgid\n AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW()))\n ORDER BY priority ASC, price ASC\n LIMIT 1", array('pid' => $product_id, 'cgid' => $customer_group_id))->fetch(); if (count($product_special_query) && !empty($product_special_query['price'])) { $price = $product_special_query['price']; } // Downloads $download_data = array(); $download_query = Sumo\Database::fetchAll("SELECT *\n FROM PREFIX_product_to_download p2d\n LEFT JOIN PREFIX_download d\n ON (p2d.download_id = d.download_id)\n LEFT JOIN PREFIX_download_description dd\n ON (d.download_id = dd.download_id)\n WHERE p2d.product_id = :pid\n AND dd.language_id = :lid", array('pid' => $product_id, 'lid' => $this->config->get('language_id'))); foreach ($download_query as $download) { $download_data[] = $download; } if (count($option_data)) { foreach ($option_data as $data) { foreach ($data['options'] as $option) { if (!$option['quantity'] || $product['quantity'] < $option['quantity']) { $stock = false; } if (!empty($option['price'])) { if ($option['price_prefix'] == '-') { $price -= $option['price']; } else { $price += $option['price']; } } } } } else { // Check if stock is linked if ($product['stock_id'] != $product['product_id']) { $stockData = Sumo\Database::query("SELECT quantity FROM PREFIX_product WHERE product_id = :id", array('id' => $product['stock_id']))->fetch(); $product['quantity'] = $stockData['quantity']; } // Stock if (!$product['quantity'] || $product['quantity'] < $quantity) { $stock = false; } } // Image if (empty($product['image'])) { $product['image'] = 'no_image.jpg'; } $this->data[$key] = array('key' => $key, 'product_id' => $product['product_id'], 'name' => $product['name'], 'model' => $product['model'], 'shipping' => $product['shipping'], 'image' => $product['image'], 'options' => $options, 'options_data' => $option_data, 'download' => $download_data, 'quantity' => $quantity, 'minimum' => $product['minimum'], 'subtract' => $product['subtract'], 'stock' => $stock, 'stock_id' => $product['stock_id'], 'in_stock' => $product['quantity'], 'price' => $price + $option_price, 'total' => round($price + $option_price, 2) * $quantity, 'points' => $product['points'] ? ($product['points'] + $option_points) * $quantity : 0, 'tax_percentage' => $product['tax_percentage'], 'weight' => ($product['weight'] + $option_weight) * $quantity, 'weight_class_id' => $product['weight_class_id'], 'length' => $product['length'], 'width' => $product['width'], 'height' => $product['height'], 'length_class_id' => $product['length_class_id']); } else { $this->remove($key); } } } return $this->data; }
public function getRewardPoints() { $query = Sumo\Database::query("SELECT SUM(points) AS total FROM PREFIX_customer_reward WHERE customer_id = " . (int) $this->customer_id)->fetch(); return $query['total']; }
<?php if (!defined('CATALOG_ENABLED')) { // SumoGuard notification header('Location: ../'); exit; } define('DIR_APPLICATION', DIR_HOME . 'catalog/'); define('DIR_TEMPLATE', DIR_APPLICATION . 'view/theme/'); // Which store is this? if (!empty($_SERVER['HTTP_HOST'])) { $url = rtrim($_SERVER['HTTP_HOST'] . '/' . rtrim(dirname($_SERVER['SCRIPT_NAME']), '/'), '/') . '%'; $store = Sumo\Database::query("SELECT *\n FROM PREFIX_stores\n WHERE base_http LIKE :url1\n OR base_https LIKE :url2\n OR REPLACE(base_http, 'www.', '') LIKE :url3\n OR REPLACE(base_https, '', '') LIKE :url4\n LIMIT 1", array('url1' => $url, 'url2' => $url, 'url3' => str_replace('www.', '', $url), 'url4' => str_replace('www.', '', $url)))->fetch(); } if (empty($store) || !count($store)) { $store = Sumo\Database::query("SELECT * FROM PREFIX_stores WHERE store_id = 0 LIMIT 1")->fetch(); } $config->set('store_id', $store['store_id']); $config->set('store_data', $store); $config->set('name', $store['name']); $config->set('base_default', $store['base_default']); $config->set('base_http', $store['base_http']); $config->set('base_https', $store['base_https']); // Update cache class with store Sumo\Cache::setStore($store['store_id']); // Get default settings foreach (Sumo\Database::fetchAll("SELECT setting_name, setting_value, is_json FROM PREFIX_settings") as $list) { $config->set($list['setting_name'], $list['is_json'] ? json_decode($list['setting_value'], true) : $list['setting_value']); } // Overrule with store settings foreach (Sumo\Database::fetchAll("SELECT setting_name, setting_value, is_json FROM PREFIX_settings_stores WHERE store_id = :id", array('id' => $store['store_id'])) as $list) {