public function getCountries($data = array()) { $cache = 'countries.' . json_encode($data); $return = Cache::find($cache); if (is_array($return)) { return $return; } $sql = "SELECT * FROM PREFIX_country"; $sort_data = array('name', 'iso_code_2', 'iso_code_3'); if (isset($data['sort']) && in_array($data['sort'], $sort_data)) { $sql .= " ORDER BY " . $data['sort']; } else { $sql .= " ORDER BY name"; } if (isset($data['order']) && $data['order'] == 'DESC') { $sql .= " DESC"; } else { $sql .= " ASC"; } if (isset($data['start']) || isset($data['limit'])) { if ($data['start'] < 0) { $data['start'] = 0; } if ($data['limit'] < 1) { $data['limit'] = 20; } $sql .= " LIMIT " . (int) $data['start'] . "," . (int) $data['limit']; } $return = $this->fetchAll($sql); Cache::set($cache, $return); return $return; }
public function getGeoZones($data = array()) { if ($data) { $sql = "SELECT * FROM PREFIX_geo_zone"; $sort_data = array('name', 'description'); if (isset($data['sort']) && in_array($data['sort'], $sort_data)) { $sql .= " ORDER BY " . $data['sort']; } else { $sql .= " ORDER BY name"; } if (isset($data['order']) && $data['order'] == 'DESC') { $sql .= " DESC"; } else { $sql .= " ASC"; } if (isset($data['start']) || isset($data['limit'])) { if ($data['start'] < 0) { $data['start'] = 0; } if ($data['limit'] < 1) { $data['limit'] = 20; } $sql .= " LIMIT " . (int) $data['start'] . "," . (int) $data['limit']; } return $this->fetchAll($sql); } else { $data = Cache::find('geo_zone'); if (!$data) { $data = $this->fetchAll("SELECT * FROM PREFIX_geo_zone ORDER BY name ASC"); Cache::set('geo_zone', $data); } return $data; } }
public function getWeightClasses($data = array()) { if ($data) { $sql = "SELECT * FROM " . DB_PREFIX . "weight_class wc LEFT JOIN " . DB_PREFIX . "weight_class_description wcd ON (wc.weight_class_id = wcd.weight_class_id) WHERE wcd.language_id = '" . (int) $this->config->get('config_language_id') . "'"; $sort_data = array('title', 'unit', 'value'); if (isset($data['sort']) && in_array($data['sort'], $sort_data)) { $sql .= " ORDER BY " . $data['sort']; } else { $sql .= " ORDER BY title"; } if (isset($data['order']) && $data['order'] == 'DESC') { $sql .= " DESC"; } else { $sql .= " ASC"; } if (isset($data['start']) || isset($data['limit'])) { if ($data['start'] < 0) { $data['start'] = 0; } if ($data['limit'] < 1) { $data['limit'] = 20; } $sql .= " LIMIT " . (int) $data['start'] . "," . (int) $data['limit']; } $query = $this->db->query($sql); return $query->rows; } else { $weight_class_data = Cache::find('weight_class.' . (int) $this->config->get('language_id')); if (!$weight_class_data) { $weight_class_data = $this->fetchAll("SELECT * FROM PREFIX_weight_class wc\n LEFT JOIN PREFIX_weight_class_description wcd ON (wc.weight_class_id = wcd.weight_class_id)\n WHERE wcd.language_id = '" . (int) $this->config->get('language_id') . "'"); Cache::set('weight_class.' . (int) $this->config->get('language_id'), $weight_class_data); } return $weight_class_data; } }
public function getExtensions($type) { $cache = Cache::find('extensions.' . $this->config->get('config_store_id'), $type); if (!is_array($cache)) { $cache = Database::fetchAll("SELECT * FROM PREFIX_extension WHERE `type` = :type", array('type' => $type)); Cache::set('extensions.' . $this->config->get('config_store_id'), $type, $cache); } return $cache; }
public function getZonesByCountryId($country_id) { $zone_data = Cache::find('zone.' . (int) $country_id); if (!$zone_data) { $zone_data = $this->fetchAll("SELECT * FROM PREFIX_zone WHERE country_id = :id AND status = 1 ORDER BY name", array('id' => $country_id)); Cache::set('zone.' . (int) $country_id, $zone_data); } return $zone_data; }
public function getStores($data = array()) { $store_data = Cache::find('store'); if (!$store_data || !is_array($store_data) || empty($store_data)) { $store_data = Database::fetchAll("SELECT * FROM PREFIX_store ORDER BY url"); Cache::set('store', $store_data); } return $store_data; }
protected function index($setting) { $this->data['heading_title'] = Language::getVar('SUMO_PRODUCT_BESTSELLER'); $this->load->model('catalog/product'); $this->load->model('tool/image'); if ($this->registry->get('builder')) { $this->data['settings'] = Cache::find('builder'); } $this->data['products'] = array(); $results = $this->model_catalog_product->getBestSellerProducts($setting['limit']); foreach ($results as $result) { if ($result['image']) { $image = $this->model_tool_image->resize($result['image'], $setting['image_width'], $setting['image_height']); } else { $image = false; } $swapimages = $this->model_catalog_product->getProductImages($result['product_id']); if ($swapimages) { $swapimage = $this->model_tool_image->resize($swapimages[0]['image'], $this->config->get('config_image_related_width'), $this->config->get('config_image_related_height'), 'h'); } else { $swapimage = false; } if ($this->config->get('config_customer_price') && $this->customer->isLogged() || !$this->config->get('config_customer_price')) { $price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax'))); } else { $price = false; } if ((double) $result['special']) { $special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax'))); } else { $special = false; } if ($this->config->get('config_review_status')) { $rating = $result['rating']; } else { $rating = false; } if ($result['reviews']) { if ($result['reviews'] > 1) { $reviews = Language::getVar('SUMO_PRODUCT_REVIEWS_PLURAL', $result['reviews']); } else { $reviews = Language::getVar('SUMO_PRODUCT_REVIEWS_SINGULAR'); } } else { $reviews = Language::getVar('SUMO_PRODUCT_REVIEWS_NONE'); } $this->data['products'][] = array('product_id' => $result['product_id'], 'thumb' => $image, 'thumb_swap' => $swapimage, 'name' => $result['name'], 'price' => $price, 'special' => $special, 'rating' => $rating, 'reviews' => $reviews, 'href' => $this->url->link('product/product', 'path=' . $result['category_id'] . '&product_id=' . $result['product_id'])); } if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/bestseller.tpl')) { $this->template = $this->config->get('config_template') . '/template/module/bestseller.tpl'; } else { $this->template = 'default/template/module/bestseller.tpl'; } if (count($this->data['products'])) { $this->render(); } }
public function getBlogs() { $data = Cache::find('blogs'); if (count($data)) { return $data; } $query = $this->fetchAll("SELECT * FROM PREFIX_blog i LEFT JOIN PREFIX_blog_description id ON (i.blog_id = id.blog_id) WHERE id.language_id = '" . (int) $this->config->get('language_id') . "' AND i.store_id = '" . (int) $this->config->get('store_id') . "' AND i.status = '1' AND i.publish_date < NOW() ORDER BY i.publish_date DESC"); Cache::set('blogs', $query); return $query->rows; }
public function getZonesByCountryId($country_id) { $cache = 'zones.' . $country_id; $data = Cache::find($cache); if (!is_array($data) || !count($data)) { $data = $this->fetchAll("SELECT * FROM PREFIX_zone WHERE country_id = :id AND status = 1 ORDER BY name", array('id' => $country_id)); Cache::set($cache, $data); } return $data; }
public function getDashboardItems() { $active = $this->getActiveMenu(); $return = Cache::find('adi_' . md5($active)); if (!is_array($return)) { $return = Database::fetchAll("\n SELECT *\n FROM PREFIX_admin_menu\n WHERE parent_id = (SELECT menu_id FROM PREFIX_admin_menu WHERE url = :url)\n OR url = :url2\n ORDER BY sort_order ASC, parent_id ASC", array('url' => $active, 'url2' => $active)); Cache::set('admin_menu.adi_' . md5($active), $return); } return $return; }
public function getOrderStatuses($data = array()) { $cache = 'order_status.' . $this->config->get('language_id'); $data = Cache::find($cache); if (is_array($data) && count($data)) { return $data; } $data = $this->fetchAll("SELECT order_status_id, name FROM PREFIX_order_status WHERE language_id = :id ORDER BY name", array('id' => $this->config->get('language_id'))); Cache::set($cache, $data); return $data; }
public function getCountries() { $cache = 'countries'; $data = Cache::find($cache); if (is_array($cache) && count($cache)) { return $data; } $data = self::fetchAll("SELECT * FROM PREFIX_country WHERE status = 1 ORDER BY name ASC"); Cache::set($cache, $data); return $data; }
public function getTotalCategoriesByCategoryId($parent_id = 0) { $cacheFile = 'categories.totals-' . $parent_id . '-' . (int) $this->config->get('language-id') . '-' . (int) $this->config->get('store_id'); $cache = Cache::find($cacheFile); if (is_array($cache) && count($cache)) { return $cache; } $result = self::query("SELECT COUNT(*) AS total FROM PREFIX_category c LEFT JOIN PREFIX_category_to_store c2s ON (c.category_id = c2s.category_id) WHERE c.parent_id = '" . (int) $parent_id . "' AND c2s.store_id = '" . (int) $this->config->get('store_id') . "' AND c.status = '1'")->fetch(); Cache::set($cacheFile, $result); return $result; }
public function getLayout($route) { $cacheFile = 'settings.layouts.' . $this->config->get('config_store_id'); $cache = Cache::find($cacheFile, $route); if ($cache !== null) { return $cache; } $fallback = explode('/', $route); $result = Database::query("SELECT * FROM PREFIX_layout_route WHERE (:route LIKE CONCAT(route, '%') OR :fallback LIKE CONCAT(route, '%')) AND store_id = :store ORDER BY route DESC LIMIT 1", array('route' => $route, 'fallback' => $fallback[0] . '/', 'store' => $this->config->get('config_store_id')))->fetch(); Cache::set($cacheFile, $route, $result['layout_id']); return $result['layout_id']; }
public function __construct($registry) { $this->db = $registry->get('db'); $this->config = $registry->get('config'); $lengths = Cache::find('lengths.' . $this->config->get('config_language_id')); if (!is_array($lengths)) { $lengths = Database::fetchAll("SELECT * FROM PREFIX_length_class AS lc LEFT JOIN PREFIX_length_class_description AS lcd ON (lc.length_class_id = lcd.length_class_id) WHERE lcd.language_id = :lang", array('lang' => $this->config->get('config_language_id'))); Cache::set('lengths.' . $this->config->get('config_language_id'), $lengths); } foreach ($lengths as $result) { $this->lengths[$result['length_class_id']] = array('length_class_id' => $result['length_class_id'], 'title' => $result['title'], 'unit' => $result['unit'], 'value' => $result['value']); } }
public function __construct($registry) { $this->db = $registry->get('db'); $this->config = $registry->get('config'); $weights = Cache::find('weights.' . $this->config->get('config_language_id')); if (!is_array($weights)) { $weights = Database::fetchAll("SELECT * FROM PREFIX_weight_class AS wc LEFT JOIN PREFIX_weight_class_description AS wcd ON (wc.weight_class_id = wcd.weight_class_id) WHERE wcd.language_id = :lang", array('lang' => $this->config->get('config_language_id'))); Cache::set('weights.' . $this->config->get('config_language_id'), $weights); } foreach ($weights as $result) { $this->weights[$result['weight_class_id']] = array('weight_class_id' => $result['weight_class_id'], 'title' => $result['title'], 'unit' => $result['unit'], 'value' => $result['value']); } }
public static function getVar($key, $extra = array(), $updateTime = true) { // If, for instance, an error occures before the setup has fully loaded... if (isset(self::$language_id) && class_exists('Sumo\\Cache')) { $cache_string = 'language_' . self::$language_id; $cache = Cache::find($cache_string, $key); if ($cache) { return self::parse($cache, $extra); } $list = Database::query("\n SELECT value, key_id\n FROM PREFIX_translations\n RIGHT JOIN PREFIX_translations_keys\n ON PREFIX_translations.key_id = PREFIX_translations_keys.id\n WHERE language_id = " . self::$language_id . "\n AND name = :key\n ", array('key' => $key))->fetch(); if (isset($list['value'])) { if (empty($list['value'])) { $list['value'] = $key; } if ($updateTime) { Database::query("UPDATE PREFIX_translations_keys SET date_used = :date WHERE id = :id", array('id' => $list['key_id'], 'date' => date('Y-m-d H:i:s'))); } Cache::set($cache_string, $key, $list['value']); return self::parse($list['value'], $extra); } else { // Set the key as value $value = $key; // Check if the key is in the database $list2 = Database::query("SELECT id FROM PREFIX_translations_keys WHERE name = :key", array('key' => $key))->fetch(); // Totally new translation_key should be added if (!isset($list2['id'])) { Database::query("INSERT INTO PREFIX_translations_keys\n SET name = :key,\n date_added = :date", array('key' => $key, 'date' => date('Y-m-d H:i:s'))); } else { // Fallback language $list3 = Database::query("SELECT value FROM PREFIX_translations WHERE key_id = :id AND language_id = :lid", array('id' => $list2['id'], 'lid' => self::$language['fallback']))->fetch(); if (!empty($list3['value'])) { $value = $list3['value']; } else { // Absolute fallback, any translation that is not empty? $list3 = Database::query("SELECT value FROM PREFIX_translations WHERE key_id = :id AND value != '' LIMIT 1", array('id' => $list2['id']))->fetch(); if (isset($list3['value'])) { $value = $list3['value']; } } } if ($value != $key) { Cache::set($cache_string, $key, $value); } } } else { $value = $key; } return self::parse($value, $extra); }
public function getSetting($group, $store_id = 0) { $cacheFile = 'settings.' . $store_id . '.' . strtolower($group); $data = Cache::find($cacheFile); if (is_array($data) || count($data)) { return $data; } $data = array(); $result = Database::fetchAll("SELECT `key`, `value`, `serialized` FROM PREFIX_setting WHERE store_id = :id AND `group` = :group", array('id' => $store_id, 'group' => $group)); foreach ($result as $list) { $data[$list['key']] = $result['serialized'] ? unserialize($result['value']) : $result['value']; } Cache::set($cacheFile, $data); return $data; }
public function getManufacturers($data = array()) { if ($data) { $sql = "SELECT * FROM PREFIX_manufacturer m LEFT JOIN PREFIX_manufacturer_to_store m2s ON (m.manufacturer_id = m2s.manufacturer_id) WHERE m2s.store_id = :store"; $values = array(); $values['store'] = $this->config->get('store_id'); $sort_data = array('name', 'sort_order'); if (isset($data['sort']) && in_array($data['sort'], $sort_data)) { $sql .= " ORDER BY :sort"; $values['sort'] = $data['sort']; } else { $sql .= " ORDER BY name"; } if (isset($data['order']) && $data['order'] == 'DESC') { $sql .= " DESC"; } else { $sql .= " ASC"; } if (isset($data['start']) || isset($data['limit'])) { if ($data['start'] < 0) { $data['start'] = 0; } if ($data['limit'] < 1) { $data['limit'] = 20; } $values['start'] = $data['start']; $values['limit'] = $data['limit']; $sql .= " LIMIT :start,:limit"; } $result = Database::fetchAll($sql, $values); return $result; } else { $manufacturer_data = Cache::find('manufacturer.' . (int) $this->config->get('store_id')); if (!$manufacturer_data) { $manufacturer_data = Database::fetchAll("SELECT * FROM PREFIX_manufacturer m LEFT JOIN PREFIX_manufacturer_to_store m2s ON (m.manufacturer_id = m2s.manufacturer_id) WHERE m2s.store_id = :store ORDER BY name", array('store' => $this->config->get('store_id'))); Cache::set('manufacturer.' . (int) $this->config->get('store_id'), $manufacturer_data); } return $manufacturer_data; } }
public function index() { $this->load->model('catalog/manufacturer'); $this->load->model('tool/image'); $this->document->setTitle(Language::getVar('SUMO_NOUN_MANUFACTURER_PLURAL')); $this->data['heading_title'] = Language::getVar('SUMO_NOUN_MANUFACTURER_PLURAL'); $this->data['breadcrumbs'] = array(); $this->data['breadcrumbs'][] = array('text' => Language::getVar('SUMO_NOUN_HOME'), 'href' => $this->url->link('common/home'), 'separator' => false); $this->data['breadcrumbs'][] = array('text' => Language::getVar('SUMO_NOUN_MANUFACTURER_PLURAL'), 'href' => $this->url->link('product/manufacturer')); $this->data['manufacturers'] = array(); $cache = 'product.manufacturer.brand.overview'; $data = Cache::find($cache); if (!is_array($data) || !count($data)) { $results = $this->model_catalog_manufacturer->getManufacturers(); foreach ($results as $result) { if (is_numeric(utf8_substr($result['name'], 0, 1))) { $key = '0 - 9'; } else { $key = utf8_substr(utf8_strtoupper($result['name']), 0, 1); } if (!isset($this->data['manufacturers'][$key])) { $data[$key]['name'] = $key; } $result['href'] = $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $result['manufacturer_id']); $data[$key]['manufacturer'][] = $result; } Cache::set($cache, $data); } $this->data['manufacturers'] = $data; $this->data['settings'] = $this->config->get('details_product_category_' . $this->config->get('template')); if (!is_array($this->data['settings']) || !count($this->data['settings'])) { $this->data['settings']['left'][] = $this->getChild('app/widgetsimplesidebar/', array('type' => 'manufacturerTree')); $this->data['settings']['left'][] = $this->getChild('app/widgetsimplesidebar/', array('type' => 'banner', 'location' => 'category')); //$this->data['settings']['bottom'][] = $this->getChild('app/widgetsimpleproduct', array('type' => 'latest', 'limit' => 6, 'manufacturer_id' => $manufacturer_id)); } $this->template = 'product/manufacturer.tpl'; $this->children = array('common/column_left', 'common/column_right', 'common/content_top', 'common/content_bottom', 'common/footer', 'common/header'); $this->response->setOutput($this->render()); }
public function __construct($registry) { $this->config = $registry->get('config'); $this->language = $registry->get('language'); $this->request = $registry->get('request'); $this->session = $registry->get('session'); $currencies = Cache::find('currencies'); if (!is_array($currencies)) { $currencies = Database::fetchAll("SELECT * FROM PREFIX_currency"); Cache::set('currencies', $currencies); } foreach ($currencies as $result) { $this->currencies[$result['currency_id']] = $result; } if (isset($this->request->get['currency']) && array_key_exists($this->request->get['currency'], $this->currencies)) { $this->set($this->request->get['currency']); } elseif (isset($this->session->data['currency']) && array_key_exists($this->session->data['currency'], $this->currencies)) { $this->set($this->session->data['currency']); } elseif (isset($this->request->cookie['currency']) && array_key_exists($this->request->cookie['currency'], $this->currencies)) { $this->set($this->request->cookie['currency']); } else { $this->set($this->config->get('currency_id')); } }
public function getTotalReturns($data = array()) { unset($data['start']); unset($data['limit']); $cache = 'return_total_cached.' . json_encode($data); $data = Cache::find($cache); if (!is_array($data) || !count($data)) { $fetch = $this->getReturns($data); $data = count($fetch); Cache::set($cache, $data); } return $data; }
public function ajax() { // Contains results $bind = array(); $data = array(); if (isset($this->request->get['keyword'])) { // Parse all keywords to lowercase $keywords = strtolower($this->request->get['keyword']); // Perform search only if we have some keywords if (strlen($keywords) >= 2) { $cache = 'products.search.' . $keywords; $data = Cache::find($cache); if (!is_array($data) || !count($data)) { $this->load->model('catalog/product'); $data = array(); $parts = explode(' ', $keywords); $add = ''; // Generating search $partcount = 1; foreach ($parts as $part) { $part = '%' . strtolower($part) . '%'; $add .= ' AND (LOWER(pd.name) LIKE :part_' . $partcount; $bind['part_' . $partcount] = $part; $partcount++; $add .= ' OR LOWER(p.model) LIKE :part_' . $partcount; $bind['part_' . $partcount] = $part; $partcount++; $add .= ' OR LOWER(p.model_2) LIKE :part_' . $partcount; $bind['part_' . $partcount] = $part; $partcount++; $add .= ' OR LOWER(pd.tag) LIKE :part_' . $partcount; $bind['part_' . $partcount] = $part; $partcount++; $add .= ' )'; } $sql = 'SELECT pd.product_id FROM PREFIX_product_description AS pd LEFT JOIN PREFIX_product AS p ON p.product_id = pd.product_id LEFT JOIN PREFIX_product_to_store AS p2s ON p2s.product_id = pd.product_id WHERE 1 = 1 ' . $add . ' AND p.status = 1 AND pd.language_id = ' . (int) $this->config->get('language_id') . ' AND p2s.store_id = ' . (int) $this->config->get('store_id') . ' ORDER BY LOWER(tag) ASC, LOWER(pd.name) ASC, LOWER(p.model) ASC LIMIT 15'; $data = Database::fetchAll($sql, $bind); if ($data && count($data)) { $basehref = 'product/product&keyword=' . $this->request->get['keyword'] . '&product_id='; foreach ($data as $key => $list) { $product = $this->model_catalog_product->getProduct($list['product_id']); if ((!$product['stock_visible'] || $product['stock_visible'] == 2 && !$this->config->get('display_stock_empty')) && $product['quantity'] <= 0) { unset($data[$key]); continue; } $data[$key] = array('name' => htmlspecialchars_decode($product['name'], ENT_QUOTES), 'href' => $this->url->link('product/product', 'path=unknown&product_id=' . $product['product_id'] . '&keyword=' . $this->request->get['keyword'])); } } else { exit('meh, failure'); } Cache::set($cache, $data); } } } $this->response->setOutput(json_encode($data)); }
public function rewrite($link) { $link = str_replace('common/home', '', $link); $cache = Cache::find('rewrites', $link); if ($cache && !empty($cache)) { return $cache; } $url_info = parse_url(str_replace('&', '&', $link)); if (!empty($url_info['query'])) { $url_info['query'] .= '&'; } else { $url_info['query'] = ''; } if (!empty($url_info['path'])) { $url_info['query'] .= 'route=' . ltrim(str_replace('.html', '', $url_info['path']), '/'); } $url = ''; $data = array(); if (isset($url_info['query'])) { parse_str($url_info['query'], $data); foreach ($data as $key => $value) { if (isset($data['route'])) { if ($data['route'] == 'product/product' && $key == 'product_id' || ($data['route'] == 'product/manufacturer/info' || $data['route'] == 'product/product') && $key == 'manufacturer_id') { $product = Database::query("SELECT *\n FROM PREFIX_url_alias\n WHERE `query` = :query\n AND (\n language_id = :lang\n OR language_id = ''\n )", array('query' => $key . '=' . $value, 'lang' => $this->config->get('language_id')))->fetch(); if (is_array($product)) { $url = rtrim($url, '/') . '/' . strtolower($product['keyword']); $url_info['path'] = ''; unset($data[$key]); } } elseif ($key == 'path') { if ($value == 'unknown') { if (isset($data['product_id'])) { $check = Database::query("SELECT category_id FROM PREFIX_product_to_category WHERE product_id = :id ORDER BY category_id DESC LIMIT 1", array('id' => $data['product_id']))->fetch(); if (isset($check['category_id'])) { $path = Database::query("SELECT category_id, path_id, level FROM PREFIX_category_path WHERE path_id = :id", array('id' => $check['category_id']))->fetch(); if ($path['category_id'] == $path['path_id'] && $path['level'] == 0) { //$desc = Database::query("SELECT name FROM PREFIX_category_description WHERE category_id = :id AND language_id = :lang", array('id' => $check['category_id'], 'lang' => $this->config->get('language_id')))->fetch(); //$url = rtrim($url, '/') . '/' . strtolower($desc['name']) . '/'; $check = Database::query("SELECT * FROM PREFIX_url_alias WHERE `query` = 'category_id=" . (int) $check['category_id'] . "' AND language_id = :lang", array('lang' => $this->config->get('language_id')))->fetch(); if (is_array($check)) { $url = rtrim($url, '/') . '/' . strtolower($check['keyword']) . '/'; $url_info['path'] = ''; } $url_info['path'] = ''; } else { $paths = Database::fetchAll("SELECT path_id FROM PREFIX_category_path WHERE category_id = :id ORDER BY level ASC", array('id' => $path['category_id'])); foreach ($paths as $path) { $check = Database::query("SELECT * FROM PREFIX_url_alias WHERE `query` = 'category_id=" . (int) $path['path_id'] . "' AND language_id = :lang", array('lang' => $this->config->get('language_id')))->fetch(); if (is_array($check)) { $url = rtrim($url, '/') . '/' . strtolower($check['keyword']) . '/'; $url_info['path'] = ''; } //$url = rtrim($url, '/') . '/' . strtolower($desc['name']) . '/'; } //$url = rtrim($url, '/') . '/-iets-/'; } } } $url_info['path'] = ''; } else { $categories = explode('_', $value); foreach ($categories as $category) { $check = Database::query("SELECT * FROM PREFIX_url_alias WHERE `query` = 'category_id=" . (int) $category . "' AND language_id = :lang", array('lang' => $this->config->get('language_id')))->fetch(); if (is_array($check)) { $url = rtrim($url, '/') . '/' . strtolower($check['keyword']) . '/'; $url_info['path'] = ''; } } } unset($data[$key]); } else { if ($data['route'] == 'information/information' && $key == 'information_id') { $page = Database::query("SELECT *\n FROM PREFIX_url_alias\n WHERE `query` = :query\n AND (\n language_id = :lang\n OR language_id = ''\n )", array('query' => 'information_id=' . $value, 'lang' => $this->config->get('language_id')))->fetch(); if (is_array($page)) { // check for subpage $check = Database::query("\n SELECT parent_id\n FROM PREFIX_information\n WHERE information_id = " . (int) $value)->fetch(); if ($check['parent_id']) { $query2 = Database::query("\n SELECT *\n FROM PREFIX_url_alias\n WHERE `query` = :query\n AND (\n language_id = " . (int) $this->config->get('language_id') . "\n OR language_id = ''\n )", array('query' => $key . '=' . (int) $check['parent_id']))->fetch(); if (count($query2)) { $url = rtrim($url, '/') . '/' . $query2['keyword']; } } $url = rtrim($url, '/') . '/' . strtolower($page['keyword']); $url_info['path'] = ''; unset($data[$key]); } } else { if ($data['route'] == 'information/blog' && $key == 'blog_id') { $query = Database::query("\n SELECT *\n FROM PREFIX_url_alias\n WHERE `query` = :query\n AND (\n language_id = " . (int) $this->config->get('language_id') . "\n OR language_id = ''\n )", array('query' => $key . '=' . $value))->fetch(); if (count($query)) { $url = rtrim($url, '/') . '/blog/' . $query['keyword']; $url_info['path'] = ''; unset($data[$key]); } } } } } } } if ($url) { unset($data['route']); $query = ''; if ($data) { foreach ($data as $key => $value) { if (is_array($value)) { foreach ($value as $k => $v) { $query .= '&' . $key . '[' . $k . ']=' . $v; } } else { $query .= '&' . $key . '=' . $value; } } if ($query) { $query = '?' . trim($query, '&'); } } $return_url = str_replace('/index.php', '', $url_info['path']); $return_url = str_replace($url, '', $return_url) . $url . $query; Cache::set('rewrites', $link, $return_url); return $return_url; } else { Cache::set('rewrites', $link, $link); return $link; } }
protected function index($setting) { $this->language->load('module/latest'); $this->data['heading_title'] = $this->language->get('heading_title'); $this->data['button_cart'] = $this->language->get('button_cart'); $this->load->model('catalog/product'); $this->load->model('tool/image'); if ($this->registry->get('builder')) { $this->data['settings'] = Cache::find('builder', 'home'); $this->data['settings']['category'] = Cache::find('builder', 'category'); } if (isset($this->data['settings']['latest_products_limit'])) { $setting['limit'] = $this->data['settings']['latest_products_limit']; } $this->data['products'] = array(); $data = array('sort' => 'p.date_added', 'order' => 'DESC', 'start' => 0, 'limit' => $setting['limit']); $tmp = array(); if (isset($this->request->get['path'])) { $tmp = explode('_', $this->request->get['path']); } else { if (isset($this->request->get['category_id'])) { $tmp = explode('_', $this->request->get['category_id']); } } if (!count($tmp)) { } else { if (count($tmp) == 1) { $data['filter_category_id'] = $tmp[0]; } else { $data['filter_category_id'] = $tmp[0]; $data['filter_sub_category'] = $tmp[1]; } } $results = $this->model_catalog_product->getProducts($data); foreach ($results as $result) { if ($result['image']) { $image = $this->model_tool_image->resize($result['image'], $setting['image_width'], $setting['image_height']); } else { $image = false; } $swapimages = $this->model_catalog_product->getProductImages($result['product_id']); if ($swapimages) { $swapimage = $this->model_tool_image->resize($swapimages[0]['image'], $setting['image_width'], $setting['image_height']); } else { $swapimage = false; } if ($this->config->get('config_customer_price') && $this->customer->isLogged() || !$this->config->get('config_customer_price')) { $price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax'))); } else { $price = false; } if ((double) $result['special']) { $special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax'))); } else { $special = false; } if ($this->config->get('config_review_status')) { $rating = $result['rating']; } else { $rating = false; } if (!empty($result['parent_id'])) { $result['category_id'] .= '_' . $result['parent_id']; } $this->data['products'][] = array('product_id' => $result['product_id'], 'thumb' => $image, 'thumb_swap' => $swapimage, 'name' => $result['name'], 'price' => $price, 'special' => $special, 'rating' => $rating, 'reviews' => sprintf($this->language->get('text_reviews'), (int) $result['reviews']), 'href' => $this->url->link('product/product', 'path=' . $result['category_id'] . '&product_id=' . $result['product_id'])); } if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/latest.tpl')) { $this->template = $this->config->get('config_template') . '/template/module/latest.tpl'; } else { $this->template = 'default/template/module/latest.tpl'; } $this->render(); }
public function getProductRelated($product_id) { $products = Cache::find('products.related.' . $product_id); if (!is_array($products)) { $product_ids = Database::fetchAll("\n SELECT *\n FROM PREFIX_product_related AS pr\n LEFT JOIN PREFIX_product AS p\n ON (pr.related_id = p.product_id)\n LEFT JOIN PREFIX_product_to_store AS p2s\n ON (p.product_id = p2s.product_id)\n WHERE pr.product_id = '" . (int) $product_id . "'\n AND p.status = '1'\n AND p2s.store_id = '" . (int) $this->config->get('store_id') . "'"); $products = array(); foreach ($product_ids as $list) { $products[] = $this->getProduct($list['product_id']); } Cache::set('products.related.' . $product_id, $products); } return $products; }
public function getInformationParents($store_id) { $cache = 'cms_information.parents.' . $store_id; $items = Cache::find($cache); if (is_array($items) && count($items)) { return $items; } $items = array(); $data = $this->fetchAll("SELECT i.information_id, id.title\n FROM PREFIX_information AS i\n LEFT JOIN PREFIX_information_description AS id\n ON i.information_id = id.information_id\n LEFT JOIN PREFIX_information_to_store AS its\n ON i.information_id = its.information_id\n WHERE i.parent_id = 0\n AND id.language_id = :lang\n AND its.store_id = :store", array('lang' => $this->config->get('language_id'), 'store' => $store_id)); foreach ($data as $list) { $items[$list['information_id']] = $list['title']; } Cache::set($cache, $items); return $items; }
public function getProductStores($product_id) { $cache = 'products.stores.' . $product_id; $return = Cache::find($cache); if (is_array($return) && count($return)) { return $return; } $product_store_data = array(); $query = $this->fetchAll("SELECT * FROM PREFIX_product_to_store WHERE product_id = " . (int) $product_id); foreach ($query as $result) { $product_store_data[] = $result['store_id']; } Cache::set($cache, $product_store_data); return $product_store_data; }
public function getCategoriesAsList($parentID = 0, $level = 0) { if ($parentID == 0) { $cache = Cache::find('category_as_list'); if (is_array($cache) && count($cache)) { return $cache; } } $sql = "\n SELECT c.category_id, cts.store_id, cd.name, c.sort_order, parent_id, c.status, cd.meta_description, cd.description, cd.meta_keyword\n FROM PREFIX_category AS c\n LEFT JOIN PREFIX_category_to_store AS cts\n ON cts.category_id = c.category_id\n LEFT JOIN PREFIX_category_description AS cd\n ON cd.category_id = c.category_id\n WHERE parent_id = " . (int) $parentID . "\n AND cd.language_id = '" . (int) $this->config->get('language_id') . "'\n ORDER BY parent_id, sort_order"; $query = $this->query($sql); $return = array(); foreach ($query->fetchAll() as $row) { $row['level'] = $level; $return[] = $row; if (($subCategories = $this->getCategoriesAsList($row['category_id'], $level + 1)) !== false) { $return = array_merge($return, $subCategories); } } if ($parentID == 0) { Cache::set('category_as_list', $return); return $return; } if (empty($return)) { return false; } return $return; }
public function getLanguages($data = array()) { if (count($data)) { $sql = "SELECT * FROM PREFIX_language "; $sort_data = array('name', 'code', 'sort_order'); if (isset($data['sort']) && in_array($data['sort'], $sort_data)) { $sql .= " ORDER BY " . $data['sort']; } else { $sql .= " ORDER BY sort_order, name"; } if (isset($data['order']) && $data['order'] == 'DESC') { $sql .= " DESC"; } else { $sql .= " ASC"; } if (isset($data['start']) || isset($data['limit'])) { if ($data['start'] < 0) { $data['start'] = 0; } if ($data['limit'] < 1) { $data['limit'] = 20; } $sql .= " LIMIT " . (int) $data['start'] . "," . (int) $data['limit']; } return $this->fetchAll($sql); } else { $language_data = Cache::find('language'); if (!$language_data || !count($language_data)) { $language_data = array(); $default_language = $this->config->get('language_id'); $query = $this->fetchAll("SELECT * FROM PREFIX_language WHERE status = 1 ORDER BY sort_order, name"); foreach ($query as $result) { $result['is_default'] = $default_language == $result['language_id'] ? true : false; $language_data[$result['language_id']] = $result; } Cache::set('language', $language_data); } return $language_data; } }