1roma1 Опубліковано: 17 лютого 2012 Share Опубліковано: 17 лютого 2012 Всем привет! Собственно наткнулся на такую проблему/недоработку пока не знаю как назвать. Версия OcStore 0.2.2. Есть каталог продукции с установленной ценой. Например на 2 месяца устанавливаю специальную цену. Она может быть разной относительно первоначальной одинаковой цены в похожих моделях. Например есть 2 товара по цене 700. На один делаю скидку 100, на другой 150. Итого новые цены выходят 600 и 550 соответственно. Проблема заключается в том, что когда в каталоге выбираю сортировку по цене, скрипт сортирует относительно первоначальной цены, без учета специальной. Т.е. таким образом: 700 600, 700 550, 720 610, 740 630, 750 650. Вопрос: это у всех так или только у меня? И если у всех, то кто-то может подсказать как это решить? Поиском пользовался, решений не нашел. Спасибо. Надіслати Поділитися на інших сайтах More sharing options...
freelancer Опубліковано: 17 лютого 2012 Share Опубліковано: 17 лютого 2012 у всех. у меня есть мысли, но решение будет работать чуть медленнее Надіслати Поділитися на інших сайтах More sharing options... freelancer Опубліковано: 17 лютого 2012 Share Опубліковано: 17 лютого 2012 *************** *** 14,19 **** --- 14,33 ---- public function getProductsByCategoryId($category_id, $sort = 'p.sort_order', $order = 'ASC', $start = 0, $limit = 20) { $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) LEFT JOIN " . DB_PREFIX . "product_to_category p2c ON (p.product_id = p2c.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2c.category_id = '" . (int)$category_id . "'"; + + if ($sort=='p.price'){ + + if ($this->customer->isLogged()) { + $customer_group_id = $this->customer->getCustomerGroupId(); + } else { + $customer_group_id = $this->config->get('config_customer_group_id'); + } + + $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating, ". + "coalesce((SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND customer_group_id = '" . (int)$customer_group_id . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY priority ASC, price ASC LIMIT 1), p.price) as s_price ". + "FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) LEFT JOIN " . DB_PREFIX . "product_to_category p2c ON (p.product_id = p2c.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2c.category_id = '" . (int)$category_id . "'"; + $sort = 's_price'; + } $sort_data = array( 'pd.name', *************** *** 21,26 **** --- 35,41 ---- 'special', 'rating', 'p.price', + 's_price', 'p.model' ); Надіслати Поділитися на інших сайтах More sharing options... 1roma1 Опубліковано: 18 лютого 2012 Автор Share Опубліковано: 18 лютого 2012 Спасибо большое за оперативность! Мне только не совсем понятно назначение чисел *** 14,19 **** --- 14,33 ---- *** 21,26 **** --- 35,41 ---- извините, я не программист. Ясно только что править нужно файл catalog/model/catalog/product.php начиная с 14й строки. Вы бы не могли дать буквенные пояснения к этим числам?) Надіслати Поділитися на інших сайтах More sharing options... freelancer Опубліковано: 19 лютого 2012 Share Опубліковано: 19 лютого 2012 да это я diff сделал. номера строк кажется. строки где + добавить Надіслати Поділитися на інших сайтах More sharing options... 4 weeks later... Petr Опубліковано: 13 березня 2012 Share Опубліковано: 13 березня 2012 да это я diff сделал. номера строк кажется. строки где + добавить Добрый день, Скажите а как должен выглядеть код для 1.5.1.3 я попытался добавить но не получилось.? Надіслати Поділитися на інших сайтах More sharing options... freelancer Опубліковано: 14 березня 2012 Share Опубліковано: 14 березня 2012 Добрый день, Скажите а как должен выглядеть код для 1.5.1.3 я попытался добавить но не получилось.?я описал для версии 0.2.2, для 1.5.1.3 не подойдет 1 Надіслати Поділитися на інших сайтах More sharing options... 1roma1 Опубліковано: 15 березня 2012 Автор Share Опубліковано: 15 березня 2012 Извините что так долго не отписывал, был в разъездах, не было возможности проверить. Код представленный здесь действительно работает, и сортирует товар по ценам с учетом текущей акционной цены, но только в каталоге. Если зайти в производители, сортирует по старому. Может еще где-то куда-то что-то нужно прописать? Надіслати Поділитися на інших сайтах More sharing options... freelancer Опубліковано: 15 березня 2012 Share Опубліковано: 15 березня 2012 Извините что так долго не отписывал, был в разъездах, не было возможности проверить. Код представленный здесь действительно работает, и сортирует товар по ценам с учетом текущей акционной цены, но только в каталоге. Если зайти в производители, сортирует по старому. Может еще где-то куда-то что-то нужно прописать? да. в том же файле точно такие же операции следует проделать в методе getProductsByManufacturerId Надіслати Поділитися на інших сайтах More sharing options... 1roma1 Опубліковано: 15 березня 2012 Автор Share Опубліковано: 15 березня 2012 сделал, но в производителях по-прежнему не работает. выдает ошибку: Notice: Undefined variable: category_id in Z:\home\localhost\www\nb2\catalog\model\catalog\product.php on line 80 ругается на вот это: $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating, ". "coalesce((SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND customer_group_id = '" . (int)$customer_group_id . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY priority ASC, price ASC LIMIT 1), p.price) as s_price ". "FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) LEFT JOIN " . DB_PREFIX . "product_to_category p2c ON (p.product_id = p2c.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2c.category_id = '" . (int)$category_id . "'"; Надіслати Поділитися на інших сайтах More sharing options... freelancer Опубліковано: 16 березня 2012 Share Опубліковано: 16 березня 2012 сделал, но в производителях по-прежнему не работает. выдает ошибку: Notice: Undefined variable: category_id in Z:\home\localhost\www\nb2\catalog\model\catalog\product.php on line 80 возможно я не так выразился.. не нужно было копировать всё.. только разницу public function getProductsByManufacturerId($manufacturer_id, $sort = 'p.sort_order', $order = 'ASC', $start = 0, $limit = 20) { $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND m.manufacturer_id = '" . (int)$manufacturer_id . "'"; if ($sort == 'p.price') { if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating," . "coalesce((SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND customer_group_id = '" . (int)$customer_group_id . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY priority ASC, price ASC LIMIT 1), p.price) as s_price " . " FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND m.manufacturer_id = '" . (int)$manufacturer_id . "'"; $sort = 's_price'; } $sort_data = array( 'pd.name', 'p.sort_order', 'special', 'rating', 's_price', 'p.model' ); 1 Надіслати Поділитися на інших сайтах More sharing options... 1roma1 Опубліковано: 16 березня 2012 Автор Share Опубліковано: 16 березня 2012 (змінено) Спасибо большое! все работает! В блоке $sort_data = array нужно было не добавить 's_price', а заменить ним 'p.price'. Полный код рабочего файла catalog/model/catalog/product.php представил ниже, может кому пригодится (версия OcStore 0.2.2!). <?php class ModelCatalogProduct extends Model { public function getProduct($product_id) { $query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.product_id = '" . (int)$product_id . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.date_available <= NOW() AND p.status = '1'"); return $query->row; } public function getProducts() { $query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, wcd.unit AS weight_class FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) LEFT JOIN " . DB_PREFIX . "weight_class_description wcd ON (p.weight_class_id = wcd.weight_class_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND wcd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.date_available <= NOW() AND p.status = '1'"); return $query->rows; } public function getProductsByCategoryId($category_id, $sort = 'p.sort_order', $order = 'ASC', $start = 0, $limit = 20) { $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) LEFT JOIN " . DB_PREFIX . "product_to_category p2c ON (p.product_id = p2c.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2c.category_id = '" . (int)$category_id . "'"; if ($sort=='p.price'){ if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating, ". "coalesce((SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND customer_group_id = '" . (int)$customer_group_id . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY priority ASC, price ASC LIMIT 1), p.price) as s_price ". "FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) LEFT JOIN " . DB_PREFIX . "product_to_category p2c ON (p.product_id = p2c.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2c.category_id = '" . (int)$category_id . "'"; $sort = 's_price'; } $sort_data = array( 'pd.name', 'p.sort_order', 'special', 'rating', 'p.price', 's_price', 'p.model' ); if (in_array($sort, $sort_data)) { if ($sort == 'pd.name' || $sort == 'p.model') { $sql .= " ORDER BY LCASE(" . $sort . ")"; } else { $sql .= " ORDER BY " . $sort; } } else { $sql .= " ORDER BY p.sort_order"; } if ($order == 'DESC') { $sql .= " DESC"; } else { $sql .= " ASC"; } if ($start < 0) { $start = 0; } $sql .= " LIMIT " . (int)$start . "," . (int)$limit; $query = $this->db->query($sql); return $query->rows; } public function getTotalProductsByCategoryId($category_id = 0) { $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product_to_category p2c LEFT JOIN " . DB_PREFIX . "product p ON (p2c.product_id = p.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND p2c.category_id = '" . (int)$category_id . "'"); return $query->row['total']; } public function getProductsByManufacturerId($manufacturer_id, $sort = 'p.sort_order', $order = 'ASC', $start = 0, $limit = 20) { $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND m.manufacturer_id = '" . (int)$manufacturer_id. "'"; if ($sort == 'p.price') { if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating," . "coalesce((SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND customer_group_id = '" . (int)$customer_group_id . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY priority ASC, price ASC LIMIT 1), p.price) as s_price " . " FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND m.manufacturer_id = '" . (int)$manufacturer_id . "'"; $sort = 's_price'; } $sort_data = array( 'pd.name', 'p.sort_order', 'special', 'rating', 's_price', 'p.model' ); if (in_array($sort, $sort_data)) { if ($sort == 'pd.name' || $sort == 'p.model') { $sql .= " ORDER BY LCASE(" . $sort . ")"; } else { $sql .= " ORDER BY " . $sort; } } else { $sql .= " ORDER BY p.sort_order"; } if ($order == 'DESC') { $sql .= " DESC"; } else { $sql .= " ASC"; } if ($start < 0) { $start = 0; } $sql .= " LIMIT " . (int)$start . "," . (int)$limit; $query = $this->db->query($sql); return $query->rows; } public function getTotalProductsByManufacturerId($manufacturer_id = 0) { $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product WHERE status = '1' AND date_available <= NOW() AND manufacturer_id = '" . (int)$manufacturer_id . "'"); return $query->row['total']; } public function getProductsByTag($tag, $category_id = 0, $sort = 'p.sort_order', $order = 'ASC', $start = 0, $limit = 20) { if ($tag) { $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_tags pt ON (p.product_id = pt.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND pt.language_id = '" . (int)$this->config->get('config_language_id') . "' AND (pt.tag = '" . $this->db->escape($tag) . "'"; $keywords = explode(" ", $tag); foreach ($keywords as $keyword) { $sql .= " OR pt.tag = '" . $this->db->escape($keyword) . "'"; } $sql .= ")"; if ($category_id) { $data = array(); $this->load->model('catalog/category'); $string = rtrim($this->getPath($category_id), ','); foreach (explode(',', $string) as $category_id) { $data[] = "category_id = '" . (int)$category_id . "'"; } $sql .= " AND p.product_id IN (SELECT product_id FROM " . DB_PREFIX . "product_to_category WHERE " . implode(" OR ", $data) . ")"; } $sql .= " AND p.status = '1' AND p.date_available <= NOW() GROUP BY p.product_id"; $sort_data = array( 'pd.name', 'p.sort_order', 'special', 'rating', 'p.price', 'p.model' ); if (in_array($sort, $sort_data)) { if ($sort == 'pd.name' || $sort == 'p.model') { $sql .= " ORDER BY LCASE(" . $sort . ")"; } else { $sql .= " ORDER BY " . $sort; } } else { $sql .= " ORDER BY p.sort_order"; } if ($order == 'DESC') { $sql .= " DESC"; } else { $sql .= " ASC"; } if ($start < 0) { $start = 0; } $sql .= " LIMIT " . (int)$start . "," . (int)$limit; $query = $this->db->query($sql); $products = array(); foreach ($query->rows as $key => $value) { $products[$value['product_id']] = $this->getProduct($value['product_id']); } return $products; } } public function getProductsByKeyword($keyword, $category_id = 0, $description = FALSE, $model = FALSE, $sort = 'p.sort_order', $order = 'ASC', $start = 0, $limit = 20) { if ($keyword) { $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "'"; if (!$description) { $sql .= " AND (pd.name LIKE '%" . $this->db->escape($keyword) . "%'"; } else { $sql .= " AND (pd.name LIKE '%" . $this->db->escape($keyword) . "%' OR pd.description LIKE '%" . $this->db->escape($keyword) . "%'"; } if (!$model) { $sql .= ")"; } else { $sql .= " OR p.model LIKE '%" . $this->db->escape($keyword) . "%')"; } if ($category_id) { $data = array(); $this->load->model('catalog/category'); $string = rtrim($this->getPath($category_id), ','); foreach (explode(',', $string) as $category_id) { $data[] = "category_id = '" . (int)$category_id . "'"; } $sql .= " AND p.product_id IN (SELECT product_id FROM " . DB_PREFIX . "product_to_category WHERE " . implode(" OR ", $data) . ")"; } $sql .= " AND p.status = '1' AND p.date_available <= NOW() GROUP BY p.product_id"; $sort_data = array( 'pd.name', 'p.sort_order', 'special', 'rating', 'p.price', 'p.model' ); if (in_array($sort, $sort_data)) { if ($sort == 'pd.name' || $sort == 'p.model') { $sql .= " ORDER BY LCASE(" . $sort . ")"; } else { $sql .= " ORDER BY " . $sort; } } else { $sql .= " ORDER BY p.sort_order"; } if ($order == 'DESC') { $sql .= " DESC"; } else { $sql .= " ASC"; } if ($start < 0) { $start = 0; } $sql .= " LIMIT " . (int)$start . "," . (int)$limit; $query = $this->db->query($sql); return $query->rows; } return 0; } public function getTotalProductsByKeyword($keyword, $category_id = 0, $description = FALSE, $model = FALSE) { if ($keyword) { $sql = "SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "'"; if (!$description) { $sql .= " AND (pd.name LIKE '%" . $this->db->escape($keyword) . "%'"; } else { $sql .= " AND (pd.name LIKE '%" . $this->db->escape($keyword) . "%' OR pd.description LIKE '%" . $this->db->escape($keyword) . "%'"; } if (!$model) { $sql .= ")"; } else { $sql .= " OR p.model LIKE '%" . $this->db->escape($keyword) . "%')"; } if ($category_id) { $data = array(); $this->load->model('catalog/category'); $string = rtrim($this->getPath($category_id), ','); foreach (explode(',', $string) as $category_id) { $data[] = "category_id = '" . (int)$category_id . "'"; } $sql .= " AND p.product_id IN (SELECT product_id FROM " . DB_PREFIX . "product_to_category WHERE " . implode(" OR ", $data) . ")"; } $sql .= " AND p.status = '1' AND p.date_available <= NOW()"; $query = $this->db->query($sql); if ($query->num_rows) { return $query->row['total']; } else { return 0; } } return 0; } public function getTotalProductsByTag($tag, $category_id = 0) { if ($tag) { $sql = "SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_tags pt ON (p.product_id = pt.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND pt.language_id = '" . (int)$this->config->get('config_language_id') . "' AND (pt.tag = '" . $this->db->escape($tag) . "'"; $keywords = explode(" ", $tag); foreach ($keywords as $keyword) { $sql .= " OR pt.tag = '" . $this->db->escape($keyword) . "'"; } $sql .= ")"; if ($category_id) { $data = array(); $this->load->model('catalog/category'); $string = rtrim($this->getPath($category_id), ','); foreach (explode(',', $string) as $category_id) { $data[] = "category_id = '" . (int)$category_id . "'"; } $sql .= " AND p.product_id IN (SELECT product_id FROM " . DB_PREFIX . "product_to_category WHERE " . implode(" OR ", $data) . ")"; } $sql .= " AND p.status = '1' AND p.date_available <= NOW()"; $query = $this->db->query($sql); if ($query->num_rows) { return $query->row['total']; } else { return 0; } } return 0; } public function getPath($category_id) { $string = $category_id . ','; $results = $this->model_catalog_category->getCategories($category_id); foreach ($results as $result) { $string .= $this->getPath($result['category_id']); } return $string; } public function getLatestProducts($limit) { $product_data = $this->cache->get('product.latest.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit); if (!$product_data) { $query = $this->db->query("SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY p.date_added DESC LIMIT " . (int)$limit); $product_data = $query->rows; $this->cache->set('product.latest.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit, $product_data); } return $product_data; } public function getPopularProducts($limit) { $query = $this->db->query("SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY p.viewed, p.date_added DESC LIMIT " . (int)$limit); return $query->rows; } public function getFeaturedProducts($limit) { $product_data = $this->cache->get('product.featured.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit); if (!$product_data) { $query = $this->db->query("SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product_featured f LEFT JOIN " . DB_PREFIX . "product p ON (f.product_id=p.product_id) LEFT JOIN " . DB_PREFIX . "product_description pd ON (f.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' LIMIT " . (int)$limit); $product_data = $query->rows; $this->cache->set('product.featured.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit, $product_data); } return $product_data; } public function getBestSellerProducts($limit) { $product_data = $this->cache->get('product.bestseller.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit); if (!$product_data) { $product_data = array(); $query = $this->db->query("SELECT op.product_id, SUM(op.quantity) AS total, p.status FROM " . DB_PREFIX . "order_product op LEFT JOIN `" . DB_PREFIX . "order` o ON (op.order_id = o.order_id) LEFT JOIN `" . DB_PREFIX . "product` p ON (op.product_id = p.product_id) WHERE o.order_status_id > '0' AND p.status = '1' GROUP BY op.product_id, p.status ORDER BY total DESC LIMIT " . (int)$limit); foreach ($query->rows as $result) { $product_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE p.product_id = '" . (int)$result['product_id'] . "' AND p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "'"); if ($product_query->num_rows) { $product_data[] = $product_query->row; } } $this->cache->set('product.bestseller.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit, $product_data); } return $product_data; } public function updateViewed($product_id) { $this->db->query("UPDATE " . DB_PREFIX . "product SET viewed = viewed + 1 WHERE product_id = '" . (int)$product_id . "'"); } public function getProductOptions($product_id) { $product_option_data = array(); $product_option_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option WHERE product_id = '" . (int)$product_id . "' ORDER BY sort_order"); foreach ($product_option_query->rows as $product_option) { $product_option_value_data = array(); $product_option_value_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option_value WHERE product_option_id = '" . (int)$product_option['product_option_id'] . "' ORDER BY sort_order"); foreach ($product_option_value_query->rows as $product_option_value) { $product_option_value_description_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option_value_description WHERE product_option_value_id = '" . (int)$product_option_value['product_option_value_id'] . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'"); $product_option_value_data[] = array( 'product_option_value_id' => $product_option_value['product_option_value_id'], 'name' => $product_option_value_description_query->row['name'], 'price' => $product_option_value['price'], 'prefix' => $product_option_value['prefix'], 'quantity' => $product_option_value['quantity'] /* webme - options show|hide - mod */ ); } $product_option_description_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option_description WHERE product_option_id = '" . (int)$product_option['product_option_id'] . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'"); $product_option_data[] = array( 'product_option_id' => $product_option['product_option_id'], 'name' => $product_option_description_query->row['name'], 'option_value' => $product_option_value_data, 'sort_order' => $product_option['sort_order'] ); } return $product_option_data; } public function getProductImages($product_id) { $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_image WHERE product_id = '" . (int)$product_id . "'"); return $query->rows; } public function getProductTags($product_id) { $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_tags WHERE product_id = '" . (int)$product_id . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'"); return $query->rows; } public function getProductDiscount($product_id) { if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $query = $this->db->query("SELECT price FROM " . DB_PREFIX . "product_discount WHERE product_id = '" . (int)$product_id . "' AND customer_group_id = '" . (int)$customer_group_id . "' AND quantity = '1' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY priority ASC, price ASC LIMIT 1"); if ($query->num_rows) { return $query->row['price']; } else { return FALSE; } } public function getProductDiscounts($product_id) { if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_discount WHERE product_id = '" . (int)$product_id . "' AND customer_group_id = '" . (int)$customer_group_id . "' AND quantity > 1 AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY quantity ASC, priority ASC, price ASC"); return $query->rows; } public function getProductSpecial($product_id) { if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $query = $this->db->query("SELECT price FROM " . DB_PREFIX . "product_special WHERE product_id = '" . (int)$product_id . "' AND customer_group_id = '" . (int)$customer_group_id . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY priority ASC, price ASC LIMIT 1"); if ($query->num_rows) { return $query->row['price']; } else { return FALSE; } } public function getProductSpecials($sort = 'p.sort_order', $order = 'ASC', $start = 0, $limit = 20) { if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $sql = "SELECT *, pd.name AS name, p.price, (SELECT ps2.price FROM " . DB_PREFIX . "product_special ps2 WHERE p.product_id = ps2.product_id AND ps2.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps2.date_start = '0000-00-00' OR ps2.date_start < NOW()) AND (ps2.date_end = '0000-00-00' OR ps2.date_end > NOW())) ORDER BY ps2.priority ASC, ps2.price ASC LIMIT 1) AS special, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "product_special ps ON (p.product_id = ps.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND ps.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW())AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) AND ps.product_id NOT IN (SELECT pd2.product_id FROM " . DB_PREFIX . "product_discount pd2 WHERE p.product_id = pd2.product_id AND pd2.customer_group_id = '" . (int)$customer_group_id . "' AND pd2.quantity = '1' AND ((pd2.date_start = '0000-00-00' OR pd2.date_start < NOW()) AND (pd2.date_end = '0000-00-00' OR pd2.date_end > NOW()))) GROUP BY p.product_id"; $sort_data = array( 'pd.name', 'p.sort_order', 'special', 'rating', 'p.price', 'p.model' ); if (in_array($sort, $sort_data)) { if ($sort == 'pd.name' || $sort == 'p.model') { $sql .= " ORDER BY LCASE(" . $sort . ")"; } else { $sql .= " ORDER BY " . $sort; } } else { $sql .= " ORDER BY p.sort_order"; } if ($order == 'DESC') { $sql .= " DESC"; } else { $sql .= " ASC"; } if ($start < 0) { $start = 0; } $sql .= " LIMIT " . (int)$start . "," . (int)$limit; $query = $this->db->query($sql); return $query->rows; } public function getTotalProductSpecials() { if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $query = $this->db->query("SELECT COUNT(DISTINCT ps.product_id) AS total FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "product_special ps ON (p.product_id = ps.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) AND ps.product_id NOT IN (SELECT pd2.product_id FROM " . DB_PREFIX . "product_discount pd2 WHERE p.product_id = pd2.product_id AND pd2.customer_group_id = '" . (int)$customer_group_id . "' AND pd2.quantity = '1' AND ((pd2.date_start = '0000-00-00' OR pd2.date_start < NOW()) AND (pd2.date_end = '0000-00-00' OR pd2.date_end > NOW())))"); if (isset($query->row['total'])) { return $query->row['total']; } else { return 0; } } public function getProductRelated($product_id) { $product_data = array(); $product_related_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$product_id . "'"); foreach ($product_related_query->rows as $result) { $product_query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.product_id = '" . (int)$result['related_id'] . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.date_available <= NOW() AND p.status = '1'"); if ($product_query->num_rows) { $product_data[$result['related_id']] = $product_query->row; } } return $product_data; } public function getCategories($product_id) { $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_to_category WHERE product_id = '" . (int)$product_id . "'"); return $query->rows; } } ?> Тему можно закрыть с пометкой решено и сделать на нее ссылку в FAQ) Змінено 16 березня 2012 користувачем 1roma1 Надіслати Поділитися на інших сайтах More sharing options... freelancer Опубліковано: 16 березня 2012 Share Опубліковано: 16 березня 2012 Спасибо большое! все работает! В блоке $sort_data = array нужно было не добавить 's_price', а заменить ним 'p.price'. .. это вовсе не обязательно. важное исправление было в другом месте.ну да не суть Надіслати Поділитися на інших сайтах More sharing options... DAN Опубліковано: 22 березня 2012 Share Опубліковано: 22 березня 2012 я описал для версии 0.2.2, для 1.5.1.3 не подойдет А для версии 1.5.1.3 как сделать не подскажите? Надіслати Поділитися на інших сайтах More sharing options... 7 months later... mybay Опубліковано: 31 жовтня 2012 Share Опубліковано: 31 жовтня 2012 большое спасибо! и мне помогло))) Надіслати Поділитися на інших сайтах More sharing options... 7 months later... hon2012 Опубліковано: 10 червня 2013 Share Опубліковано: 10 червня 2013 Добрый день, Скажите а как должен выглядеть код для 1.5.1.3 я попытался добавить но не получилось.?я описал для версии 0.2.2, для 1.5.1.3 не подойдет Уважаемый freelancer, подскажите как сделать для версии 1.5.13 Спасибо Надіслати Поділитися на інших сайтах More sharing options... freelancer Опубліковано: 10 червня 2013 Share Опубліковано: 10 червня 2013 по аналогии. разжевывать не буду Надіслати Поділитися на інших сайтах More sharing options... 3 months later... NoobMan Опубліковано: 7 жовтня 2013 Share Опубліковано: 7 жовтня 2013 Всем привет! Собственно наткнулся на такую проблему/недоработку пока не знаю как назвать. Версия OcStore 0.2.2. Есть каталог продукции с установленной ценой. Например на 2 месяца устанавливаю специальную цену. Она может быть разной относительно первоначальной одинаковой цены в похожих моделях. Например есть 2 товара по цене 700. На один делаю скидку 100, на другой 150. Итого новые цены выходят 600 и 550 соответственно. Проблема заключается в том, что когда в каталоге выбираю сортировку по цене, скрипт сортирует относительно первоначальной цены, без учета специальной. Т.е. таким образом: 700 600, 700 550, 720 610, 740 630, 750 650. Вопрос: это у всех так или только у меня? И если у всех, то кто-то может подсказать как это решить? Поиском пользовался, решений не нашел. Спасибо. Для opencart 1.5.4.1 решение не подскажите? Надіслати Поділитися на інших сайтах More sharing options... 1 year later... Marinka Опубліковано: 11 квітня 2015 Share Опубліковано: 11 квітня 2015 Да, для 1.5.4.1 тоже не могу найти решение! хэлп!!! Надіслати Поділитися на інших сайтах More sharing options... 1 year later... newjey Опубліковано: 11 січня 2017 Share Опубліковано: 11 січня 2017 Подскажите под ocStore 2.1.0.2 как сделать сортировку с учётом акционной цены? Надіслати Поділитися на інших сайтах More sharing options... Створіть аккаунт або увійдіть для коментування Ви повинні бути користувачем, щоб залишити коментар Створити обліковий запис Зареєструйтеся для отримання облікового запису. Це просто! Зареєструвати аккаунт Вхід Уже зареєстровані? Увійдіть тут. Вхід зараз Share More sharing options... Передплатники 0 Перейти до списку тем Зараз на сторінці 0 користувачів Ні користувачів, які переглядиють цю сторінку Последние темы Последние дополнения Последние новости Вся активність Головна Підтримка та відповіді на запитання. Встановлення, оновлення, налаштування Сортировка товаров по цене с учетом скидок Покупцям Оплата розширень фізичними особами Оплата розширень юридичними особами Політика повернень Розробникам Регламент розміщення розширень Регламент продажу та підтримки розширень Віртуальний обліковий запис автора Політика просування оголошень API каталогу розширень Вирішення спорів щодо авторських прав Корисна інформація Публічна оферта Політика повернень Політика конфіденційності Платіжна політика Політика передачі особистих даних Політика прозорості Останні розширення Повний пакет SEO Автор: GeekoDev SameSite Session Fix Opencart 3 Автор: web_bond SP Telegram повідомлення FREE Автор: spectre Відключити порожні категорії Автор: spectre SEO Автор тексту категорії / фільтра / блогу з датою оновлення контенту + мікророзмітка Автор: radaevich × Уже зареєстровані? Ввійти Реєстрація Ваші замовлення Назад Придбані модулі та шаблони Ваші рахунки Лист очікувань Альтернативні контакти Форум Новини ocStore Назад Офіційний сайт Демо ocStore 3.0.3.2 Демо ocStore 2.3.0.2.4 Завантажити ocStore Документація Історія версій ocStore Блоги Модулі Шаблони Назад Безкоштовні шаблони Платні шаблони Де купувати модулі? Послуги FAQ OpenCart.Pro Назад Демо Купити Порівняння × Створити... Important Information На нашому сайті використовуються файли cookie і відбувається обробка деяких персональних даних користувачів, щоб поліпшити користувальницький інтерфейс. Щоб дізнатися для чого і які персональні дані ми обробляємо перейдіть за посиланням . Якщо Ви натиснете «Я даю згоду», це означає, що Ви розумієте і приймаєте всі умови, зазначені в цьому Повідомленні про конфіденційність. Я даю згоду
freelancer Опубліковано: 17 лютого 2012 Share Опубліковано: 17 лютого 2012 *************** *** 14,19 **** --- 14,33 ---- public function getProductsByCategoryId($category_id, $sort = 'p.sort_order', $order = 'ASC', $start = 0, $limit = 20) { $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) LEFT JOIN " . DB_PREFIX . "product_to_category p2c ON (p.product_id = p2c.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2c.category_id = '" . (int)$category_id . "'"; + + if ($sort=='p.price'){ + + if ($this->customer->isLogged()) { + $customer_group_id = $this->customer->getCustomerGroupId(); + } else { + $customer_group_id = $this->config->get('config_customer_group_id'); + } + + $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating, ". + "coalesce((SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND customer_group_id = '" . (int)$customer_group_id . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY priority ASC, price ASC LIMIT 1), p.price) as s_price ". + "FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) LEFT JOIN " . DB_PREFIX . "product_to_category p2c ON (p.product_id = p2c.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2c.category_id = '" . (int)$category_id . "'"; + $sort = 's_price'; + } $sort_data = array( 'pd.name', *************** *** 21,26 **** --- 35,41 ---- 'special', 'rating', 'p.price', + 's_price', 'p.model' ); Надіслати Поділитися на інших сайтах More sharing options... 1roma1 Опубліковано: 18 лютого 2012 Автор Share Опубліковано: 18 лютого 2012 Спасибо большое за оперативность! Мне только не совсем понятно назначение чисел *** 14,19 **** --- 14,33 ---- *** 21,26 **** --- 35,41 ---- извините, я не программист. Ясно только что править нужно файл catalog/model/catalog/product.php начиная с 14й строки. Вы бы не могли дать буквенные пояснения к этим числам?) Надіслати Поділитися на інших сайтах More sharing options... freelancer Опубліковано: 19 лютого 2012 Share Опубліковано: 19 лютого 2012 да это я diff сделал. номера строк кажется. строки где + добавить Надіслати Поділитися на інших сайтах More sharing options... 4 weeks later... Petr Опубліковано: 13 березня 2012 Share Опубліковано: 13 березня 2012 да это я diff сделал. номера строк кажется. строки где + добавить Добрый день, Скажите а как должен выглядеть код для 1.5.1.3 я попытался добавить но не получилось.? Надіслати Поділитися на інших сайтах More sharing options... freelancer Опубліковано: 14 березня 2012 Share Опубліковано: 14 березня 2012 Добрый день, Скажите а как должен выглядеть код для 1.5.1.3 я попытался добавить но не получилось.?я описал для версии 0.2.2, для 1.5.1.3 не подойдет 1 Надіслати Поділитися на інших сайтах More sharing options... 1roma1 Опубліковано: 15 березня 2012 Автор Share Опубліковано: 15 березня 2012 Извините что так долго не отписывал, был в разъездах, не было возможности проверить. Код представленный здесь действительно работает, и сортирует товар по ценам с учетом текущей акционной цены, но только в каталоге. Если зайти в производители, сортирует по старому. Может еще где-то куда-то что-то нужно прописать? Надіслати Поділитися на інших сайтах More sharing options... freelancer Опубліковано: 15 березня 2012 Share Опубліковано: 15 березня 2012 Извините что так долго не отписывал, был в разъездах, не было возможности проверить. Код представленный здесь действительно работает, и сортирует товар по ценам с учетом текущей акционной цены, но только в каталоге. Если зайти в производители, сортирует по старому. Может еще где-то куда-то что-то нужно прописать? да. в том же файле точно такие же операции следует проделать в методе getProductsByManufacturerId Надіслати Поділитися на інших сайтах More sharing options... 1roma1 Опубліковано: 15 березня 2012 Автор Share Опубліковано: 15 березня 2012 сделал, но в производителях по-прежнему не работает. выдает ошибку: Notice: Undefined variable: category_id in Z:\home\localhost\www\nb2\catalog\model\catalog\product.php on line 80 ругается на вот это: $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating, ". "coalesce((SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND customer_group_id = '" . (int)$customer_group_id . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY priority ASC, price ASC LIMIT 1), p.price) as s_price ". "FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) LEFT JOIN " . DB_PREFIX . "product_to_category p2c ON (p.product_id = p2c.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2c.category_id = '" . (int)$category_id . "'"; Надіслати Поділитися на інших сайтах More sharing options... freelancer Опубліковано: 16 березня 2012 Share Опубліковано: 16 березня 2012 сделал, но в производителях по-прежнему не работает. выдает ошибку: Notice: Undefined variable: category_id in Z:\home\localhost\www\nb2\catalog\model\catalog\product.php on line 80 возможно я не так выразился.. не нужно было копировать всё.. только разницу public function getProductsByManufacturerId($manufacturer_id, $sort = 'p.sort_order', $order = 'ASC', $start = 0, $limit = 20) { $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND m.manufacturer_id = '" . (int)$manufacturer_id . "'"; if ($sort == 'p.price') { if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating," . "coalesce((SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND customer_group_id = '" . (int)$customer_group_id . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY priority ASC, price ASC LIMIT 1), p.price) as s_price " . " FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND m.manufacturer_id = '" . (int)$manufacturer_id . "'"; $sort = 's_price'; } $sort_data = array( 'pd.name', 'p.sort_order', 'special', 'rating', 's_price', 'p.model' ); 1 Надіслати Поділитися на інших сайтах More sharing options... 1roma1 Опубліковано: 16 березня 2012 Автор Share Опубліковано: 16 березня 2012 (змінено) Спасибо большое! все работает! В блоке $sort_data = array нужно было не добавить 's_price', а заменить ним 'p.price'. Полный код рабочего файла catalog/model/catalog/product.php представил ниже, может кому пригодится (версия OcStore 0.2.2!). <?php class ModelCatalogProduct extends Model { public function getProduct($product_id) { $query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.product_id = '" . (int)$product_id . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.date_available <= NOW() AND p.status = '1'"); return $query->row; } public function getProducts() { $query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, wcd.unit AS weight_class FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) LEFT JOIN " . DB_PREFIX . "weight_class_description wcd ON (p.weight_class_id = wcd.weight_class_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND wcd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.date_available <= NOW() AND p.status = '1'"); return $query->rows; } public function getProductsByCategoryId($category_id, $sort = 'p.sort_order', $order = 'ASC', $start = 0, $limit = 20) { $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) LEFT JOIN " . DB_PREFIX . "product_to_category p2c ON (p.product_id = p2c.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2c.category_id = '" . (int)$category_id . "'"; if ($sort=='p.price'){ if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating, ". "coalesce((SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND customer_group_id = '" . (int)$customer_group_id . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY priority ASC, price ASC LIMIT 1), p.price) as s_price ". "FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) LEFT JOIN " . DB_PREFIX . "product_to_category p2c ON (p.product_id = p2c.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2c.category_id = '" . (int)$category_id . "'"; $sort = 's_price'; } $sort_data = array( 'pd.name', 'p.sort_order', 'special', 'rating', 'p.price', 's_price', 'p.model' ); if (in_array($sort, $sort_data)) { if ($sort == 'pd.name' || $sort == 'p.model') { $sql .= " ORDER BY LCASE(" . $sort . ")"; } else { $sql .= " ORDER BY " . $sort; } } else { $sql .= " ORDER BY p.sort_order"; } if ($order == 'DESC') { $sql .= " DESC"; } else { $sql .= " ASC"; } if ($start < 0) { $start = 0; } $sql .= " LIMIT " . (int)$start . "," . (int)$limit; $query = $this->db->query($sql); return $query->rows; } public function getTotalProductsByCategoryId($category_id = 0) { $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product_to_category p2c LEFT JOIN " . DB_PREFIX . "product p ON (p2c.product_id = p.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND p2c.category_id = '" . (int)$category_id . "'"); return $query->row['total']; } public function getProductsByManufacturerId($manufacturer_id, $sort = 'p.sort_order', $order = 'ASC', $start = 0, $limit = 20) { $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND m.manufacturer_id = '" . (int)$manufacturer_id. "'"; if ($sort == 'p.price') { if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating," . "coalesce((SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND customer_group_id = '" . (int)$customer_group_id . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY priority ASC, price ASC LIMIT 1), p.price) as s_price " . " FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND m.manufacturer_id = '" . (int)$manufacturer_id . "'"; $sort = 's_price'; } $sort_data = array( 'pd.name', 'p.sort_order', 'special', 'rating', 's_price', 'p.model' ); if (in_array($sort, $sort_data)) { if ($sort == 'pd.name' || $sort == 'p.model') { $sql .= " ORDER BY LCASE(" . $sort . ")"; } else { $sql .= " ORDER BY " . $sort; } } else { $sql .= " ORDER BY p.sort_order"; } if ($order == 'DESC') { $sql .= " DESC"; } else { $sql .= " ASC"; } if ($start < 0) { $start = 0; } $sql .= " LIMIT " . (int)$start . "," . (int)$limit; $query = $this->db->query($sql); return $query->rows; } public function getTotalProductsByManufacturerId($manufacturer_id = 0) { $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product WHERE status = '1' AND date_available <= NOW() AND manufacturer_id = '" . (int)$manufacturer_id . "'"); return $query->row['total']; } public function getProductsByTag($tag, $category_id = 0, $sort = 'p.sort_order', $order = 'ASC', $start = 0, $limit = 20) { if ($tag) { $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_tags pt ON (p.product_id = pt.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND pt.language_id = '" . (int)$this->config->get('config_language_id') . "' AND (pt.tag = '" . $this->db->escape($tag) . "'"; $keywords = explode(" ", $tag); foreach ($keywords as $keyword) { $sql .= " OR pt.tag = '" . $this->db->escape($keyword) . "'"; } $sql .= ")"; if ($category_id) { $data = array(); $this->load->model('catalog/category'); $string = rtrim($this->getPath($category_id), ','); foreach (explode(',', $string) as $category_id) { $data[] = "category_id = '" . (int)$category_id . "'"; } $sql .= " AND p.product_id IN (SELECT product_id FROM " . DB_PREFIX . "product_to_category WHERE " . implode(" OR ", $data) . ")"; } $sql .= " AND p.status = '1' AND p.date_available <= NOW() GROUP BY p.product_id"; $sort_data = array( 'pd.name', 'p.sort_order', 'special', 'rating', 'p.price', 'p.model' ); if (in_array($sort, $sort_data)) { if ($sort == 'pd.name' || $sort == 'p.model') { $sql .= " ORDER BY LCASE(" . $sort . ")"; } else { $sql .= " ORDER BY " . $sort; } } else { $sql .= " ORDER BY p.sort_order"; } if ($order == 'DESC') { $sql .= " DESC"; } else { $sql .= " ASC"; } if ($start < 0) { $start = 0; } $sql .= " LIMIT " . (int)$start . "," . (int)$limit; $query = $this->db->query($sql); $products = array(); foreach ($query->rows as $key => $value) { $products[$value['product_id']] = $this->getProduct($value['product_id']); } return $products; } } public function getProductsByKeyword($keyword, $category_id = 0, $description = FALSE, $model = FALSE, $sort = 'p.sort_order', $order = 'ASC', $start = 0, $limit = 20) { if ($keyword) { $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "'"; if (!$description) { $sql .= " AND (pd.name LIKE '%" . $this->db->escape($keyword) . "%'"; } else { $sql .= " AND (pd.name LIKE '%" . $this->db->escape($keyword) . "%' OR pd.description LIKE '%" . $this->db->escape($keyword) . "%'"; } if (!$model) { $sql .= ")"; } else { $sql .= " OR p.model LIKE '%" . $this->db->escape($keyword) . "%')"; } if ($category_id) { $data = array(); $this->load->model('catalog/category'); $string = rtrim($this->getPath($category_id), ','); foreach (explode(',', $string) as $category_id) { $data[] = "category_id = '" . (int)$category_id . "'"; } $sql .= " AND p.product_id IN (SELECT product_id FROM " . DB_PREFIX . "product_to_category WHERE " . implode(" OR ", $data) . ")"; } $sql .= " AND p.status = '1' AND p.date_available <= NOW() GROUP BY p.product_id"; $sort_data = array( 'pd.name', 'p.sort_order', 'special', 'rating', 'p.price', 'p.model' ); if (in_array($sort, $sort_data)) { if ($sort == 'pd.name' || $sort == 'p.model') { $sql .= " ORDER BY LCASE(" . $sort . ")"; } else { $sql .= " ORDER BY " . $sort; } } else { $sql .= " ORDER BY p.sort_order"; } if ($order == 'DESC') { $sql .= " DESC"; } else { $sql .= " ASC"; } if ($start < 0) { $start = 0; } $sql .= " LIMIT " . (int)$start . "," . (int)$limit; $query = $this->db->query($sql); return $query->rows; } return 0; } public function getTotalProductsByKeyword($keyword, $category_id = 0, $description = FALSE, $model = FALSE) { if ($keyword) { $sql = "SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "'"; if (!$description) { $sql .= " AND (pd.name LIKE '%" . $this->db->escape($keyword) . "%'"; } else { $sql .= " AND (pd.name LIKE '%" . $this->db->escape($keyword) . "%' OR pd.description LIKE '%" . $this->db->escape($keyword) . "%'"; } if (!$model) { $sql .= ")"; } else { $sql .= " OR p.model LIKE '%" . $this->db->escape($keyword) . "%')"; } if ($category_id) { $data = array(); $this->load->model('catalog/category'); $string = rtrim($this->getPath($category_id), ','); foreach (explode(',', $string) as $category_id) { $data[] = "category_id = '" . (int)$category_id . "'"; } $sql .= " AND p.product_id IN (SELECT product_id FROM " . DB_PREFIX . "product_to_category WHERE " . implode(" OR ", $data) . ")"; } $sql .= " AND p.status = '1' AND p.date_available <= NOW()"; $query = $this->db->query($sql); if ($query->num_rows) { return $query->row['total']; } else { return 0; } } return 0; } public function getTotalProductsByTag($tag, $category_id = 0) { if ($tag) { $sql = "SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_tags pt ON (p.product_id = pt.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND pt.language_id = '" . (int)$this->config->get('config_language_id') . "' AND (pt.tag = '" . $this->db->escape($tag) . "'"; $keywords = explode(" ", $tag); foreach ($keywords as $keyword) { $sql .= " OR pt.tag = '" . $this->db->escape($keyword) . "'"; } $sql .= ")"; if ($category_id) { $data = array(); $this->load->model('catalog/category'); $string = rtrim($this->getPath($category_id), ','); foreach (explode(',', $string) as $category_id) { $data[] = "category_id = '" . (int)$category_id . "'"; } $sql .= " AND p.product_id IN (SELECT product_id FROM " . DB_PREFIX . "product_to_category WHERE " . implode(" OR ", $data) . ")"; } $sql .= " AND p.status = '1' AND p.date_available <= NOW()"; $query = $this->db->query($sql); if ($query->num_rows) { return $query->row['total']; } else { return 0; } } return 0; } public function getPath($category_id) { $string = $category_id . ','; $results = $this->model_catalog_category->getCategories($category_id); foreach ($results as $result) { $string .= $this->getPath($result['category_id']); } return $string; } public function getLatestProducts($limit) { $product_data = $this->cache->get('product.latest.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit); if (!$product_data) { $query = $this->db->query("SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY p.date_added DESC LIMIT " . (int)$limit); $product_data = $query->rows; $this->cache->set('product.latest.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit, $product_data); } return $product_data; } public function getPopularProducts($limit) { $query = $this->db->query("SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY p.viewed, p.date_added DESC LIMIT " . (int)$limit); return $query->rows; } public function getFeaturedProducts($limit) { $product_data = $this->cache->get('product.featured.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit); if (!$product_data) { $query = $this->db->query("SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product_featured f LEFT JOIN " . DB_PREFIX . "product p ON (f.product_id=p.product_id) LEFT JOIN " . DB_PREFIX . "product_description pd ON (f.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' LIMIT " . (int)$limit); $product_data = $query->rows; $this->cache->set('product.featured.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit, $product_data); } return $product_data; } public function getBestSellerProducts($limit) { $product_data = $this->cache->get('product.bestseller.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit); if (!$product_data) { $product_data = array(); $query = $this->db->query("SELECT op.product_id, SUM(op.quantity) AS total, p.status FROM " . DB_PREFIX . "order_product op LEFT JOIN `" . DB_PREFIX . "order` o ON (op.order_id = o.order_id) LEFT JOIN `" . DB_PREFIX . "product` p ON (op.product_id = p.product_id) WHERE o.order_status_id > '0' AND p.status = '1' GROUP BY op.product_id, p.status ORDER BY total DESC LIMIT " . (int)$limit); foreach ($query->rows as $result) { $product_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE p.product_id = '" . (int)$result['product_id'] . "' AND p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "'"); if ($product_query->num_rows) { $product_data[] = $product_query->row; } } $this->cache->set('product.bestseller.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit, $product_data); } return $product_data; } public function updateViewed($product_id) { $this->db->query("UPDATE " . DB_PREFIX . "product SET viewed = viewed + 1 WHERE product_id = '" . (int)$product_id . "'"); } public function getProductOptions($product_id) { $product_option_data = array(); $product_option_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option WHERE product_id = '" . (int)$product_id . "' ORDER BY sort_order"); foreach ($product_option_query->rows as $product_option) { $product_option_value_data = array(); $product_option_value_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option_value WHERE product_option_id = '" . (int)$product_option['product_option_id'] . "' ORDER BY sort_order"); foreach ($product_option_value_query->rows as $product_option_value) { $product_option_value_description_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option_value_description WHERE product_option_value_id = '" . (int)$product_option_value['product_option_value_id'] . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'"); $product_option_value_data[] = array( 'product_option_value_id' => $product_option_value['product_option_value_id'], 'name' => $product_option_value_description_query->row['name'], 'price' => $product_option_value['price'], 'prefix' => $product_option_value['prefix'], 'quantity' => $product_option_value['quantity'] /* webme - options show|hide - mod */ ); } $product_option_description_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option_description WHERE product_option_id = '" . (int)$product_option['product_option_id'] . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'"); $product_option_data[] = array( 'product_option_id' => $product_option['product_option_id'], 'name' => $product_option_description_query->row['name'], 'option_value' => $product_option_value_data, 'sort_order' => $product_option['sort_order'] ); } return $product_option_data; } public function getProductImages($product_id) { $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_image WHERE product_id = '" . (int)$product_id . "'"); return $query->rows; } public function getProductTags($product_id) { $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_tags WHERE product_id = '" . (int)$product_id . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'"); return $query->rows; } public function getProductDiscount($product_id) { if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $query = $this->db->query("SELECT price FROM " . DB_PREFIX . "product_discount WHERE product_id = '" . (int)$product_id . "' AND customer_group_id = '" . (int)$customer_group_id . "' AND quantity = '1' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY priority ASC, price ASC LIMIT 1"); if ($query->num_rows) { return $query->row['price']; } else { return FALSE; } } public function getProductDiscounts($product_id) { if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_discount WHERE product_id = '" . (int)$product_id . "' AND customer_group_id = '" . (int)$customer_group_id . "' AND quantity > 1 AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY quantity ASC, priority ASC, price ASC"); return $query->rows; } public function getProductSpecial($product_id) { if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $query = $this->db->query("SELECT price FROM " . DB_PREFIX . "product_special WHERE product_id = '" . (int)$product_id . "' AND customer_group_id = '" . (int)$customer_group_id . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY priority ASC, price ASC LIMIT 1"); if ($query->num_rows) { return $query->row['price']; } else { return FALSE; } } public function getProductSpecials($sort = 'p.sort_order', $order = 'ASC', $start = 0, $limit = 20) { if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $sql = "SELECT *, pd.name AS name, p.price, (SELECT ps2.price FROM " . DB_PREFIX . "product_special ps2 WHERE p.product_id = ps2.product_id AND ps2.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps2.date_start = '0000-00-00' OR ps2.date_start < NOW()) AND (ps2.date_end = '0000-00-00' OR ps2.date_end > NOW())) ORDER BY ps2.priority ASC, ps2.price ASC LIMIT 1) AS special, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "product_special ps ON (p.product_id = ps.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND ps.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW())AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) AND ps.product_id NOT IN (SELECT pd2.product_id FROM " . DB_PREFIX . "product_discount pd2 WHERE p.product_id = pd2.product_id AND pd2.customer_group_id = '" . (int)$customer_group_id . "' AND pd2.quantity = '1' AND ((pd2.date_start = '0000-00-00' OR pd2.date_start < NOW()) AND (pd2.date_end = '0000-00-00' OR pd2.date_end > NOW()))) GROUP BY p.product_id"; $sort_data = array( 'pd.name', 'p.sort_order', 'special', 'rating', 'p.price', 'p.model' ); if (in_array($sort, $sort_data)) { if ($sort == 'pd.name' || $sort == 'p.model') { $sql .= " ORDER BY LCASE(" . $sort . ")"; } else { $sql .= " ORDER BY " . $sort; } } else { $sql .= " ORDER BY p.sort_order"; } if ($order == 'DESC') { $sql .= " DESC"; } else { $sql .= " ASC"; } if ($start < 0) { $start = 0; } $sql .= " LIMIT " . (int)$start . "," . (int)$limit; $query = $this->db->query($sql); return $query->rows; } public function getTotalProductSpecials() { if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $query = $this->db->query("SELECT COUNT(DISTINCT ps.product_id) AS total FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "product_special ps ON (p.product_id = ps.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) AND ps.product_id NOT IN (SELECT pd2.product_id FROM " . DB_PREFIX . "product_discount pd2 WHERE p.product_id = pd2.product_id AND pd2.customer_group_id = '" . (int)$customer_group_id . "' AND pd2.quantity = '1' AND ((pd2.date_start = '0000-00-00' OR pd2.date_start < NOW()) AND (pd2.date_end = '0000-00-00' OR pd2.date_end > NOW())))"); if (isset($query->row['total'])) { return $query->row['total']; } else { return 0; } } public function getProductRelated($product_id) { $product_data = array(); $product_related_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$product_id . "'"); foreach ($product_related_query->rows as $result) { $product_query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.product_id = '" . (int)$result['related_id'] . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.date_available <= NOW() AND p.status = '1'"); if ($product_query->num_rows) { $product_data[$result['related_id']] = $product_query->row; } } return $product_data; } public function getCategories($product_id) { $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_to_category WHERE product_id = '" . (int)$product_id . "'"); return $query->rows; } } ?> Тему можно закрыть с пометкой решено и сделать на нее ссылку в FAQ) Змінено 16 березня 2012 користувачем 1roma1 Надіслати Поділитися на інших сайтах More sharing options... freelancer Опубліковано: 16 березня 2012 Share Опубліковано: 16 березня 2012 Спасибо большое! все работает! В блоке $sort_data = array нужно было не добавить 's_price', а заменить ним 'p.price'. .. это вовсе не обязательно. важное исправление было в другом месте.ну да не суть Надіслати Поділитися на інших сайтах More sharing options... DAN Опубліковано: 22 березня 2012 Share Опубліковано: 22 березня 2012 я описал для версии 0.2.2, для 1.5.1.3 не подойдет А для версии 1.5.1.3 как сделать не подскажите? Надіслати Поділитися на інших сайтах More sharing options... 7 months later... mybay Опубліковано: 31 жовтня 2012 Share Опубліковано: 31 жовтня 2012 большое спасибо! и мне помогло))) Надіслати Поділитися на інших сайтах More sharing options... 7 months later... hon2012 Опубліковано: 10 червня 2013 Share Опубліковано: 10 червня 2013 Добрый день, Скажите а как должен выглядеть код для 1.5.1.3 я попытался добавить но не получилось.?я описал для версии 0.2.2, для 1.5.1.3 не подойдет Уважаемый freelancer, подскажите как сделать для версии 1.5.13 Спасибо Надіслати Поділитися на інших сайтах More sharing options... freelancer Опубліковано: 10 червня 2013 Share Опубліковано: 10 червня 2013 по аналогии. разжевывать не буду Надіслати Поділитися на інших сайтах More sharing options... 3 months later... NoobMan Опубліковано: 7 жовтня 2013 Share Опубліковано: 7 жовтня 2013 Всем привет! Собственно наткнулся на такую проблему/недоработку пока не знаю как назвать. Версия OcStore 0.2.2. Есть каталог продукции с установленной ценой. Например на 2 месяца устанавливаю специальную цену. Она может быть разной относительно первоначальной одинаковой цены в похожих моделях. Например есть 2 товара по цене 700. На один делаю скидку 100, на другой 150. Итого новые цены выходят 600 и 550 соответственно. Проблема заключается в том, что когда в каталоге выбираю сортировку по цене, скрипт сортирует относительно первоначальной цены, без учета специальной. Т.е. таким образом: 700 600, 700 550, 720 610, 740 630, 750 650. Вопрос: это у всех так или только у меня? И если у всех, то кто-то может подсказать как это решить? Поиском пользовался, решений не нашел. Спасибо. Для opencart 1.5.4.1 решение не подскажите? Надіслати Поділитися на інших сайтах More sharing options... 1 year later... Marinka Опубліковано: 11 квітня 2015 Share Опубліковано: 11 квітня 2015 Да, для 1.5.4.1 тоже не могу найти решение! хэлп!!! Надіслати Поділитися на інших сайтах More sharing options... 1 year later... newjey Опубліковано: 11 січня 2017 Share Опубліковано: 11 січня 2017 Подскажите под ocStore 2.1.0.2 как сделать сортировку с учётом акционной цены? Надіслати Поділитися на інших сайтах More sharing options... Створіть аккаунт або увійдіть для коментування Ви повинні бути користувачем, щоб залишити коментар Створити обліковий запис Зареєструйтеся для отримання облікового запису. Це просто! Зареєструвати аккаунт Вхід Уже зареєстровані? Увійдіть тут. Вхід зараз Share More sharing options... Передплатники 0 Перейти до списку тем Зараз на сторінці 0 користувачів Ні користувачів, які переглядиють цю сторінку Последние темы Последние дополнения Последние новости Вся активність Головна Підтримка та відповіді на запитання. Встановлення, оновлення, налаштування Сортировка товаров по цене с учетом скидок Покупцям Оплата розширень фізичними особами Оплата розширень юридичними особами Політика повернень Розробникам Регламент розміщення розширень Регламент продажу та підтримки розширень Віртуальний обліковий запис автора Політика просування оголошень API каталогу розширень Вирішення спорів щодо авторських прав Корисна інформація Публічна оферта Політика повернень Політика конфіденційності Платіжна політика Політика передачі особистих даних Політика прозорості Останні розширення Повний пакет SEO Автор: GeekoDev SameSite Session Fix Opencart 3 Автор: web_bond SP Telegram повідомлення FREE Автор: spectre Відключити порожні категорії Автор: spectre SEO Автор тексту категорії / фільтра / блогу з датою оновлення контенту + мікророзмітка Автор: radaevich × Уже зареєстровані? Ввійти Реєстрація Ваші замовлення Назад Придбані модулі та шаблони Ваші рахунки Лист очікувань Альтернативні контакти Форум Новини ocStore Назад Офіційний сайт Демо ocStore 3.0.3.2 Демо ocStore 2.3.0.2.4 Завантажити ocStore Документація Історія версій ocStore Блоги Модулі Шаблони Назад Безкоштовні шаблони Платні шаблони Де купувати модулі? Послуги FAQ OpenCart.Pro Назад Демо Купити Порівняння × Створити... Important Information На нашому сайті використовуються файли cookie і відбувається обробка деяких персональних даних користувачів, щоб поліпшити користувальницький інтерфейс. Щоб дізнатися для чого і які персональні дані ми обробляємо перейдіть за посиланням . Якщо Ви натиснете «Я даю згоду», це означає, що Ви розумієте і приймаєте всі умови, зазначені в цьому Повідомленні про конфіденційність. Я даю згоду
1roma1 Опубліковано: 18 лютого 2012 Автор Share Опубліковано: 18 лютого 2012 Спасибо большое за оперативность! Мне только не совсем понятно назначение чисел *** 14,19 **** --- 14,33 ---- *** 21,26 **** --- 35,41 ---- извините, я не программист. Ясно только что править нужно файл catalog/model/catalog/product.php начиная с 14й строки. Вы бы не могли дать буквенные пояснения к этим числам?) Надіслати Поділитися на інших сайтах More sharing options...
freelancer Опубліковано: 19 лютого 2012 Share Опубліковано: 19 лютого 2012 да это я diff сделал. номера строк кажется. строки где + добавить Надіслати Поділитися на інших сайтах More sharing options... 4 weeks later... Petr Опубліковано: 13 березня 2012 Share Опубліковано: 13 березня 2012 да это я diff сделал. номера строк кажется. строки где + добавить Добрый день, Скажите а как должен выглядеть код для 1.5.1.3 я попытался добавить но не получилось.? Надіслати Поділитися на інших сайтах More sharing options... freelancer Опубліковано: 14 березня 2012 Share Опубліковано: 14 березня 2012 Добрый день, Скажите а как должен выглядеть код для 1.5.1.3 я попытался добавить но не получилось.?я описал для версии 0.2.2, для 1.5.1.3 не подойдет 1 Надіслати Поділитися на інших сайтах More sharing options... 1roma1 Опубліковано: 15 березня 2012 Автор Share Опубліковано: 15 березня 2012 Извините что так долго не отписывал, был в разъездах, не было возможности проверить. Код представленный здесь действительно работает, и сортирует товар по ценам с учетом текущей акционной цены, но только в каталоге. Если зайти в производители, сортирует по старому. Может еще где-то куда-то что-то нужно прописать? Надіслати Поділитися на інших сайтах More sharing options... freelancer Опубліковано: 15 березня 2012 Share Опубліковано: 15 березня 2012 Извините что так долго не отписывал, был в разъездах, не было возможности проверить. Код представленный здесь действительно работает, и сортирует товар по ценам с учетом текущей акционной цены, но только в каталоге. Если зайти в производители, сортирует по старому. Может еще где-то куда-то что-то нужно прописать? да. в том же файле точно такие же операции следует проделать в методе getProductsByManufacturerId Надіслати Поділитися на інших сайтах More sharing options... 1roma1 Опубліковано: 15 березня 2012 Автор Share Опубліковано: 15 березня 2012 сделал, но в производителях по-прежнему не работает. выдает ошибку: Notice: Undefined variable: category_id in Z:\home\localhost\www\nb2\catalog\model\catalog\product.php on line 80 ругается на вот это: $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating, ". "coalesce((SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND customer_group_id = '" . (int)$customer_group_id . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY priority ASC, price ASC LIMIT 1), p.price) as s_price ". "FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) LEFT JOIN " . DB_PREFIX . "product_to_category p2c ON (p.product_id = p2c.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2c.category_id = '" . (int)$category_id . "'"; Надіслати Поділитися на інших сайтах More sharing options... freelancer Опубліковано: 16 березня 2012 Share Опубліковано: 16 березня 2012 сделал, но в производителях по-прежнему не работает. выдает ошибку: Notice: Undefined variable: category_id in Z:\home\localhost\www\nb2\catalog\model\catalog\product.php on line 80 возможно я не так выразился.. не нужно было копировать всё.. только разницу public function getProductsByManufacturerId($manufacturer_id, $sort = 'p.sort_order', $order = 'ASC', $start = 0, $limit = 20) { $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND m.manufacturer_id = '" . (int)$manufacturer_id . "'"; if ($sort == 'p.price') { if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating," . "coalesce((SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND customer_group_id = '" . (int)$customer_group_id . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY priority ASC, price ASC LIMIT 1), p.price) as s_price " . " FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND m.manufacturer_id = '" . (int)$manufacturer_id . "'"; $sort = 's_price'; } $sort_data = array( 'pd.name', 'p.sort_order', 'special', 'rating', 's_price', 'p.model' ); 1 Надіслати Поділитися на інших сайтах More sharing options... 1roma1 Опубліковано: 16 березня 2012 Автор Share Опубліковано: 16 березня 2012 (змінено) Спасибо большое! все работает! В блоке $sort_data = array нужно было не добавить 's_price', а заменить ним 'p.price'. Полный код рабочего файла catalog/model/catalog/product.php представил ниже, может кому пригодится (версия OcStore 0.2.2!). <?php class ModelCatalogProduct extends Model { public function getProduct($product_id) { $query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.product_id = '" . (int)$product_id . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.date_available <= NOW() AND p.status = '1'"); return $query->row; } public function getProducts() { $query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, wcd.unit AS weight_class FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) LEFT JOIN " . DB_PREFIX . "weight_class_description wcd ON (p.weight_class_id = wcd.weight_class_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND wcd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.date_available <= NOW() AND p.status = '1'"); return $query->rows; } public function getProductsByCategoryId($category_id, $sort = 'p.sort_order', $order = 'ASC', $start = 0, $limit = 20) { $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) LEFT JOIN " . DB_PREFIX . "product_to_category p2c ON (p.product_id = p2c.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2c.category_id = '" . (int)$category_id . "'"; if ($sort=='p.price'){ if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating, ". "coalesce((SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND customer_group_id = '" . (int)$customer_group_id . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY priority ASC, price ASC LIMIT 1), p.price) as s_price ". "FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) LEFT JOIN " . DB_PREFIX . "product_to_category p2c ON (p.product_id = p2c.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2c.category_id = '" . (int)$category_id . "'"; $sort = 's_price'; } $sort_data = array( 'pd.name', 'p.sort_order', 'special', 'rating', 'p.price', 's_price', 'p.model' ); if (in_array($sort, $sort_data)) { if ($sort == 'pd.name' || $sort == 'p.model') { $sql .= " ORDER BY LCASE(" . $sort . ")"; } else { $sql .= " ORDER BY " . $sort; } } else { $sql .= " ORDER BY p.sort_order"; } if ($order == 'DESC') { $sql .= " DESC"; } else { $sql .= " ASC"; } if ($start < 0) { $start = 0; } $sql .= " LIMIT " . (int)$start . "," . (int)$limit; $query = $this->db->query($sql); return $query->rows; } public function getTotalProductsByCategoryId($category_id = 0) { $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product_to_category p2c LEFT JOIN " . DB_PREFIX . "product p ON (p2c.product_id = p.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND p2c.category_id = '" . (int)$category_id . "'"); return $query->row['total']; } public function getProductsByManufacturerId($manufacturer_id, $sort = 'p.sort_order', $order = 'ASC', $start = 0, $limit = 20) { $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND m.manufacturer_id = '" . (int)$manufacturer_id. "'"; if ($sort == 'p.price') { if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating," . "coalesce((SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND customer_group_id = '" . (int)$customer_group_id . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY priority ASC, price ASC LIMIT 1), p.price) as s_price " . " FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND m.manufacturer_id = '" . (int)$manufacturer_id . "'"; $sort = 's_price'; } $sort_data = array( 'pd.name', 'p.sort_order', 'special', 'rating', 's_price', 'p.model' ); if (in_array($sort, $sort_data)) { if ($sort == 'pd.name' || $sort == 'p.model') { $sql .= " ORDER BY LCASE(" . $sort . ")"; } else { $sql .= " ORDER BY " . $sort; } } else { $sql .= " ORDER BY p.sort_order"; } if ($order == 'DESC') { $sql .= " DESC"; } else { $sql .= " ASC"; } if ($start < 0) { $start = 0; } $sql .= " LIMIT " . (int)$start . "," . (int)$limit; $query = $this->db->query($sql); return $query->rows; } public function getTotalProductsByManufacturerId($manufacturer_id = 0) { $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product WHERE status = '1' AND date_available <= NOW() AND manufacturer_id = '" . (int)$manufacturer_id . "'"); return $query->row['total']; } public function getProductsByTag($tag, $category_id = 0, $sort = 'p.sort_order', $order = 'ASC', $start = 0, $limit = 20) { if ($tag) { $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_tags pt ON (p.product_id = pt.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND pt.language_id = '" . (int)$this->config->get('config_language_id') . "' AND (pt.tag = '" . $this->db->escape($tag) . "'"; $keywords = explode(" ", $tag); foreach ($keywords as $keyword) { $sql .= " OR pt.tag = '" . $this->db->escape($keyword) . "'"; } $sql .= ")"; if ($category_id) { $data = array(); $this->load->model('catalog/category'); $string = rtrim($this->getPath($category_id), ','); foreach (explode(',', $string) as $category_id) { $data[] = "category_id = '" . (int)$category_id . "'"; } $sql .= " AND p.product_id IN (SELECT product_id FROM " . DB_PREFIX . "product_to_category WHERE " . implode(" OR ", $data) . ")"; } $sql .= " AND p.status = '1' AND p.date_available <= NOW() GROUP BY p.product_id"; $sort_data = array( 'pd.name', 'p.sort_order', 'special', 'rating', 'p.price', 'p.model' ); if (in_array($sort, $sort_data)) { if ($sort == 'pd.name' || $sort == 'p.model') { $sql .= " ORDER BY LCASE(" . $sort . ")"; } else { $sql .= " ORDER BY " . $sort; } } else { $sql .= " ORDER BY p.sort_order"; } if ($order == 'DESC') { $sql .= " DESC"; } else { $sql .= " ASC"; } if ($start < 0) { $start = 0; } $sql .= " LIMIT " . (int)$start . "," . (int)$limit; $query = $this->db->query($sql); $products = array(); foreach ($query->rows as $key => $value) { $products[$value['product_id']] = $this->getProduct($value['product_id']); } return $products; } } public function getProductsByKeyword($keyword, $category_id = 0, $description = FALSE, $model = FALSE, $sort = 'p.sort_order', $order = 'ASC', $start = 0, $limit = 20) { if ($keyword) { $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "'"; if (!$description) { $sql .= " AND (pd.name LIKE '%" . $this->db->escape($keyword) . "%'"; } else { $sql .= " AND (pd.name LIKE '%" . $this->db->escape($keyword) . "%' OR pd.description LIKE '%" . $this->db->escape($keyword) . "%'"; } if (!$model) { $sql .= ")"; } else { $sql .= " OR p.model LIKE '%" . $this->db->escape($keyword) . "%')"; } if ($category_id) { $data = array(); $this->load->model('catalog/category'); $string = rtrim($this->getPath($category_id), ','); foreach (explode(',', $string) as $category_id) { $data[] = "category_id = '" . (int)$category_id . "'"; } $sql .= " AND p.product_id IN (SELECT product_id FROM " . DB_PREFIX . "product_to_category WHERE " . implode(" OR ", $data) . ")"; } $sql .= " AND p.status = '1' AND p.date_available <= NOW() GROUP BY p.product_id"; $sort_data = array( 'pd.name', 'p.sort_order', 'special', 'rating', 'p.price', 'p.model' ); if (in_array($sort, $sort_data)) { if ($sort == 'pd.name' || $sort == 'p.model') { $sql .= " ORDER BY LCASE(" . $sort . ")"; } else { $sql .= " ORDER BY " . $sort; } } else { $sql .= " ORDER BY p.sort_order"; } if ($order == 'DESC') { $sql .= " DESC"; } else { $sql .= " ASC"; } if ($start < 0) { $start = 0; } $sql .= " LIMIT " . (int)$start . "," . (int)$limit; $query = $this->db->query($sql); return $query->rows; } return 0; } public function getTotalProductsByKeyword($keyword, $category_id = 0, $description = FALSE, $model = FALSE) { if ($keyword) { $sql = "SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "'"; if (!$description) { $sql .= " AND (pd.name LIKE '%" . $this->db->escape($keyword) . "%'"; } else { $sql .= " AND (pd.name LIKE '%" . $this->db->escape($keyword) . "%' OR pd.description LIKE '%" . $this->db->escape($keyword) . "%'"; } if (!$model) { $sql .= ")"; } else { $sql .= " OR p.model LIKE '%" . $this->db->escape($keyword) . "%')"; } if ($category_id) { $data = array(); $this->load->model('catalog/category'); $string = rtrim($this->getPath($category_id), ','); foreach (explode(',', $string) as $category_id) { $data[] = "category_id = '" . (int)$category_id . "'"; } $sql .= " AND p.product_id IN (SELECT product_id FROM " . DB_PREFIX . "product_to_category WHERE " . implode(" OR ", $data) . ")"; } $sql .= " AND p.status = '1' AND p.date_available <= NOW()"; $query = $this->db->query($sql); if ($query->num_rows) { return $query->row['total']; } else { return 0; } } return 0; } public function getTotalProductsByTag($tag, $category_id = 0) { if ($tag) { $sql = "SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_tags pt ON (p.product_id = pt.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND pt.language_id = '" . (int)$this->config->get('config_language_id') . "' AND (pt.tag = '" . $this->db->escape($tag) . "'"; $keywords = explode(" ", $tag); foreach ($keywords as $keyword) { $sql .= " OR pt.tag = '" . $this->db->escape($keyword) . "'"; } $sql .= ")"; if ($category_id) { $data = array(); $this->load->model('catalog/category'); $string = rtrim($this->getPath($category_id), ','); foreach (explode(',', $string) as $category_id) { $data[] = "category_id = '" . (int)$category_id . "'"; } $sql .= " AND p.product_id IN (SELECT product_id FROM " . DB_PREFIX . "product_to_category WHERE " . implode(" OR ", $data) . ")"; } $sql .= " AND p.status = '1' AND p.date_available <= NOW()"; $query = $this->db->query($sql); if ($query->num_rows) { return $query->row['total']; } else { return 0; } } return 0; } public function getPath($category_id) { $string = $category_id . ','; $results = $this->model_catalog_category->getCategories($category_id); foreach ($results as $result) { $string .= $this->getPath($result['category_id']); } return $string; } public function getLatestProducts($limit) { $product_data = $this->cache->get('product.latest.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit); if (!$product_data) { $query = $this->db->query("SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY p.date_added DESC LIMIT " . (int)$limit); $product_data = $query->rows; $this->cache->set('product.latest.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit, $product_data); } return $product_data; } public function getPopularProducts($limit) { $query = $this->db->query("SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY p.viewed, p.date_added DESC LIMIT " . (int)$limit); return $query->rows; } public function getFeaturedProducts($limit) { $product_data = $this->cache->get('product.featured.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit); if (!$product_data) { $query = $this->db->query("SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product_featured f LEFT JOIN " . DB_PREFIX . "product p ON (f.product_id=p.product_id) LEFT JOIN " . DB_PREFIX . "product_description pd ON (f.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' LIMIT " . (int)$limit); $product_data = $query->rows; $this->cache->set('product.featured.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit, $product_data); } return $product_data; } public function getBestSellerProducts($limit) { $product_data = $this->cache->get('product.bestseller.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit); if (!$product_data) { $product_data = array(); $query = $this->db->query("SELECT op.product_id, SUM(op.quantity) AS total, p.status FROM " . DB_PREFIX . "order_product op LEFT JOIN `" . DB_PREFIX . "order` o ON (op.order_id = o.order_id) LEFT JOIN `" . DB_PREFIX . "product` p ON (op.product_id = p.product_id) WHERE o.order_status_id > '0' AND p.status = '1' GROUP BY op.product_id, p.status ORDER BY total DESC LIMIT " . (int)$limit); foreach ($query->rows as $result) { $product_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE p.product_id = '" . (int)$result['product_id'] . "' AND p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "'"); if ($product_query->num_rows) { $product_data[] = $product_query->row; } } $this->cache->set('product.bestseller.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit, $product_data); } return $product_data; } public function updateViewed($product_id) { $this->db->query("UPDATE " . DB_PREFIX . "product SET viewed = viewed + 1 WHERE product_id = '" . (int)$product_id . "'"); } public function getProductOptions($product_id) { $product_option_data = array(); $product_option_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option WHERE product_id = '" . (int)$product_id . "' ORDER BY sort_order"); foreach ($product_option_query->rows as $product_option) { $product_option_value_data = array(); $product_option_value_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option_value WHERE product_option_id = '" . (int)$product_option['product_option_id'] . "' ORDER BY sort_order"); foreach ($product_option_value_query->rows as $product_option_value) { $product_option_value_description_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option_value_description WHERE product_option_value_id = '" . (int)$product_option_value['product_option_value_id'] . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'"); $product_option_value_data[] = array( 'product_option_value_id' => $product_option_value['product_option_value_id'], 'name' => $product_option_value_description_query->row['name'], 'price' => $product_option_value['price'], 'prefix' => $product_option_value['prefix'], 'quantity' => $product_option_value['quantity'] /* webme - options show|hide - mod */ ); } $product_option_description_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option_description WHERE product_option_id = '" . (int)$product_option['product_option_id'] . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'"); $product_option_data[] = array( 'product_option_id' => $product_option['product_option_id'], 'name' => $product_option_description_query->row['name'], 'option_value' => $product_option_value_data, 'sort_order' => $product_option['sort_order'] ); } return $product_option_data; } public function getProductImages($product_id) { $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_image WHERE product_id = '" . (int)$product_id . "'"); return $query->rows; } public function getProductTags($product_id) { $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_tags WHERE product_id = '" . (int)$product_id . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'"); return $query->rows; } public function getProductDiscount($product_id) { if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $query = $this->db->query("SELECT price FROM " . DB_PREFIX . "product_discount WHERE product_id = '" . (int)$product_id . "' AND customer_group_id = '" . (int)$customer_group_id . "' AND quantity = '1' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY priority ASC, price ASC LIMIT 1"); if ($query->num_rows) { return $query->row['price']; } else { return FALSE; } } public function getProductDiscounts($product_id) { if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_discount WHERE product_id = '" . (int)$product_id . "' AND customer_group_id = '" . (int)$customer_group_id . "' AND quantity > 1 AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY quantity ASC, priority ASC, price ASC"); return $query->rows; } public function getProductSpecial($product_id) { if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $query = $this->db->query("SELECT price FROM " . DB_PREFIX . "product_special WHERE product_id = '" . (int)$product_id . "' AND customer_group_id = '" . (int)$customer_group_id . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY priority ASC, price ASC LIMIT 1"); if ($query->num_rows) { return $query->row['price']; } else { return FALSE; } } public function getProductSpecials($sort = 'p.sort_order', $order = 'ASC', $start = 0, $limit = 20) { if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $sql = "SELECT *, pd.name AS name, p.price, (SELECT ps2.price FROM " . DB_PREFIX . "product_special ps2 WHERE p.product_id = ps2.product_id AND ps2.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps2.date_start = '0000-00-00' OR ps2.date_start < NOW()) AND (ps2.date_end = '0000-00-00' OR ps2.date_end > NOW())) ORDER BY ps2.priority ASC, ps2.price ASC LIMIT 1) AS special, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "product_special ps ON (p.product_id = ps.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND ps.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW())AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) AND ps.product_id NOT IN (SELECT pd2.product_id FROM " . DB_PREFIX . "product_discount pd2 WHERE p.product_id = pd2.product_id AND pd2.customer_group_id = '" . (int)$customer_group_id . "' AND pd2.quantity = '1' AND ((pd2.date_start = '0000-00-00' OR pd2.date_start < NOW()) AND (pd2.date_end = '0000-00-00' OR pd2.date_end > NOW()))) GROUP BY p.product_id"; $sort_data = array( 'pd.name', 'p.sort_order', 'special', 'rating', 'p.price', 'p.model' ); if (in_array($sort, $sort_data)) { if ($sort == 'pd.name' || $sort == 'p.model') { $sql .= " ORDER BY LCASE(" . $sort . ")"; } else { $sql .= " ORDER BY " . $sort; } } else { $sql .= " ORDER BY p.sort_order"; } if ($order == 'DESC') { $sql .= " DESC"; } else { $sql .= " ASC"; } if ($start < 0) { $start = 0; } $sql .= " LIMIT " . (int)$start . "," . (int)$limit; $query = $this->db->query($sql); return $query->rows; } public function getTotalProductSpecials() { if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $query = $this->db->query("SELECT COUNT(DISTINCT ps.product_id) AS total FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "product_special ps ON (p.product_id = ps.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) AND ps.product_id NOT IN (SELECT pd2.product_id FROM " . DB_PREFIX . "product_discount pd2 WHERE p.product_id = pd2.product_id AND pd2.customer_group_id = '" . (int)$customer_group_id . "' AND pd2.quantity = '1' AND ((pd2.date_start = '0000-00-00' OR pd2.date_start < NOW()) AND (pd2.date_end = '0000-00-00' OR pd2.date_end > NOW())))"); if (isset($query->row['total'])) { return $query->row['total']; } else { return 0; } } public function getProductRelated($product_id) { $product_data = array(); $product_related_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$product_id . "'"); foreach ($product_related_query->rows as $result) { $product_query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.product_id = '" . (int)$result['related_id'] . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.date_available <= NOW() AND p.status = '1'"); if ($product_query->num_rows) { $product_data[$result['related_id']] = $product_query->row; } } return $product_data; } public function getCategories($product_id) { $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_to_category WHERE product_id = '" . (int)$product_id . "'"); return $query->rows; } } ?> Тему можно закрыть с пометкой решено и сделать на нее ссылку в FAQ) Змінено 16 березня 2012 користувачем 1roma1 Надіслати Поділитися на інших сайтах More sharing options... freelancer Опубліковано: 16 березня 2012 Share Опубліковано: 16 березня 2012 Спасибо большое! все работает! В блоке $sort_data = array нужно было не добавить 's_price', а заменить ним 'p.price'. .. это вовсе не обязательно. важное исправление было в другом месте.ну да не суть Надіслати Поділитися на інших сайтах More sharing options... DAN Опубліковано: 22 березня 2012 Share Опубліковано: 22 березня 2012 я описал для версии 0.2.2, для 1.5.1.3 не подойдет А для версии 1.5.1.3 как сделать не подскажите? Надіслати Поділитися на інших сайтах More sharing options... 7 months later... mybay Опубліковано: 31 жовтня 2012 Share Опубліковано: 31 жовтня 2012 большое спасибо! и мне помогло))) Надіслати Поділитися на інших сайтах More sharing options... 7 months later... hon2012 Опубліковано: 10 червня 2013 Share Опубліковано: 10 червня 2013 Добрый день, Скажите а как должен выглядеть код для 1.5.1.3 я попытался добавить но не получилось.?я описал для версии 0.2.2, для 1.5.1.3 не подойдет Уважаемый freelancer, подскажите как сделать для версии 1.5.13 Спасибо Надіслати Поділитися на інших сайтах More sharing options... freelancer Опубліковано: 10 червня 2013 Share Опубліковано: 10 червня 2013 по аналогии. разжевывать не буду Надіслати Поділитися на інших сайтах More sharing options... 3 months later... NoobMan Опубліковано: 7 жовтня 2013 Share Опубліковано: 7 жовтня 2013 Всем привет! Собственно наткнулся на такую проблему/недоработку пока не знаю как назвать. Версия OcStore 0.2.2. Есть каталог продукции с установленной ценой. Например на 2 месяца устанавливаю специальную цену. Она может быть разной относительно первоначальной одинаковой цены в похожих моделях. Например есть 2 товара по цене 700. На один делаю скидку 100, на другой 150. Итого новые цены выходят 600 и 550 соответственно. Проблема заключается в том, что когда в каталоге выбираю сортировку по цене, скрипт сортирует относительно первоначальной цены, без учета специальной. Т.е. таким образом: 700 600, 700 550, 720 610, 740 630, 750 650. Вопрос: это у всех так или только у меня? И если у всех, то кто-то может подсказать как это решить? Поиском пользовался, решений не нашел. Спасибо. Для opencart 1.5.4.1 решение не подскажите? Надіслати Поділитися на інших сайтах More sharing options... 1 year later... Marinka Опубліковано: 11 квітня 2015 Share Опубліковано: 11 квітня 2015 Да, для 1.5.4.1 тоже не могу найти решение! хэлп!!! Надіслати Поділитися на інших сайтах More sharing options... 1 year later... newjey Опубліковано: 11 січня 2017 Share Опубліковано: 11 січня 2017 Подскажите под ocStore 2.1.0.2 как сделать сортировку с учётом акционной цены? Надіслати Поділитися на інших сайтах More sharing options... Створіть аккаунт або увійдіть для коментування Ви повинні бути користувачем, щоб залишити коментар Створити обліковий запис Зареєструйтеся для отримання облікового запису. Це просто! Зареєструвати аккаунт Вхід Уже зареєстровані? Увійдіть тут. Вхід зараз Share More sharing options... Передплатники 0 Перейти до списку тем Зараз на сторінці 0 користувачів Ні користувачів, які переглядиють цю сторінку Последние темы Последние дополнения Последние новости Вся активність Головна Підтримка та відповіді на запитання. Встановлення, оновлення, налаштування Сортировка товаров по цене с учетом скидок Покупцям Оплата розширень фізичними особами Оплата розширень юридичними особами Політика повернень Розробникам Регламент розміщення розширень Регламент продажу та підтримки розширень Віртуальний обліковий запис автора Політика просування оголошень API каталогу розширень Вирішення спорів щодо авторських прав Корисна інформація Публічна оферта Політика повернень Політика конфіденційності Платіжна політика Політика передачі особистих даних Політика прозорості Останні розширення Повний пакет SEO Автор: GeekoDev SameSite Session Fix Opencart 3 Автор: web_bond SP Telegram повідомлення FREE Автор: spectre Відключити порожні категорії Автор: spectre SEO Автор тексту категорії / фільтра / блогу з датою оновлення контенту + мікророзмітка Автор: radaevich × Уже зареєстровані? Ввійти Реєстрація Ваші замовлення Назад Придбані модулі та шаблони Ваші рахунки Лист очікувань Альтернативні контакти Форум Новини ocStore Назад Офіційний сайт Демо ocStore 3.0.3.2 Демо ocStore 2.3.0.2.4 Завантажити ocStore Документація Історія версій ocStore Блоги Модулі Шаблони Назад Безкоштовні шаблони Платні шаблони Де купувати модулі? Послуги FAQ OpenCart.Pro Назад Демо Купити Порівняння × Створити... Important Information На нашому сайті використовуються файли cookie і відбувається обробка деяких персональних даних користувачів, щоб поліпшити користувальницький інтерфейс. Щоб дізнатися для чого і які персональні дані ми обробляємо перейдіть за посиланням . Якщо Ви натиснете «Я даю згоду», це означає, що Ви розумієте і приймаєте всі умови, зазначені в цьому Повідомленні про конфіденційність. Я даю згоду
Petr Опубліковано: 13 березня 2012 Share Опубліковано: 13 березня 2012 да это я diff сделал. номера строк кажется. строки где + добавить Добрый день, Скажите а как должен выглядеть код для 1.5.1.3 я попытался добавить но не получилось.? Надіслати Поділитися на інших сайтах More sharing options...
freelancer Опубліковано: 14 березня 2012 Share Опубліковано: 14 березня 2012 Добрый день, Скажите а как должен выглядеть код для 1.5.1.3 я попытался добавить но не получилось.?я описал для версии 0.2.2, для 1.5.1.3 не подойдет 1 Надіслати Поділитися на інших сайтах More sharing options... 1roma1 Опубліковано: 15 березня 2012 Автор Share Опубліковано: 15 березня 2012 Извините что так долго не отписывал, был в разъездах, не было возможности проверить. Код представленный здесь действительно работает, и сортирует товар по ценам с учетом текущей акционной цены, но только в каталоге. Если зайти в производители, сортирует по старому. Может еще где-то куда-то что-то нужно прописать? Надіслати Поділитися на інших сайтах More sharing options... freelancer Опубліковано: 15 березня 2012 Share Опубліковано: 15 березня 2012 Извините что так долго не отписывал, был в разъездах, не было возможности проверить. Код представленный здесь действительно работает, и сортирует товар по ценам с учетом текущей акционной цены, но только в каталоге. Если зайти в производители, сортирует по старому. Может еще где-то куда-то что-то нужно прописать? да. в том же файле точно такие же операции следует проделать в методе getProductsByManufacturerId Надіслати Поділитися на інших сайтах More sharing options... 1roma1 Опубліковано: 15 березня 2012 Автор Share Опубліковано: 15 березня 2012 сделал, но в производителях по-прежнему не работает. выдает ошибку: Notice: Undefined variable: category_id in Z:\home\localhost\www\nb2\catalog\model\catalog\product.php on line 80 ругается на вот это: $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating, ". "coalesce((SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND customer_group_id = '" . (int)$customer_group_id . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY priority ASC, price ASC LIMIT 1), p.price) as s_price ". "FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) LEFT JOIN " . DB_PREFIX . "product_to_category p2c ON (p.product_id = p2c.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2c.category_id = '" . (int)$category_id . "'"; Надіслати Поділитися на інших сайтах More sharing options... freelancer Опубліковано: 16 березня 2012 Share Опубліковано: 16 березня 2012 сделал, но в производителях по-прежнему не работает. выдает ошибку: Notice: Undefined variable: category_id in Z:\home\localhost\www\nb2\catalog\model\catalog\product.php on line 80 возможно я не так выразился.. не нужно было копировать всё.. только разницу public function getProductsByManufacturerId($manufacturer_id, $sort = 'p.sort_order', $order = 'ASC', $start = 0, $limit = 20) { $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND m.manufacturer_id = '" . (int)$manufacturer_id . "'"; if ($sort == 'p.price') { if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating," . "coalesce((SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND customer_group_id = '" . (int)$customer_group_id . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY priority ASC, price ASC LIMIT 1), p.price) as s_price " . " FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND m.manufacturer_id = '" . (int)$manufacturer_id . "'"; $sort = 's_price'; } $sort_data = array( 'pd.name', 'p.sort_order', 'special', 'rating', 's_price', 'p.model' ); 1 Надіслати Поділитися на інших сайтах More sharing options... 1roma1 Опубліковано: 16 березня 2012 Автор Share Опубліковано: 16 березня 2012 (змінено) Спасибо большое! все работает! В блоке $sort_data = array нужно было не добавить 's_price', а заменить ним 'p.price'. Полный код рабочего файла catalog/model/catalog/product.php представил ниже, может кому пригодится (версия OcStore 0.2.2!). <?php class ModelCatalogProduct extends Model { public function getProduct($product_id) { $query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.product_id = '" . (int)$product_id . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.date_available <= NOW() AND p.status = '1'"); return $query->row; } public function getProducts() { $query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, wcd.unit AS weight_class FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) LEFT JOIN " . DB_PREFIX . "weight_class_description wcd ON (p.weight_class_id = wcd.weight_class_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND wcd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.date_available <= NOW() AND p.status = '1'"); return $query->rows; } public function getProductsByCategoryId($category_id, $sort = 'p.sort_order', $order = 'ASC', $start = 0, $limit = 20) { $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) LEFT JOIN " . DB_PREFIX . "product_to_category p2c ON (p.product_id = p2c.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2c.category_id = '" . (int)$category_id . "'"; if ($sort=='p.price'){ if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating, ". "coalesce((SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND customer_group_id = '" . (int)$customer_group_id . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY priority ASC, price ASC LIMIT 1), p.price) as s_price ". "FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) LEFT JOIN " . DB_PREFIX . "product_to_category p2c ON (p.product_id = p2c.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2c.category_id = '" . (int)$category_id . "'"; $sort = 's_price'; } $sort_data = array( 'pd.name', 'p.sort_order', 'special', 'rating', 'p.price', 's_price', 'p.model' ); if (in_array($sort, $sort_data)) { if ($sort == 'pd.name' || $sort == 'p.model') { $sql .= " ORDER BY LCASE(" . $sort . ")"; } else { $sql .= " ORDER BY " . $sort; } } else { $sql .= " ORDER BY p.sort_order"; } if ($order == 'DESC') { $sql .= " DESC"; } else { $sql .= " ASC"; } if ($start < 0) { $start = 0; } $sql .= " LIMIT " . (int)$start . "," . (int)$limit; $query = $this->db->query($sql); return $query->rows; } public function getTotalProductsByCategoryId($category_id = 0) { $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product_to_category p2c LEFT JOIN " . DB_PREFIX . "product p ON (p2c.product_id = p.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND p2c.category_id = '" . (int)$category_id . "'"); return $query->row['total']; } public function getProductsByManufacturerId($manufacturer_id, $sort = 'p.sort_order', $order = 'ASC', $start = 0, $limit = 20) { $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND m.manufacturer_id = '" . (int)$manufacturer_id. "'"; if ($sort == 'p.price') { if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating," . "coalesce((SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND customer_group_id = '" . (int)$customer_group_id . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY priority ASC, price ASC LIMIT 1), p.price) as s_price " . " FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND m.manufacturer_id = '" . (int)$manufacturer_id . "'"; $sort = 's_price'; } $sort_data = array( 'pd.name', 'p.sort_order', 'special', 'rating', 's_price', 'p.model' ); if (in_array($sort, $sort_data)) { if ($sort == 'pd.name' || $sort == 'p.model') { $sql .= " ORDER BY LCASE(" . $sort . ")"; } else { $sql .= " ORDER BY " . $sort; } } else { $sql .= " ORDER BY p.sort_order"; } if ($order == 'DESC') { $sql .= " DESC"; } else { $sql .= " ASC"; } if ($start < 0) { $start = 0; } $sql .= " LIMIT " . (int)$start . "," . (int)$limit; $query = $this->db->query($sql); return $query->rows; } public function getTotalProductsByManufacturerId($manufacturer_id = 0) { $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product WHERE status = '1' AND date_available <= NOW() AND manufacturer_id = '" . (int)$manufacturer_id . "'"); return $query->row['total']; } public function getProductsByTag($tag, $category_id = 0, $sort = 'p.sort_order', $order = 'ASC', $start = 0, $limit = 20) { if ($tag) { $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_tags pt ON (p.product_id = pt.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND pt.language_id = '" . (int)$this->config->get('config_language_id') . "' AND (pt.tag = '" . $this->db->escape($tag) . "'"; $keywords = explode(" ", $tag); foreach ($keywords as $keyword) { $sql .= " OR pt.tag = '" . $this->db->escape($keyword) . "'"; } $sql .= ")"; if ($category_id) { $data = array(); $this->load->model('catalog/category'); $string = rtrim($this->getPath($category_id), ','); foreach (explode(',', $string) as $category_id) { $data[] = "category_id = '" . (int)$category_id . "'"; } $sql .= " AND p.product_id IN (SELECT product_id FROM " . DB_PREFIX . "product_to_category WHERE " . implode(" OR ", $data) . ")"; } $sql .= " AND p.status = '1' AND p.date_available <= NOW() GROUP BY p.product_id"; $sort_data = array( 'pd.name', 'p.sort_order', 'special', 'rating', 'p.price', 'p.model' ); if (in_array($sort, $sort_data)) { if ($sort == 'pd.name' || $sort == 'p.model') { $sql .= " ORDER BY LCASE(" . $sort . ")"; } else { $sql .= " ORDER BY " . $sort; } } else { $sql .= " ORDER BY p.sort_order"; } if ($order == 'DESC') { $sql .= " DESC"; } else { $sql .= " ASC"; } if ($start < 0) { $start = 0; } $sql .= " LIMIT " . (int)$start . "," . (int)$limit; $query = $this->db->query($sql); $products = array(); foreach ($query->rows as $key => $value) { $products[$value['product_id']] = $this->getProduct($value['product_id']); } return $products; } } public function getProductsByKeyword($keyword, $category_id = 0, $description = FALSE, $model = FALSE, $sort = 'p.sort_order', $order = 'ASC', $start = 0, $limit = 20) { if ($keyword) { $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "'"; if (!$description) { $sql .= " AND (pd.name LIKE '%" . $this->db->escape($keyword) . "%'"; } else { $sql .= " AND (pd.name LIKE '%" . $this->db->escape($keyword) . "%' OR pd.description LIKE '%" . $this->db->escape($keyword) . "%'"; } if (!$model) { $sql .= ")"; } else { $sql .= " OR p.model LIKE '%" . $this->db->escape($keyword) . "%')"; } if ($category_id) { $data = array(); $this->load->model('catalog/category'); $string = rtrim($this->getPath($category_id), ','); foreach (explode(',', $string) as $category_id) { $data[] = "category_id = '" . (int)$category_id . "'"; } $sql .= " AND p.product_id IN (SELECT product_id FROM " . DB_PREFIX . "product_to_category WHERE " . implode(" OR ", $data) . ")"; } $sql .= " AND p.status = '1' AND p.date_available <= NOW() GROUP BY p.product_id"; $sort_data = array( 'pd.name', 'p.sort_order', 'special', 'rating', 'p.price', 'p.model' ); if (in_array($sort, $sort_data)) { if ($sort == 'pd.name' || $sort == 'p.model') { $sql .= " ORDER BY LCASE(" . $sort . ")"; } else { $sql .= " ORDER BY " . $sort; } } else { $sql .= " ORDER BY p.sort_order"; } if ($order == 'DESC') { $sql .= " DESC"; } else { $sql .= " ASC"; } if ($start < 0) { $start = 0; } $sql .= " LIMIT " . (int)$start . "," . (int)$limit; $query = $this->db->query($sql); return $query->rows; } return 0; } public function getTotalProductsByKeyword($keyword, $category_id = 0, $description = FALSE, $model = FALSE) { if ($keyword) { $sql = "SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "'"; if (!$description) { $sql .= " AND (pd.name LIKE '%" . $this->db->escape($keyword) . "%'"; } else { $sql .= " AND (pd.name LIKE '%" . $this->db->escape($keyword) . "%' OR pd.description LIKE '%" . $this->db->escape($keyword) . "%'"; } if (!$model) { $sql .= ")"; } else { $sql .= " OR p.model LIKE '%" . $this->db->escape($keyword) . "%')"; } if ($category_id) { $data = array(); $this->load->model('catalog/category'); $string = rtrim($this->getPath($category_id), ','); foreach (explode(',', $string) as $category_id) { $data[] = "category_id = '" . (int)$category_id . "'"; } $sql .= " AND p.product_id IN (SELECT product_id FROM " . DB_PREFIX . "product_to_category WHERE " . implode(" OR ", $data) . ")"; } $sql .= " AND p.status = '1' AND p.date_available <= NOW()"; $query = $this->db->query($sql); if ($query->num_rows) { return $query->row['total']; } else { return 0; } } return 0; } public function getTotalProductsByTag($tag, $category_id = 0) { if ($tag) { $sql = "SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_tags pt ON (p.product_id = pt.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND pt.language_id = '" . (int)$this->config->get('config_language_id') . "' AND (pt.tag = '" . $this->db->escape($tag) . "'"; $keywords = explode(" ", $tag); foreach ($keywords as $keyword) { $sql .= " OR pt.tag = '" . $this->db->escape($keyword) . "'"; } $sql .= ")"; if ($category_id) { $data = array(); $this->load->model('catalog/category'); $string = rtrim($this->getPath($category_id), ','); foreach (explode(',', $string) as $category_id) { $data[] = "category_id = '" . (int)$category_id . "'"; } $sql .= " AND p.product_id IN (SELECT product_id FROM " . DB_PREFIX . "product_to_category WHERE " . implode(" OR ", $data) . ")"; } $sql .= " AND p.status = '1' AND p.date_available <= NOW()"; $query = $this->db->query($sql); if ($query->num_rows) { return $query->row['total']; } else { return 0; } } return 0; } public function getPath($category_id) { $string = $category_id . ','; $results = $this->model_catalog_category->getCategories($category_id); foreach ($results as $result) { $string .= $this->getPath($result['category_id']); } return $string; } public function getLatestProducts($limit) { $product_data = $this->cache->get('product.latest.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit); if (!$product_data) { $query = $this->db->query("SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY p.date_added DESC LIMIT " . (int)$limit); $product_data = $query->rows; $this->cache->set('product.latest.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit, $product_data); } return $product_data; } public function getPopularProducts($limit) { $query = $this->db->query("SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY p.viewed, p.date_added DESC LIMIT " . (int)$limit); return $query->rows; } public function getFeaturedProducts($limit) { $product_data = $this->cache->get('product.featured.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit); if (!$product_data) { $query = $this->db->query("SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product_featured f LEFT JOIN " . DB_PREFIX . "product p ON (f.product_id=p.product_id) LEFT JOIN " . DB_PREFIX . "product_description pd ON (f.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' LIMIT " . (int)$limit); $product_data = $query->rows; $this->cache->set('product.featured.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit, $product_data); } return $product_data; } public function getBestSellerProducts($limit) { $product_data = $this->cache->get('product.bestseller.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit); if (!$product_data) { $product_data = array(); $query = $this->db->query("SELECT op.product_id, SUM(op.quantity) AS total, p.status FROM " . DB_PREFIX . "order_product op LEFT JOIN `" . DB_PREFIX . "order` o ON (op.order_id = o.order_id) LEFT JOIN `" . DB_PREFIX . "product` p ON (op.product_id = p.product_id) WHERE o.order_status_id > '0' AND p.status = '1' GROUP BY op.product_id, p.status ORDER BY total DESC LIMIT " . (int)$limit); foreach ($query->rows as $result) { $product_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE p.product_id = '" . (int)$result['product_id'] . "' AND p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "'"); if ($product_query->num_rows) { $product_data[] = $product_query->row; } } $this->cache->set('product.bestseller.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit, $product_data); } return $product_data; } public function updateViewed($product_id) { $this->db->query("UPDATE " . DB_PREFIX . "product SET viewed = viewed + 1 WHERE product_id = '" . (int)$product_id . "'"); } public function getProductOptions($product_id) { $product_option_data = array(); $product_option_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option WHERE product_id = '" . (int)$product_id . "' ORDER BY sort_order"); foreach ($product_option_query->rows as $product_option) { $product_option_value_data = array(); $product_option_value_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option_value WHERE product_option_id = '" . (int)$product_option['product_option_id'] . "' ORDER BY sort_order"); foreach ($product_option_value_query->rows as $product_option_value) { $product_option_value_description_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option_value_description WHERE product_option_value_id = '" . (int)$product_option_value['product_option_value_id'] . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'"); $product_option_value_data[] = array( 'product_option_value_id' => $product_option_value['product_option_value_id'], 'name' => $product_option_value_description_query->row['name'], 'price' => $product_option_value['price'], 'prefix' => $product_option_value['prefix'], 'quantity' => $product_option_value['quantity'] /* webme - options show|hide - mod */ ); } $product_option_description_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option_description WHERE product_option_id = '" . (int)$product_option['product_option_id'] . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'"); $product_option_data[] = array( 'product_option_id' => $product_option['product_option_id'], 'name' => $product_option_description_query->row['name'], 'option_value' => $product_option_value_data, 'sort_order' => $product_option['sort_order'] ); } return $product_option_data; } public function getProductImages($product_id) { $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_image WHERE product_id = '" . (int)$product_id . "'"); return $query->rows; } public function getProductTags($product_id) { $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_tags WHERE product_id = '" . (int)$product_id . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'"); return $query->rows; } public function getProductDiscount($product_id) { if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $query = $this->db->query("SELECT price FROM " . DB_PREFIX . "product_discount WHERE product_id = '" . (int)$product_id . "' AND customer_group_id = '" . (int)$customer_group_id . "' AND quantity = '1' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY priority ASC, price ASC LIMIT 1"); if ($query->num_rows) { return $query->row['price']; } else { return FALSE; } } public function getProductDiscounts($product_id) { if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_discount WHERE product_id = '" . (int)$product_id . "' AND customer_group_id = '" . (int)$customer_group_id . "' AND quantity > 1 AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY quantity ASC, priority ASC, price ASC"); return $query->rows; } public function getProductSpecial($product_id) { if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $query = $this->db->query("SELECT price FROM " . DB_PREFIX . "product_special WHERE product_id = '" . (int)$product_id . "' AND customer_group_id = '" . (int)$customer_group_id . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY priority ASC, price ASC LIMIT 1"); if ($query->num_rows) { return $query->row['price']; } else { return FALSE; } } public function getProductSpecials($sort = 'p.sort_order', $order = 'ASC', $start = 0, $limit = 20) { if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $sql = "SELECT *, pd.name AS name, p.price, (SELECT ps2.price FROM " . DB_PREFIX . "product_special ps2 WHERE p.product_id = ps2.product_id AND ps2.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps2.date_start = '0000-00-00' OR ps2.date_start < NOW()) AND (ps2.date_end = '0000-00-00' OR ps2.date_end > NOW())) ORDER BY ps2.priority ASC, ps2.price ASC LIMIT 1) AS special, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "product_special ps ON (p.product_id = ps.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND ps.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW())AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) AND ps.product_id NOT IN (SELECT pd2.product_id FROM " . DB_PREFIX . "product_discount pd2 WHERE p.product_id = pd2.product_id AND pd2.customer_group_id = '" . (int)$customer_group_id . "' AND pd2.quantity = '1' AND ((pd2.date_start = '0000-00-00' OR pd2.date_start < NOW()) AND (pd2.date_end = '0000-00-00' OR pd2.date_end > NOW()))) GROUP BY p.product_id"; $sort_data = array( 'pd.name', 'p.sort_order', 'special', 'rating', 'p.price', 'p.model' ); if (in_array($sort, $sort_data)) { if ($sort == 'pd.name' || $sort == 'p.model') { $sql .= " ORDER BY LCASE(" . $sort . ")"; } else { $sql .= " ORDER BY " . $sort; } } else { $sql .= " ORDER BY p.sort_order"; } if ($order == 'DESC') { $sql .= " DESC"; } else { $sql .= " ASC"; } if ($start < 0) { $start = 0; } $sql .= " LIMIT " . (int)$start . "," . (int)$limit; $query = $this->db->query($sql); return $query->rows; } public function getTotalProductSpecials() { if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $query = $this->db->query("SELECT COUNT(DISTINCT ps.product_id) AS total FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "product_special ps ON (p.product_id = ps.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) AND ps.product_id NOT IN (SELECT pd2.product_id FROM " . DB_PREFIX . "product_discount pd2 WHERE p.product_id = pd2.product_id AND pd2.customer_group_id = '" . (int)$customer_group_id . "' AND pd2.quantity = '1' AND ((pd2.date_start = '0000-00-00' OR pd2.date_start < NOW()) AND (pd2.date_end = '0000-00-00' OR pd2.date_end > NOW())))"); if (isset($query->row['total'])) { return $query->row['total']; } else { return 0; } } public function getProductRelated($product_id) { $product_data = array(); $product_related_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$product_id . "'"); foreach ($product_related_query->rows as $result) { $product_query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.product_id = '" . (int)$result['related_id'] . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.date_available <= NOW() AND p.status = '1'"); if ($product_query->num_rows) { $product_data[$result['related_id']] = $product_query->row; } } return $product_data; } public function getCategories($product_id) { $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_to_category WHERE product_id = '" . (int)$product_id . "'"); return $query->rows; } } ?> Тему можно закрыть с пометкой решено и сделать на нее ссылку в FAQ) Змінено 16 березня 2012 користувачем 1roma1 Надіслати Поділитися на інших сайтах More sharing options... freelancer Опубліковано: 16 березня 2012 Share Опубліковано: 16 березня 2012 Спасибо большое! все работает! В блоке $sort_data = array нужно было не добавить 's_price', а заменить ним 'p.price'. .. это вовсе не обязательно. важное исправление было в другом месте.ну да не суть Надіслати Поділитися на інших сайтах More sharing options... DAN Опубліковано: 22 березня 2012 Share Опубліковано: 22 березня 2012 я описал для версии 0.2.2, для 1.5.1.3 не подойдет А для версии 1.5.1.3 как сделать не подскажите? Надіслати Поділитися на інших сайтах More sharing options... 7 months later... mybay Опубліковано: 31 жовтня 2012 Share Опубліковано: 31 жовтня 2012 большое спасибо! и мне помогло))) Надіслати Поділитися на інших сайтах More sharing options... 7 months later... hon2012 Опубліковано: 10 червня 2013 Share Опубліковано: 10 червня 2013 Добрый день, Скажите а как должен выглядеть код для 1.5.1.3 я попытался добавить но не получилось.?я описал для версии 0.2.2, для 1.5.1.3 не подойдет Уважаемый freelancer, подскажите как сделать для версии 1.5.13 Спасибо Надіслати Поділитися на інших сайтах More sharing options... freelancer Опубліковано: 10 червня 2013 Share Опубліковано: 10 червня 2013 по аналогии. разжевывать не буду Надіслати Поділитися на інших сайтах More sharing options... 3 months later... NoobMan Опубліковано: 7 жовтня 2013 Share Опубліковано: 7 жовтня 2013 Всем привет! Собственно наткнулся на такую проблему/недоработку пока не знаю как назвать. Версия OcStore 0.2.2. Есть каталог продукции с установленной ценой. Например на 2 месяца устанавливаю специальную цену. Она может быть разной относительно первоначальной одинаковой цены в похожих моделях. Например есть 2 товара по цене 700. На один делаю скидку 100, на другой 150. Итого новые цены выходят 600 и 550 соответственно. Проблема заключается в том, что когда в каталоге выбираю сортировку по цене, скрипт сортирует относительно первоначальной цены, без учета специальной. Т.е. таким образом: 700 600, 700 550, 720 610, 740 630, 750 650. Вопрос: это у всех так или только у меня? И если у всех, то кто-то может подсказать как это решить? Поиском пользовался, решений не нашел. Спасибо. Для opencart 1.5.4.1 решение не подскажите? Надіслати Поділитися на інших сайтах More sharing options... 1 year later... Marinka Опубліковано: 11 квітня 2015 Share Опубліковано: 11 квітня 2015 Да, для 1.5.4.1 тоже не могу найти решение! хэлп!!! Надіслати Поділитися на інших сайтах More sharing options... 1 year later... newjey Опубліковано: 11 січня 2017 Share Опубліковано: 11 січня 2017 Подскажите под ocStore 2.1.0.2 как сделать сортировку с учётом акционной цены? Надіслати Поділитися на інших сайтах More sharing options... Створіть аккаунт або увійдіть для коментування Ви повинні бути користувачем, щоб залишити коментар Створити обліковий запис Зареєструйтеся для отримання облікового запису. Це просто! Зареєструвати аккаунт Вхід Уже зареєстровані? Увійдіть тут. Вхід зараз Share More sharing options... Передплатники 0 Перейти до списку тем Зараз на сторінці 0 користувачів Ні користувачів, які переглядиють цю сторінку Последние темы Последние дополнения Последние новости Вся активність Головна Підтримка та відповіді на запитання. Встановлення, оновлення, налаштування Сортировка товаров по цене с учетом скидок Покупцям Оплата розширень фізичними особами Оплата розширень юридичними особами Політика повернень Розробникам Регламент розміщення розширень Регламент продажу та підтримки розширень Віртуальний обліковий запис автора Політика просування оголошень API каталогу розширень Вирішення спорів щодо авторських прав Корисна інформація Публічна оферта Політика повернень Політика конфіденційності Платіжна політика Політика передачі особистих даних Політика прозорості Останні розширення Повний пакет SEO Автор: GeekoDev SameSite Session Fix Opencart 3 Автор: web_bond SP Telegram повідомлення FREE Автор: spectre Відключити порожні категорії Автор: spectre SEO Автор тексту категорії / фільтра / блогу з датою оновлення контенту + мікророзмітка Автор: radaevich × Уже зареєстровані? Ввійти Реєстрація Ваші замовлення Назад Придбані модулі та шаблони Ваші рахунки Лист очікувань Альтернативні контакти Форум Новини ocStore Назад Офіційний сайт Демо ocStore 3.0.3.2 Демо ocStore 2.3.0.2.4 Завантажити ocStore Документація Історія версій ocStore Блоги Модулі Шаблони Назад Безкоштовні шаблони Платні шаблони Де купувати модулі? Послуги FAQ OpenCart.Pro Назад Демо Купити Порівняння × Створити... Important Information На нашому сайті використовуються файли cookie і відбувається обробка деяких персональних даних користувачів, щоб поліпшити користувальницький інтерфейс. Щоб дізнатися для чого і які персональні дані ми обробляємо перейдіть за посиланням . Якщо Ви натиснете «Я даю згоду», це означає, що Ви розумієте і приймаєте всі умови, зазначені в цьому Повідомленні про конфіденційність. Я даю згоду
1roma1 Опубліковано: 15 березня 2012 Автор Share Опубліковано: 15 березня 2012 Извините что так долго не отписывал, был в разъездах, не было возможности проверить. Код представленный здесь действительно работает, и сортирует товар по ценам с учетом текущей акционной цены, но только в каталоге. Если зайти в производители, сортирует по старому. Может еще где-то куда-то что-то нужно прописать? Надіслати Поділитися на інших сайтах More sharing options...
freelancer Опубліковано: 15 березня 2012 Share Опубліковано: 15 березня 2012 Извините что так долго не отписывал, был в разъездах, не было возможности проверить. Код представленный здесь действительно работает, и сортирует товар по ценам с учетом текущей акционной цены, но только в каталоге. Если зайти в производители, сортирует по старому. Может еще где-то куда-то что-то нужно прописать? да. в том же файле точно такие же операции следует проделать в методе getProductsByManufacturerId Надіслати Поділитися на інших сайтах More sharing options... 1roma1 Опубліковано: 15 березня 2012 Автор Share Опубліковано: 15 березня 2012 сделал, но в производителях по-прежнему не работает. выдает ошибку: Notice: Undefined variable: category_id in Z:\home\localhost\www\nb2\catalog\model\catalog\product.php on line 80 ругается на вот это: $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating, ". "coalesce((SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND customer_group_id = '" . (int)$customer_group_id . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY priority ASC, price ASC LIMIT 1), p.price) as s_price ". "FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) LEFT JOIN " . DB_PREFIX . "product_to_category p2c ON (p.product_id = p2c.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2c.category_id = '" . (int)$category_id . "'"; Надіслати Поділитися на інших сайтах More sharing options... freelancer Опубліковано: 16 березня 2012 Share Опубліковано: 16 березня 2012 сделал, но в производителях по-прежнему не работает. выдает ошибку: Notice: Undefined variable: category_id in Z:\home\localhost\www\nb2\catalog\model\catalog\product.php on line 80 возможно я не так выразился.. не нужно было копировать всё.. только разницу public function getProductsByManufacturerId($manufacturer_id, $sort = 'p.sort_order', $order = 'ASC', $start = 0, $limit = 20) { $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND m.manufacturer_id = '" . (int)$manufacturer_id . "'"; if ($sort == 'p.price') { if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating," . "coalesce((SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND customer_group_id = '" . (int)$customer_group_id . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY priority ASC, price ASC LIMIT 1), p.price) as s_price " . " FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND m.manufacturer_id = '" . (int)$manufacturer_id . "'"; $sort = 's_price'; } $sort_data = array( 'pd.name', 'p.sort_order', 'special', 'rating', 's_price', 'p.model' ); 1 Надіслати Поділитися на інших сайтах More sharing options... 1roma1 Опубліковано: 16 березня 2012 Автор Share Опубліковано: 16 березня 2012 (змінено) Спасибо большое! все работает! В блоке $sort_data = array нужно было не добавить 's_price', а заменить ним 'p.price'. Полный код рабочего файла catalog/model/catalog/product.php представил ниже, может кому пригодится (версия OcStore 0.2.2!). <?php class ModelCatalogProduct extends Model { public function getProduct($product_id) { $query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.product_id = '" . (int)$product_id . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.date_available <= NOW() AND p.status = '1'"); return $query->row; } public function getProducts() { $query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, wcd.unit AS weight_class FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) LEFT JOIN " . DB_PREFIX . "weight_class_description wcd ON (p.weight_class_id = wcd.weight_class_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND wcd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.date_available <= NOW() AND p.status = '1'"); return $query->rows; } public function getProductsByCategoryId($category_id, $sort = 'p.sort_order', $order = 'ASC', $start = 0, $limit = 20) { $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) LEFT JOIN " . DB_PREFIX . "product_to_category p2c ON (p.product_id = p2c.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2c.category_id = '" . (int)$category_id . "'"; if ($sort=='p.price'){ if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating, ". "coalesce((SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND customer_group_id = '" . (int)$customer_group_id . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY priority ASC, price ASC LIMIT 1), p.price) as s_price ". "FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) LEFT JOIN " . DB_PREFIX . "product_to_category p2c ON (p.product_id = p2c.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2c.category_id = '" . (int)$category_id . "'"; $sort = 's_price'; } $sort_data = array( 'pd.name', 'p.sort_order', 'special', 'rating', 'p.price', 's_price', 'p.model' ); if (in_array($sort, $sort_data)) { if ($sort == 'pd.name' || $sort == 'p.model') { $sql .= " ORDER BY LCASE(" . $sort . ")"; } else { $sql .= " ORDER BY " . $sort; } } else { $sql .= " ORDER BY p.sort_order"; } if ($order == 'DESC') { $sql .= " DESC"; } else { $sql .= " ASC"; } if ($start < 0) { $start = 0; } $sql .= " LIMIT " . (int)$start . "," . (int)$limit; $query = $this->db->query($sql); return $query->rows; } public function getTotalProductsByCategoryId($category_id = 0) { $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product_to_category p2c LEFT JOIN " . DB_PREFIX . "product p ON (p2c.product_id = p.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND p2c.category_id = '" . (int)$category_id . "'"); return $query->row['total']; } public function getProductsByManufacturerId($manufacturer_id, $sort = 'p.sort_order', $order = 'ASC', $start = 0, $limit = 20) { $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND m.manufacturer_id = '" . (int)$manufacturer_id. "'"; if ($sort == 'p.price') { if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating," . "coalesce((SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND customer_group_id = '" . (int)$customer_group_id . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY priority ASC, price ASC LIMIT 1), p.price) as s_price " . " FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND m.manufacturer_id = '" . (int)$manufacturer_id . "'"; $sort = 's_price'; } $sort_data = array( 'pd.name', 'p.sort_order', 'special', 'rating', 's_price', 'p.model' ); if (in_array($sort, $sort_data)) { if ($sort == 'pd.name' || $sort == 'p.model') { $sql .= " ORDER BY LCASE(" . $sort . ")"; } else { $sql .= " ORDER BY " . $sort; } } else { $sql .= " ORDER BY p.sort_order"; } if ($order == 'DESC') { $sql .= " DESC"; } else { $sql .= " ASC"; } if ($start < 0) { $start = 0; } $sql .= " LIMIT " . (int)$start . "," . (int)$limit; $query = $this->db->query($sql); return $query->rows; } public function getTotalProductsByManufacturerId($manufacturer_id = 0) { $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product WHERE status = '1' AND date_available <= NOW() AND manufacturer_id = '" . (int)$manufacturer_id . "'"); return $query->row['total']; } public function getProductsByTag($tag, $category_id = 0, $sort = 'p.sort_order', $order = 'ASC', $start = 0, $limit = 20) { if ($tag) { $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_tags pt ON (p.product_id = pt.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND pt.language_id = '" . (int)$this->config->get('config_language_id') . "' AND (pt.tag = '" . $this->db->escape($tag) . "'"; $keywords = explode(" ", $tag); foreach ($keywords as $keyword) { $sql .= " OR pt.tag = '" . $this->db->escape($keyword) . "'"; } $sql .= ")"; if ($category_id) { $data = array(); $this->load->model('catalog/category'); $string = rtrim($this->getPath($category_id), ','); foreach (explode(',', $string) as $category_id) { $data[] = "category_id = '" . (int)$category_id . "'"; } $sql .= " AND p.product_id IN (SELECT product_id FROM " . DB_PREFIX . "product_to_category WHERE " . implode(" OR ", $data) . ")"; } $sql .= " AND p.status = '1' AND p.date_available <= NOW() GROUP BY p.product_id"; $sort_data = array( 'pd.name', 'p.sort_order', 'special', 'rating', 'p.price', 'p.model' ); if (in_array($sort, $sort_data)) { if ($sort == 'pd.name' || $sort == 'p.model') { $sql .= " ORDER BY LCASE(" . $sort . ")"; } else { $sql .= " ORDER BY " . $sort; } } else { $sql .= " ORDER BY p.sort_order"; } if ($order == 'DESC') { $sql .= " DESC"; } else { $sql .= " ASC"; } if ($start < 0) { $start = 0; } $sql .= " LIMIT " . (int)$start . "," . (int)$limit; $query = $this->db->query($sql); $products = array(); foreach ($query->rows as $key => $value) { $products[$value['product_id']] = $this->getProduct($value['product_id']); } return $products; } } public function getProductsByKeyword($keyword, $category_id = 0, $description = FALSE, $model = FALSE, $sort = 'p.sort_order', $order = 'ASC', $start = 0, $limit = 20) { if ($keyword) { $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "'"; if (!$description) { $sql .= " AND (pd.name LIKE '%" . $this->db->escape($keyword) . "%'"; } else { $sql .= " AND (pd.name LIKE '%" . $this->db->escape($keyword) . "%' OR pd.description LIKE '%" . $this->db->escape($keyword) . "%'"; } if (!$model) { $sql .= ")"; } else { $sql .= " OR p.model LIKE '%" . $this->db->escape($keyword) . "%')"; } if ($category_id) { $data = array(); $this->load->model('catalog/category'); $string = rtrim($this->getPath($category_id), ','); foreach (explode(',', $string) as $category_id) { $data[] = "category_id = '" . (int)$category_id . "'"; } $sql .= " AND p.product_id IN (SELECT product_id FROM " . DB_PREFIX . "product_to_category WHERE " . implode(" OR ", $data) . ")"; } $sql .= " AND p.status = '1' AND p.date_available <= NOW() GROUP BY p.product_id"; $sort_data = array( 'pd.name', 'p.sort_order', 'special', 'rating', 'p.price', 'p.model' ); if (in_array($sort, $sort_data)) { if ($sort == 'pd.name' || $sort == 'p.model') { $sql .= " ORDER BY LCASE(" . $sort . ")"; } else { $sql .= " ORDER BY " . $sort; } } else { $sql .= " ORDER BY p.sort_order"; } if ($order == 'DESC') { $sql .= " DESC"; } else { $sql .= " ASC"; } if ($start < 0) { $start = 0; } $sql .= " LIMIT " . (int)$start . "," . (int)$limit; $query = $this->db->query($sql); return $query->rows; } return 0; } public function getTotalProductsByKeyword($keyword, $category_id = 0, $description = FALSE, $model = FALSE) { if ($keyword) { $sql = "SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "'"; if (!$description) { $sql .= " AND (pd.name LIKE '%" . $this->db->escape($keyword) . "%'"; } else { $sql .= " AND (pd.name LIKE '%" . $this->db->escape($keyword) . "%' OR pd.description LIKE '%" . $this->db->escape($keyword) . "%'"; } if (!$model) { $sql .= ")"; } else { $sql .= " OR p.model LIKE '%" . $this->db->escape($keyword) . "%')"; } if ($category_id) { $data = array(); $this->load->model('catalog/category'); $string = rtrim($this->getPath($category_id), ','); foreach (explode(',', $string) as $category_id) { $data[] = "category_id = '" . (int)$category_id . "'"; } $sql .= " AND p.product_id IN (SELECT product_id FROM " . DB_PREFIX . "product_to_category WHERE " . implode(" OR ", $data) . ")"; } $sql .= " AND p.status = '1' AND p.date_available <= NOW()"; $query = $this->db->query($sql); if ($query->num_rows) { return $query->row['total']; } else { return 0; } } return 0; } public function getTotalProductsByTag($tag, $category_id = 0) { if ($tag) { $sql = "SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_tags pt ON (p.product_id = pt.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND pt.language_id = '" . (int)$this->config->get('config_language_id') . "' AND (pt.tag = '" . $this->db->escape($tag) . "'"; $keywords = explode(" ", $tag); foreach ($keywords as $keyword) { $sql .= " OR pt.tag = '" . $this->db->escape($keyword) . "'"; } $sql .= ")"; if ($category_id) { $data = array(); $this->load->model('catalog/category'); $string = rtrim($this->getPath($category_id), ','); foreach (explode(',', $string) as $category_id) { $data[] = "category_id = '" . (int)$category_id . "'"; } $sql .= " AND p.product_id IN (SELECT product_id FROM " . DB_PREFIX . "product_to_category WHERE " . implode(" OR ", $data) . ")"; } $sql .= " AND p.status = '1' AND p.date_available <= NOW()"; $query = $this->db->query($sql); if ($query->num_rows) { return $query->row['total']; } else { return 0; } } return 0; } public function getPath($category_id) { $string = $category_id . ','; $results = $this->model_catalog_category->getCategories($category_id); foreach ($results as $result) { $string .= $this->getPath($result['category_id']); } return $string; } public function getLatestProducts($limit) { $product_data = $this->cache->get('product.latest.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit); if (!$product_data) { $query = $this->db->query("SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY p.date_added DESC LIMIT " . (int)$limit); $product_data = $query->rows; $this->cache->set('product.latest.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit, $product_data); } return $product_data; } public function getPopularProducts($limit) { $query = $this->db->query("SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY p.viewed, p.date_added DESC LIMIT " . (int)$limit); return $query->rows; } public function getFeaturedProducts($limit) { $product_data = $this->cache->get('product.featured.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit); if (!$product_data) { $query = $this->db->query("SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product_featured f LEFT JOIN " . DB_PREFIX . "product p ON (f.product_id=p.product_id) LEFT JOIN " . DB_PREFIX . "product_description pd ON (f.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' LIMIT " . (int)$limit); $product_data = $query->rows; $this->cache->set('product.featured.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit, $product_data); } return $product_data; } public function getBestSellerProducts($limit) { $product_data = $this->cache->get('product.bestseller.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit); if (!$product_data) { $product_data = array(); $query = $this->db->query("SELECT op.product_id, SUM(op.quantity) AS total, p.status FROM " . DB_PREFIX . "order_product op LEFT JOIN `" . DB_PREFIX . "order` o ON (op.order_id = o.order_id) LEFT JOIN `" . DB_PREFIX . "product` p ON (op.product_id = p.product_id) WHERE o.order_status_id > '0' AND p.status = '1' GROUP BY op.product_id, p.status ORDER BY total DESC LIMIT " . (int)$limit); foreach ($query->rows as $result) { $product_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE p.product_id = '" . (int)$result['product_id'] . "' AND p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "'"); if ($product_query->num_rows) { $product_data[] = $product_query->row; } } $this->cache->set('product.bestseller.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit, $product_data); } return $product_data; } public function updateViewed($product_id) { $this->db->query("UPDATE " . DB_PREFIX . "product SET viewed = viewed + 1 WHERE product_id = '" . (int)$product_id . "'"); } public function getProductOptions($product_id) { $product_option_data = array(); $product_option_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option WHERE product_id = '" . (int)$product_id . "' ORDER BY sort_order"); foreach ($product_option_query->rows as $product_option) { $product_option_value_data = array(); $product_option_value_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option_value WHERE product_option_id = '" . (int)$product_option['product_option_id'] . "' ORDER BY sort_order"); foreach ($product_option_value_query->rows as $product_option_value) { $product_option_value_description_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option_value_description WHERE product_option_value_id = '" . (int)$product_option_value['product_option_value_id'] . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'"); $product_option_value_data[] = array( 'product_option_value_id' => $product_option_value['product_option_value_id'], 'name' => $product_option_value_description_query->row['name'], 'price' => $product_option_value['price'], 'prefix' => $product_option_value['prefix'], 'quantity' => $product_option_value['quantity'] /* webme - options show|hide - mod */ ); } $product_option_description_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option_description WHERE product_option_id = '" . (int)$product_option['product_option_id'] . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'"); $product_option_data[] = array( 'product_option_id' => $product_option['product_option_id'], 'name' => $product_option_description_query->row['name'], 'option_value' => $product_option_value_data, 'sort_order' => $product_option['sort_order'] ); } return $product_option_data; } public function getProductImages($product_id) { $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_image WHERE product_id = '" . (int)$product_id . "'"); return $query->rows; } public function getProductTags($product_id) { $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_tags WHERE product_id = '" . (int)$product_id . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'"); return $query->rows; } public function getProductDiscount($product_id) { if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $query = $this->db->query("SELECT price FROM " . DB_PREFIX . "product_discount WHERE product_id = '" . (int)$product_id . "' AND customer_group_id = '" . (int)$customer_group_id . "' AND quantity = '1' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY priority ASC, price ASC LIMIT 1"); if ($query->num_rows) { return $query->row['price']; } else { return FALSE; } } public function getProductDiscounts($product_id) { if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_discount WHERE product_id = '" . (int)$product_id . "' AND customer_group_id = '" . (int)$customer_group_id . "' AND quantity > 1 AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY quantity ASC, priority ASC, price ASC"); return $query->rows; } public function getProductSpecial($product_id) { if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $query = $this->db->query("SELECT price FROM " . DB_PREFIX . "product_special WHERE product_id = '" . (int)$product_id . "' AND customer_group_id = '" . (int)$customer_group_id . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY priority ASC, price ASC LIMIT 1"); if ($query->num_rows) { return $query->row['price']; } else { return FALSE; } } public function getProductSpecials($sort = 'p.sort_order', $order = 'ASC', $start = 0, $limit = 20) { if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $sql = "SELECT *, pd.name AS name, p.price, (SELECT ps2.price FROM " . DB_PREFIX . "product_special ps2 WHERE p.product_id = ps2.product_id AND ps2.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps2.date_start = '0000-00-00' OR ps2.date_start < NOW()) AND (ps2.date_end = '0000-00-00' OR ps2.date_end > NOW())) ORDER BY ps2.priority ASC, ps2.price ASC LIMIT 1) AS special, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "product_special ps ON (p.product_id = ps.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND ps.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW())AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) AND ps.product_id NOT IN (SELECT pd2.product_id FROM " . DB_PREFIX . "product_discount pd2 WHERE p.product_id = pd2.product_id AND pd2.customer_group_id = '" . (int)$customer_group_id . "' AND pd2.quantity = '1' AND ((pd2.date_start = '0000-00-00' OR pd2.date_start < NOW()) AND (pd2.date_end = '0000-00-00' OR pd2.date_end > NOW()))) GROUP BY p.product_id"; $sort_data = array( 'pd.name', 'p.sort_order', 'special', 'rating', 'p.price', 'p.model' ); if (in_array($sort, $sort_data)) { if ($sort == 'pd.name' || $sort == 'p.model') { $sql .= " ORDER BY LCASE(" . $sort . ")"; } else { $sql .= " ORDER BY " . $sort; } } else { $sql .= " ORDER BY p.sort_order"; } if ($order == 'DESC') { $sql .= " DESC"; } else { $sql .= " ASC"; } if ($start < 0) { $start = 0; } $sql .= " LIMIT " . (int)$start . "," . (int)$limit; $query = $this->db->query($sql); return $query->rows; } public function getTotalProductSpecials() { if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $query = $this->db->query("SELECT COUNT(DISTINCT ps.product_id) AS total FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "product_special ps ON (p.product_id = ps.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) AND ps.product_id NOT IN (SELECT pd2.product_id FROM " . DB_PREFIX . "product_discount pd2 WHERE p.product_id = pd2.product_id AND pd2.customer_group_id = '" . (int)$customer_group_id . "' AND pd2.quantity = '1' AND ((pd2.date_start = '0000-00-00' OR pd2.date_start < NOW()) AND (pd2.date_end = '0000-00-00' OR pd2.date_end > NOW())))"); if (isset($query->row['total'])) { return $query->row['total']; } else { return 0; } } public function getProductRelated($product_id) { $product_data = array(); $product_related_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$product_id . "'"); foreach ($product_related_query->rows as $result) { $product_query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.product_id = '" . (int)$result['related_id'] . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.date_available <= NOW() AND p.status = '1'"); if ($product_query->num_rows) { $product_data[$result['related_id']] = $product_query->row; } } return $product_data; } public function getCategories($product_id) { $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_to_category WHERE product_id = '" . (int)$product_id . "'"); return $query->rows; } } ?> Тему можно закрыть с пометкой решено и сделать на нее ссылку в FAQ) Змінено 16 березня 2012 користувачем 1roma1 Надіслати Поділитися на інших сайтах More sharing options... freelancer Опубліковано: 16 березня 2012 Share Опубліковано: 16 березня 2012 Спасибо большое! все работает! В блоке $sort_data = array нужно было не добавить 's_price', а заменить ним 'p.price'. .. это вовсе не обязательно. важное исправление было в другом месте.ну да не суть Надіслати Поділитися на інших сайтах More sharing options... DAN Опубліковано: 22 березня 2012 Share Опубліковано: 22 березня 2012 я описал для версии 0.2.2, для 1.5.1.3 не подойдет А для версии 1.5.1.3 как сделать не подскажите? Надіслати Поділитися на інших сайтах More sharing options... 7 months later... mybay Опубліковано: 31 жовтня 2012 Share Опубліковано: 31 жовтня 2012 большое спасибо! и мне помогло))) Надіслати Поділитися на інших сайтах More sharing options... 7 months later... hon2012 Опубліковано: 10 червня 2013 Share Опубліковано: 10 червня 2013 Добрый день, Скажите а как должен выглядеть код для 1.5.1.3 я попытался добавить но не получилось.?я описал для версии 0.2.2, для 1.5.1.3 не подойдет Уважаемый freelancer, подскажите как сделать для версии 1.5.13 Спасибо Надіслати Поділитися на інших сайтах More sharing options... freelancer Опубліковано: 10 червня 2013 Share Опубліковано: 10 червня 2013 по аналогии. разжевывать не буду Надіслати Поділитися на інших сайтах More sharing options... 3 months later... NoobMan Опубліковано: 7 жовтня 2013 Share Опубліковано: 7 жовтня 2013 Всем привет! Собственно наткнулся на такую проблему/недоработку пока не знаю как назвать. Версия OcStore 0.2.2. Есть каталог продукции с установленной ценой. Например на 2 месяца устанавливаю специальную цену. Она может быть разной относительно первоначальной одинаковой цены в похожих моделях. Например есть 2 товара по цене 700. На один делаю скидку 100, на другой 150. Итого новые цены выходят 600 и 550 соответственно. Проблема заключается в том, что когда в каталоге выбираю сортировку по цене, скрипт сортирует относительно первоначальной цены, без учета специальной. Т.е. таким образом: 700 600, 700 550, 720 610, 740 630, 750 650. Вопрос: это у всех так или только у меня? И если у всех, то кто-то может подсказать как это решить? Поиском пользовался, решений не нашел. Спасибо. Для opencart 1.5.4.1 решение не подскажите? Надіслати Поділитися на інших сайтах More sharing options... 1 year later... Marinka Опубліковано: 11 квітня 2015 Share Опубліковано: 11 квітня 2015 Да, для 1.5.4.1 тоже не могу найти решение! хэлп!!! Надіслати Поділитися на інших сайтах More sharing options... 1 year later... newjey Опубліковано: 11 січня 2017 Share Опубліковано: 11 січня 2017 Подскажите под ocStore 2.1.0.2 как сделать сортировку с учётом акционной цены? Надіслати Поділитися на інших сайтах More sharing options... Створіть аккаунт або увійдіть для коментування Ви повинні бути користувачем, щоб залишити коментар Створити обліковий запис Зареєструйтеся для отримання облікового запису. Це просто! Зареєструвати аккаунт Вхід Уже зареєстровані? Увійдіть тут. Вхід зараз Share More sharing options... Передплатники 0 Перейти до списку тем Зараз на сторінці 0 користувачів Ні користувачів, які переглядиють цю сторінку Последние темы Последние дополнения Последние новости Вся активність Головна Підтримка та відповіді на запитання. Встановлення, оновлення, налаштування Сортировка товаров по цене с учетом скидок Покупцям Оплата розширень фізичними особами Оплата розширень юридичними особами Політика повернень Розробникам Регламент розміщення розширень Регламент продажу та підтримки розширень Віртуальний обліковий запис автора Політика просування оголошень API каталогу розширень Вирішення спорів щодо авторських прав Корисна інформація Публічна оферта Політика повернень Політика конфіденційності Платіжна політика Політика передачі особистих даних Політика прозорості Останні розширення Повний пакет SEO Автор: GeekoDev SameSite Session Fix Opencart 3 Автор: web_bond SP Telegram повідомлення FREE Автор: spectre Відключити порожні категорії Автор: spectre SEO Автор тексту категорії / фільтра / блогу з датою оновлення контенту + мікророзмітка Автор: radaevich
1roma1 Опубліковано: 15 березня 2012 Автор Share Опубліковано: 15 березня 2012 сделал, но в производителях по-прежнему не работает. выдает ошибку: Notice: Undefined variable: category_id in Z:\home\localhost\www\nb2\catalog\model\catalog\product.php on line 80 ругается на вот это: $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating, ". "coalesce((SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND customer_group_id = '" . (int)$customer_group_id . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY priority ASC, price ASC LIMIT 1), p.price) as s_price ". "FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) LEFT JOIN " . DB_PREFIX . "product_to_category p2c ON (p.product_id = p2c.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2c.category_id = '" . (int)$category_id . "'"; Надіслати Поділитися на інших сайтах More sharing options...
freelancer Опубліковано: 16 березня 2012 Share Опубліковано: 16 березня 2012 сделал, но в производителях по-прежнему не работает. выдает ошибку: Notice: Undefined variable: category_id in Z:\home\localhost\www\nb2\catalog\model\catalog\product.php on line 80 возможно я не так выразился.. не нужно было копировать всё.. только разницу public function getProductsByManufacturerId($manufacturer_id, $sort = 'p.sort_order', $order = 'ASC', $start = 0, $limit = 20) { $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND m.manufacturer_id = '" . (int)$manufacturer_id . "'"; if ($sort == 'p.price') { if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating," . "coalesce((SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND customer_group_id = '" . (int)$customer_group_id . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY priority ASC, price ASC LIMIT 1), p.price) as s_price " . " FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND m.manufacturer_id = '" . (int)$manufacturer_id . "'"; $sort = 's_price'; } $sort_data = array( 'pd.name', 'p.sort_order', 'special', 'rating', 's_price', 'p.model' ); 1 Надіслати Поділитися на інших сайтах More sharing options... 1roma1 Опубліковано: 16 березня 2012 Автор Share Опубліковано: 16 березня 2012 (змінено) Спасибо большое! все работает! В блоке $sort_data = array нужно было не добавить 's_price', а заменить ним 'p.price'. Полный код рабочего файла catalog/model/catalog/product.php представил ниже, может кому пригодится (версия OcStore 0.2.2!). <?php class ModelCatalogProduct extends Model { public function getProduct($product_id) { $query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.product_id = '" . (int)$product_id . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.date_available <= NOW() AND p.status = '1'"); return $query->row; } public function getProducts() { $query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, wcd.unit AS weight_class FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) LEFT JOIN " . DB_PREFIX . "weight_class_description wcd ON (p.weight_class_id = wcd.weight_class_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND wcd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.date_available <= NOW() AND p.status = '1'"); return $query->rows; } public function getProductsByCategoryId($category_id, $sort = 'p.sort_order', $order = 'ASC', $start = 0, $limit = 20) { $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) LEFT JOIN " . DB_PREFIX . "product_to_category p2c ON (p.product_id = p2c.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2c.category_id = '" . (int)$category_id . "'"; if ($sort=='p.price'){ if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating, ". "coalesce((SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND customer_group_id = '" . (int)$customer_group_id . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY priority ASC, price ASC LIMIT 1), p.price) as s_price ". "FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) LEFT JOIN " . DB_PREFIX . "product_to_category p2c ON (p.product_id = p2c.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2c.category_id = '" . (int)$category_id . "'"; $sort = 's_price'; } $sort_data = array( 'pd.name', 'p.sort_order', 'special', 'rating', 'p.price', 's_price', 'p.model' ); if (in_array($sort, $sort_data)) { if ($sort == 'pd.name' || $sort == 'p.model') { $sql .= " ORDER BY LCASE(" . $sort . ")"; } else { $sql .= " ORDER BY " . $sort; } } else { $sql .= " ORDER BY p.sort_order"; } if ($order == 'DESC') { $sql .= " DESC"; } else { $sql .= " ASC"; } if ($start < 0) { $start = 0; } $sql .= " LIMIT " . (int)$start . "," . (int)$limit; $query = $this->db->query($sql); return $query->rows; } public function getTotalProductsByCategoryId($category_id = 0) { $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product_to_category p2c LEFT JOIN " . DB_PREFIX . "product p ON (p2c.product_id = p.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND p2c.category_id = '" . (int)$category_id . "'"); return $query->row['total']; } public function getProductsByManufacturerId($manufacturer_id, $sort = 'p.sort_order', $order = 'ASC', $start = 0, $limit = 20) { $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND m.manufacturer_id = '" . (int)$manufacturer_id. "'"; if ($sort == 'p.price') { if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating," . "coalesce((SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND customer_group_id = '" . (int)$customer_group_id . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY priority ASC, price ASC LIMIT 1), p.price) as s_price " . " FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND m.manufacturer_id = '" . (int)$manufacturer_id . "'"; $sort = 's_price'; } $sort_data = array( 'pd.name', 'p.sort_order', 'special', 'rating', 's_price', 'p.model' ); if (in_array($sort, $sort_data)) { if ($sort == 'pd.name' || $sort == 'p.model') { $sql .= " ORDER BY LCASE(" . $sort . ")"; } else { $sql .= " ORDER BY " . $sort; } } else { $sql .= " ORDER BY p.sort_order"; } if ($order == 'DESC') { $sql .= " DESC"; } else { $sql .= " ASC"; } if ($start < 0) { $start = 0; } $sql .= " LIMIT " . (int)$start . "," . (int)$limit; $query = $this->db->query($sql); return $query->rows; } public function getTotalProductsByManufacturerId($manufacturer_id = 0) { $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product WHERE status = '1' AND date_available <= NOW() AND manufacturer_id = '" . (int)$manufacturer_id . "'"); return $query->row['total']; } public function getProductsByTag($tag, $category_id = 0, $sort = 'p.sort_order', $order = 'ASC', $start = 0, $limit = 20) { if ($tag) { $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_tags pt ON (p.product_id = pt.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND pt.language_id = '" . (int)$this->config->get('config_language_id') . "' AND (pt.tag = '" . $this->db->escape($tag) . "'"; $keywords = explode(" ", $tag); foreach ($keywords as $keyword) { $sql .= " OR pt.tag = '" . $this->db->escape($keyword) . "'"; } $sql .= ")"; if ($category_id) { $data = array(); $this->load->model('catalog/category'); $string = rtrim($this->getPath($category_id), ','); foreach (explode(',', $string) as $category_id) { $data[] = "category_id = '" . (int)$category_id . "'"; } $sql .= " AND p.product_id IN (SELECT product_id FROM " . DB_PREFIX . "product_to_category WHERE " . implode(" OR ", $data) . ")"; } $sql .= " AND p.status = '1' AND p.date_available <= NOW() GROUP BY p.product_id"; $sort_data = array( 'pd.name', 'p.sort_order', 'special', 'rating', 'p.price', 'p.model' ); if (in_array($sort, $sort_data)) { if ($sort == 'pd.name' || $sort == 'p.model') { $sql .= " ORDER BY LCASE(" . $sort . ")"; } else { $sql .= " ORDER BY " . $sort; } } else { $sql .= " ORDER BY p.sort_order"; } if ($order == 'DESC') { $sql .= " DESC"; } else { $sql .= " ASC"; } if ($start < 0) { $start = 0; } $sql .= " LIMIT " . (int)$start . "," . (int)$limit; $query = $this->db->query($sql); $products = array(); foreach ($query->rows as $key => $value) { $products[$value['product_id']] = $this->getProduct($value['product_id']); } return $products; } } public function getProductsByKeyword($keyword, $category_id = 0, $description = FALSE, $model = FALSE, $sort = 'p.sort_order', $order = 'ASC', $start = 0, $limit = 20) { if ($keyword) { $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "'"; if (!$description) { $sql .= " AND (pd.name LIKE '%" . $this->db->escape($keyword) . "%'"; } else { $sql .= " AND (pd.name LIKE '%" . $this->db->escape($keyword) . "%' OR pd.description LIKE '%" . $this->db->escape($keyword) . "%'"; } if (!$model) { $sql .= ")"; } else { $sql .= " OR p.model LIKE '%" . $this->db->escape($keyword) . "%')"; } if ($category_id) { $data = array(); $this->load->model('catalog/category'); $string = rtrim($this->getPath($category_id), ','); foreach (explode(',', $string) as $category_id) { $data[] = "category_id = '" . (int)$category_id . "'"; } $sql .= " AND p.product_id IN (SELECT product_id FROM " . DB_PREFIX . "product_to_category WHERE " . implode(" OR ", $data) . ")"; } $sql .= " AND p.status = '1' AND p.date_available <= NOW() GROUP BY p.product_id"; $sort_data = array( 'pd.name', 'p.sort_order', 'special', 'rating', 'p.price', 'p.model' ); if (in_array($sort, $sort_data)) { if ($sort == 'pd.name' || $sort == 'p.model') { $sql .= " ORDER BY LCASE(" . $sort . ")"; } else { $sql .= " ORDER BY " . $sort; } } else { $sql .= " ORDER BY p.sort_order"; } if ($order == 'DESC') { $sql .= " DESC"; } else { $sql .= " ASC"; } if ($start < 0) { $start = 0; } $sql .= " LIMIT " . (int)$start . "," . (int)$limit; $query = $this->db->query($sql); return $query->rows; } return 0; } public function getTotalProductsByKeyword($keyword, $category_id = 0, $description = FALSE, $model = FALSE) { if ($keyword) { $sql = "SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "'"; if (!$description) { $sql .= " AND (pd.name LIKE '%" . $this->db->escape($keyword) . "%'"; } else { $sql .= " AND (pd.name LIKE '%" . $this->db->escape($keyword) . "%' OR pd.description LIKE '%" . $this->db->escape($keyword) . "%'"; } if (!$model) { $sql .= ")"; } else { $sql .= " OR p.model LIKE '%" . $this->db->escape($keyword) . "%')"; } if ($category_id) { $data = array(); $this->load->model('catalog/category'); $string = rtrim($this->getPath($category_id), ','); foreach (explode(',', $string) as $category_id) { $data[] = "category_id = '" . (int)$category_id . "'"; } $sql .= " AND p.product_id IN (SELECT product_id FROM " . DB_PREFIX . "product_to_category WHERE " . implode(" OR ", $data) . ")"; } $sql .= " AND p.status = '1' AND p.date_available <= NOW()"; $query = $this->db->query($sql); if ($query->num_rows) { return $query->row['total']; } else { return 0; } } return 0; } public function getTotalProductsByTag($tag, $category_id = 0) { if ($tag) { $sql = "SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_tags pt ON (p.product_id = pt.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND pt.language_id = '" . (int)$this->config->get('config_language_id') . "' AND (pt.tag = '" . $this->db->escape($tag) . "'"; $keywords = explode(" ", $tag); foreach ($keywords as $keyword) { $sql .= " OR pt.tag = '" . $this->db->escape($keyword) . "'"; } $sql .= ")"; if ($category_id) { $data = array(); $this->load->model('catalog/category'); $string = rtrim($this->getPath($category_id), ','); foreach (explode(',', $string) as $category_id) { $data[] = "category_id = '" . (int)$category_id . "'"; } $sql .= " AND p.product_id IN (SELECT product_id FROM " . DB_PREFIX . "product_to_category WHERE " . implode(" OR ", $data) . ")"; } $sql .= " AND p.status = '1' AND p.date_available <= NOW()"; $query = $this->db->query($sql); if ($query->num_rows) { return $query->row['total']; } else { return 0; } } return 0; } public function getPath($category_id) { $string = $category_id . ','; $results = $this->model_catalog_category->getCategories($category_id); foreach ($results as $result) { $string .= $this->getPath($result['category_id']); } return $string; } public function getLatestProducts($limit) { $product_data = $this->cache->get('product.latest.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit); if (!$product_data) { $query = $this->db->query("SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY p.date_added DESC LIMIT " . (int)$limit); $product_data = $query->rows; $this->cache->set('product.latest.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit, $product_data); } return $product_data; } public function getPopularProducts($limit) { $query = $this->db->query("SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY p.viewed, p.date_added DESC LIMIT " . (int)$limit); return $query->rows; } public function getFeaturedProducts($limit) { $product_data = $this->cache->get('product.featured.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit); if (!$product_data) { $query = $this->db->query("SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product_featured f LEFT JOIN " . DB_PREFIX . "product p ON (f.product_id=p.product_id) LEFT JOIN " . DB_PREFIX . "product_description pd ON (f.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' LIMIT " . (int)$limit); $product_data = $query->rows; $this->cache->set('product.featured.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit, $product_data); } return $product_data; } public function getBestSellerProducts($limit) { $product_data = $this->cache->get('product.bestseller.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit); if (!$product_data) { $product_data = array(); $query = $this->db->query("SELECT op.product_id, SUM(op.quantity) AS total, p.status FROM " . DB_PREFIX . "order_product op LEFT JOIN `" . DB_PREFIX . "order` o ON (op.order_id = o.order_id) LEFT JOIN `" . DB_PREFIX . "product` p ON (op.product_id = p.product_id) WHERE o.order_status_id > '0' AND p.status = '1' GROUP BY op.product_id, p.status ORDER BY total DESC LIMIT " . (int)$limit); foreach ($query->rows as $result) { $product_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE p.product_id = '" . (int)$result['product_id'] . "' AND p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "'"); if ($product_query->num_rows) { $product_data[] = $product_query->row; } } $this->cache->set('product.bestseller.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit, $product_data); } return $product_data; } public function updateViewed($product_id) { $this->db->query("UPDATE " . DB_PREFIX . "product SET viewed = viewed + 1 WHERE product_id = '" . (int)$product_id . "'"); } public function getProductOptions($product_id) { $product_option_data = array(); $product_option_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option WHERE product_id = '" . (int)$product_id . "' ORDER BY sort_order"); foreach ($product_option_query->rows as $product_option) { $product_option_value_data = array(); $product_option_value_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option_value WHERE product_option_id = '" . (int)$product_option['product_option_id'] . "' ORDER BY sort_order"); foreach ($product_option_value_query->rows as $product_option_value) { $product_option_value_description_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option_value_description WHERE product_option_value_id = '" . (int)$product_option_value['product_option_value_id'] . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'"); $product_option_value_data[] = array( 'product_option_value_id' => $product_option_value['product_option_value_id'], 'name' => $product_option_value_description_query->row['name'], 'price' => $product_option_value['price'], 'prefix' => $product_option_value['prefix'], 'quantity' => $product_option_value['quantity'] /* webme - options show|hide - mod */ ); } $product_option_description_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option_description WHERE product_option_id = '" . (int)$product_option['product_option_id'] . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'"); $product_option_data[] = array( 'product_option_id' => $product_option['product_option_id'], 'name' => $product_option_description_query->row['name'], 'option_value' => $product_option_value_data, 'sort_order' => $product_option['sort_order'] ); } return $product_option_data; } public function getProductImages($product_id) { $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_image WHERE product_id = '" . (int)$product_id . "'"); return $query->rows; } public function getProductTags($product_id) { $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_tags WHERE product_id = '" . (int)$product_id . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'"); return $query->rows; } public function getProductDiscount($product_id) { if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $query = $this->db->query("SELECT price FROM " . DB_PREFIX . "product_discount WHERE product_id = '" . (int)$product_id . "' AND customer_group_id = '" . (int)$customer_group_id . "' AND quantity = '1' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY priority ASC, price ASC LIMIT 1"); if ($query->num_rows) { return $query->row['price']; } else { return FALSE; } } public function getProductDiscounts($product_id) { if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_discount WHERE product_id = '" . (int)$product_id . "' AND customer_group_id = '" . (int)$customer_group_id . "' AND quantity > 1 AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY quantity ASC, priority ASC, price ASC"); return $query->rows; } public function getProductSpecial($product_id) { if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $query = $this->db->query("SELECT price FROM " . DB_PREFIX . "product_special WHERE product_id = '" . (int)$product_id . "' AND customer_group_id = '" . (int)$customer_group_id . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY priority ASC, price ASC LIMIT 1"); if ($query->num_rows) { return $query->row['price']; } else { return FALSE; } } public function getProductSpecials($sort = 'p.sort_order', $order = 'ASC', $start = 0, $limit = 20) { if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $sql = "SELECT *, pd.name AS name, p.price, (SELECT ps2.price FROM " . DB_PREFIX . "product_special ps2 WHERE p.product_id = ps2.product_id AND ps2.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps2.date_start = '0000-00-00' OR ps2.date_start < NOW()) AND (ps2.date_end = '0000-00-00' OR ps2.date_end > NOW())) ORDER BY ps2.priority ASC, ps2.price ASC LIMIT 1) AS special, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "product_special ps ON (p.product_id = ps.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND ps.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW())AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) AND ps.product_id NOT IN (SELECT pd2.product_id FROM " . DB_PREFIX . "product_discount pd2 WHERE p.product_id = pd2.product_id AND pd2.customer_group_id = '" . (int)$customer_group_id . "' AND pd2.quantity = '1' AND ((pd2.date_start = '0000-00-00' OR pd2.date_start < NOW()) AND (pd2.date_end = '0000-00-00' OR pd2.date_end > NOW()))) GROUP BY p.product_id"; $sort_data = array( 'pd.name', 'p.sort_order', 'special', 'rating', 'p.price', 'p.model' ); if (in_array($sort, $sort_data)) { if ($sort == 'pd.name' || $sort == 'p.model') { $sql .= " ORDER BY LCASE(" . $sort . ")"; } else { $sql .= " ORDER BY " . $sort; } } else { $sql .= " ORDER BY p.sort_order"; } if ($order == 'DESC') { $sql .= " DESC"; } else { $sql .= " ASC"; } if ($start < 0) { $start = 0; } $sql .= " LIMIT " . (int)$start . "," . (int)$limit; $query = $this->db->query($sql); return $query->rows; } public function getTotalProductSpecials() { if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $query = $this->db->query("SELECT COUNT(DISTINCT ps.product_id) AS total FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "product_special ps ON (p.product_id = ps.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) AND ps.product_id NOT IN (SELECT pd2.product_id FROM " . DB_PREFIX . "product_discount pd2 WHERE p.product_id = pd2.product_id AND pd2.customer_group_id = '" . (int)$customer_group_id . "' AND pd2.quantity = '1' AND ((pd2.date_start = '0000-00-00' OR pd2.date_start < NOW()) AND (pd2.date_end = '0000-00-00' OR pd2.date_end > NOW())))"); if (isset($query->row['total'])) { return $query->row['total']; } else { return 0; } } public function getProductRelated($product_id) { $product_data = array(); $product_related_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$product_id . "'"); foreach ($product_related_query->rows as $result) { $product_query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.product_id = '" . (int)$result['related_id'] . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.date_available <= NOW() AND p.status = '1'"); if ($product_query->num_rows) { $product_data[$result['related_id']] = $product_query->row; } } return $product_data; } public function getCategories($product_id) { $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_to_category WHERE product_id = '" . (int)$product_id . "'"); return $query->rows; } } ?> Тему можно закрыть с пометкой решено и сделать на нее ссылку в FAQ) Змінено 16 березня 2012 користувачем 1roma1 Надіслати Поділитися на інших сайтах More sharing options... freelancer Опубліковано: 16 березня 2012 Share Опубліковано: 16 березня 2012 Спасибо большое! все работает! В блоке $sort_data = array нужно было не добавить 's_price', а заменить ним 'p.price'. .. это вовсе не обязательно. важное исправление было в другом месте.ну да не суть Надіслати Поділитися на інших сайтах More sharing options... DAN Опубліковано: 22 березня 2012 Share Опубліковано: 22 березня 2012 я описал для версии 0.2.2, для 1.5.1.3 не подойдет А для версии 1.5.1.3 как сделать не подскажите? Надіслати Поділитися на інших сайтах More sharing options... 7 months later... mybay Опубліковано: 31 жовтня 2012 Share Опубліковано: 31 жовтня 2012 большое спасибо! и мне помогло))) Надіслати Поділитися на інших сайтах More sharing options... 7 months later... hon2012 Опубліковано: 10 червня 2013 Share Опубліковано: 10 червня 2013 Добрый день, Скажите а как должен выглядеть код для 1.5.1.3 я попытался добавить но не получилось.?я описал для версии 0.2.2, для 1.5.1.3 не подойдет Уважаемый freelancer, подскажите как сделать для версии 1.5.13 Спасибо Надіслати Поділитися на інших сайтах More sharing options... freelancer Опубліковано: 10 червня 2013 Share Опубліковано: 10 червня 2013 по аналогии. разжевывать не буду Надіслати Поділитися на інших сайтах More sharing options... 3 months later... NoobMan Опубліковано: 7 жовтня 2013 Share Опубліковано: 7 жовтня 2013 Всем привет! Собственно наткнулся на такую проблему/недоработку пока не знаю как назвать. Версия OcStore 0.2.2. Есть каталог продукции с установленной ценой. Например на 2 месяца устанавливаю специальную цену. Она может быть разной относительно первоначальной одинаковой цены в похожих моделях. Например есть 2 товара по цене 700. На один делаю скидку 100, на другой 150. Итого новые цены выходят 600 и 550 соответственно. Проблема заключается в том, что когда в каталоге выбираю сортировку по цене, скрипт сортирует относительно первоначальной цены, без учета специальной. Т.е. таким образом: 700 600, 700 550, 720 610, 740 630, 750 650. Вопрос: это у всех так или только у меня? И если у всех, то кто-то может подсказать как это решить? Поиском пользовался, решений не нашел. Спасибо. Для opencart 1.5.4.1 решение не подскажите? Надіслати Поділитися на інших сайтах More sharing options... 1 year later... Marinka Опубліковано: 11 квітня 2015 Share Опубліковано: 11 квітня 2015 Да, для 1.5.4.1 тоже не могу найти решение! хэлп!!! Надіслати Поділитися на інших сайтах More sharing options... 1 year later... newjey Опубліковано: 11 січня 2017 Share Опубліковано: 11 січня 2017 Подскажите под ocStore 2.1.0.2 как сделать сортировку с учётом акционной цены? Надіслати Поділитися на інших сайтах More sharing options... Створіть аккаунт або увійдіть для коментування Ви повинні бути користувачем, щоб залишити коментар Створити обліковий запис Зареєструйтеся для отримання облікового запису. Це просто! Зареєструвати аккаунт Вхід Уже зареєстровані? Увійдіть тут. Вхід зараз Share More sharing options... Передплатники 0 Перейти до списку тем Зараз на сторінці 0 користувачів Ні користувачів, які переглядиють цю сторінку Последние темы Последние дополнения Последние новости Вся активність Головна Підтримка та відповіді на запитання. Встановлення, оновлення, налаштування Сортировка товаров по цене с учетом скидок
1roma1 Опубліковано: 16 березня 2012 Автор Share Опубліковано: 16 березня 2012 (змінено) Спасибо большое! все работает! В блоке $sort_data = array нужно было не добавить 's_price', а заменить ним 'p.price'. Полный код рабочего файла catalog/model/catalog/product.php представил ниже, может кому пригодится (версия OcStore 0.2.2!). <?php class ModelCatalogProduct extends Model { public function getProduct($product_id) { $query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.product_id = '" . (int)$product_id . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.date_available <= NOW() AND p.status = '1'"); return $query->row; } public function getProducts() { $query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, wcd.unit AS weight_class FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) LEFT JOIN " . DB_PREFIX . "weight_class_description wcd ON (p.weight_class_id = wcd.weight_class_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND wcd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.date_available <= NOW() AND p.status = '1'"); return $query->rows; } public function getProductsByCategoryId($category_id, $sort = 'p.sort_order', $order = 'ASC', $start = 0, $limit = 20) { $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) LEFT JOIN " . DB_PREFIX . "product_to_category p2c ON (p.product_id = p2c.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2c.category_id = '" . (int)$category_id . "'"; if ($sort=='p.price'){ if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating, ". "coalesce((SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND customer_group_id = '" . (int)$customer_group_id . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY priority ASC, price ASC LIMIT 1), p.price) as s_price ". "FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) LEFT JOIN " . DB_PREFIX . "product_to_category p2c ON (p.product_id = p2c.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2c.category_id = '" . (int)$category_id . "'"; $sort = 's_price'; } $sort_data = array( 'pd.name', 'p.sort_order', 'special', 'rating', 'p.price', 's_price', 'p.model' ); if (in_array($sort, $sort_data)) { if ($sort == 'pd.name' || $sort == 'p.model') { $sql .= " ORDER BY LCASE(" . $sort . ")"; } else { $sql .= " ORDER BY " . $sort; } } else { $sql .= " ORDER BY p.sort_order"; } if ($order == 'DESC') { $sql .= " DESC"; } else { $sql .= " ASC"; } if ($start < 0) { $start = 0; } $sql .= " LIMIT " . (int)$start . "," . (int)$limit; $query = $this->db->query($sql); return $query->rows; } public function getTotalProductsByCategoryId($category_id = 0) { $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product_to_category p2c LEFT JOIN " . DB_PREFIX . "product p ON (p2c.product_id = p.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND p2c.category_id = '" . (int)$category_id . "'"); return $query->row['total']; } public function getProductsByManufacturerId($manufacturer_id, $sort = 'p.sort_order', $order = 'ASC', $start = 0, $limit = 20) { $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND m.manufacturer_id = '" . (int)$manufacturer_id. "'"; if ($sort == 'p.price') { if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating," . "coalesce((SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND customer_group_id = '" . (int)$customer_group_id . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY priority ASC, price ASC LIMIT 1), p.price) as s_price " . " FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND m.manufacturer_id = '" . (int)$manufacturer_id . "'"; $sort = 's_price'; } $sort_data = array( 'pd.name', 'p.sort_order', 'special', 'rating', 's_price', 'p.model' ); if (in_array($sort, $sort_data)) { if ($sort == 'pd.name' || $sort == 'p.model') { $sql .= " ORDER BY LCASE(" . $sort . ")"; } else { $sql .= " ORDER BY " . $sort; } } else { $sql .= " ORDER BY p.sort_order"; } if ($order == 'DESC') { $sql .= " DESC"; } else { $sql .= " ASC"; } if ($start < 0) { $start = 0; } $sql .= " LIMIT " . (int)$start . "," . (int)$limit; $query = $this->db->query($sql); return $query->rows; } public function getTotalProductsByManufacturerId($manufacturer_id = 0) { $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product WHERE status = '1' AND date_available <= NOW() AND manufacturer_id = '" . (int)$manufacturer_id . "'"); return $query->row['total']; } public function getProductsByTag($tag, $category_id = 0, $sort = 'p.sort_order', $order = 'ASC', $start = 0, $limit = 20) { if ($tag) { $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_tags pt ON (p.product_id = pt.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND pt.language_id = '" . (int)$this->config->get('config_language_id') . "' AND (pt.tag = '" . $this->db->escape($tag) . "'"; $keywords = explode(" ", $tag); foreach ($keywords as $keyword) { $sql .= " OR pt.tag = '" . $this->db->escape($keyword) . "'"; } $sql .= ")"; if ($category_id) { $data = array(); $this->load->model('catalog/category'); $string = rtrim($this->getPath($category_id), ','); foreach (explode(',', $string) as $category_id) { $data[] = "category_id = '" . (int)$category_id . "'"; } $sql .= " AND p.product_id IN (SELECT product_id FROM " . DB_PREFIX . "product_to_category WHERE " . implode(" OR ", $data) . ")"; } $sql .= " AND p.status = '1' AND p.date_available <= NOW() GROUP BY p.product_id"; $sort_data = array( 'pd.name', 'p.sort_order', 'special', 'rating', 'p.price', 'p.model' ); if (in_array($sort, $sort_data)) { if ($sort == 'pd.name' || $sort == 'p.model') { $sql .= " ORDER BY LCASE(" . $sort . ")"; } else { $sql .= " ORDER BY " . $sort; } } else { $sql .= " ORDER BY p.sort_order"; } if ($order == 'DESC') { $sql .= " DESC"; } else { $sql .= " ASC"; } if ($start < 0) { $start = 0; } $sql .= " LIMIT " . (int)$start . "," . (int)$limit; $query = $this->db->query($sql); $products = array(); foreach ($query->rows as $key => $value) { $products[$value['product_id']] = $this->getProduct($value['product_id']); } return $products; } } public function getProductsByKeyword($keyword, $category_id = 0, $description = FALSE, $model = FALSE, $sort = 'p.sort_order', $order = 'ASC', $start = 0, $limit = 20) { if ($keyword) { $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "'"; if (!$description) { $sql .= " AND (pd.name LIKE '%" . $this->db->escape($keyword) . "%'"; } else { $sql .= " AND (pd.name LIKE '%" . $this->db->escape($keyword) . "%' OR pd.description LIKE '%" . $this->db->escape($keyword) . "%'"; } if (!$model) { $sql .= ")"; } else { $sql .= " OR p.model LIKE '%" . $this->db->escape($keyword) . "%')"; } if ($category_id) { $data = array(); $this->load->model('catalog/category'); $string = rtrim($this->getPath($category_id), ','); foreach (explode(',', $string) as $category_id) { $data[] = "category_id = '" . (int)$category_id . "'"; } $sql .= " AND p.product_id IN (SELECT product_id FROM " . DB_PREFIX . "product_to_category WHERE " . implode(" OR ", $data) . ")"; } $sql .= " AND p.status = '1' AND p.date_available <= NOW() GROUP BY p.product_id"; $sort_data = array( 'pd.name', 'p.sort_order', 'special', 'rating', 'p.price', 'p.model' ); if (in_array($sort, $sort_data)) { if ($sort == 'pd.name' || $sort == 'p.model') { $sql .= " ORDER BY LCASE(" . $sort . ")"; } else { $sql .= " ORDER BY " . $sort; } } else { $sql .= " ORDER BY p.sort_order"; } if ($order == 'DESC') { $sql .= " DESC"; } else { $sql .= " ASC"; } if ($start < 0) { $start = 0; } $sql .= " LIMIT " . (int)$start . "," . (int)$limit; $query = $this->db->query($sql); return $query->rows; } return 0; } public function getTotalProductsByKeyword($keyword, $category_id = 0, $description = FALSE, $model = FALSE) { if ($keyword) { $sql = "SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "'"; if (!$description) { $sql .= " AND (pd.name LIKE '%" . $this->db->escape($keyword) . "%'"; } else { $sql .= " AND (pd.name LIKE '%" . $this->db->escape($keyword) . "%' OR pd.description LIKE '%" . $this->db->escape($keyword) . "%'"; } if (!$model) { $sql .= ")"; } else { $sql .= " OR p.model LIKE '%" . $this->db->escape($keyword) . "%')"; } if ($category_id) { $data = array(); $this->load->model('catalog/category'); $string = rtrim($this->getPath($category_id), ','); foreach (explode(',', $string) as $category_id) { $data[] = "category_id = '" . (int)$category_id . "'"; } $sql .= " AND p.product_id IN (SELECT product_id FROM " . DB_PREFIX . "product_to_category WHERE " . implode(" OR ", $data) . ")"; } $sql .= " AND p.status = '1' AND p.date_available <= NOW()"; $query = $this->db->query($sql); if ($query->num_rows) { return $query->row['total']; } else { return 0; } } return 0; } public function getTotalProductsByTag($tag, $category_id = 0) { if ($tag) { $sql = "SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_tags pt ON (p.product_id = pt.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND pt.language_id = '" . (int)$this->config->get('config_language_id') . "' AND (pt.tag = '" . $this->db->escape($tag) . "'"; $keywords = explode(" ", $tag); foreach ($keywords as $keyword) { $sql .= " OR pt.tag = '" . $this->db->escape($keyword) . "'"; } $sql .= ")"; if ($category_id) { $data = array(); $this->load->model('catalog/category'); $string = rtrim($this->getPath($category_id), ','); foreach (explode(',', $string) as $category_id) { $data[] = "category_id = '" . (int)$category_id . "'"; } $sql .= " AND p.product_id IN (SELECT product_id FROM " . DB_PREFIX . "product_to_category WHERE " . implode(" OR ", $data) . ")"; } $sql .= " AND p.status = '1' AND p.date_available <= NOW()"; $query = $this->db->query($sql); if ($query->num_rows) { return $query->row['total']; } else { return 0; } } return 0; } public function getPath($category_id) { $string = $category_id . ','; $results = $this->model_catalog_category->getCategories($category_id); foreach ($results as $result) { $string .= $this->getPath($result['category_id']); } return $string; } public function getLatestProducts($limit) { $product_data = $this->cache->get('product.latest.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit); if (!$product_data) { $query = $this->db->query("SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY p.date_added DESC LIMIT " . (int)$limit); $product_data = $query->rows; $this->cache->set('product.latest.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit, $product_data); } return $product_data; } public function getPopularProducts($limit) { $query = $this->db->query("SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY p.viewed, p.date_added DESC LIMIT " . (int)$limit); return $query->rows; } public function getFeaturedProducts($limit) { $product_data = $this->cache->get('product.featured.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit); if (!$product_data) { $query = $this->db->query("SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product_featured f LEFT JOIN " . DB_PREFIX . "product p ON (f.product_id=p.product_id) LEFT JOIN " . DB_PREFIX . "product_description pd ON (f.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' LIMIT " . (int)$limit); $product_data = $query->rows; $this->cache->set('product.featured.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit, $product_data); } return $product_data; } public function getBestSellerProducts($limit) { $product_data = $this->cache->get('product.bestseller.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit); if (!$product_data) { $product_data = array(); $query = $this->db->query("SELECT op.product_id, SUM(op.quantity) AS total, p.status FROM " . DB_PREFIX . "order_product op LEFT JOIN `" . DB_PREFIX . "order` o ON (op.order_id = o.order_id) LEFT JOIN `" . DB_PREFIX . "product` p ON (op.product_id = p.product_id) WHERE o.order_status_id > '0' AND p.status = '1' GROUP BY op.product_id, p.status ORDER BY total DESC LIMIT " . (int)$limit); foreach ($query->rows as $result) { $product_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE p.product_id = '" . (int)$result['product_id'] . "' AND p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "'"); if ($product_query->num_rows) { $product_data[] = $product_query->row; } } $this->cache->set('product.bestseller.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit, $product_data); } return $product_data; } public function updateViewed($product_id) { $this->db->query("UPDATE " . DB_PREFIX . "product SET viewed = viewed + 1 WHERE product_id = '" . (int)$product_id . "'"); } public function getProductOptions($product_id) { $product_option_data = array(); $product_option_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option WHERE product_id = '" . (int)$product_id . "' ORDER BY sort_order"); foreach ($product_option_query->rows as $product_option) { $product_option_value_data = array(); $product_option_value_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option_value WHERE product_option_id = '" . (int)$product_option['product_option_id'] . "' ORDER BY sort_order"); foreach ($product_option_value_query->rows as $product_option_value) { $product_option_value_description_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option_value_description WHERE product_option_value_id = '" . (int)$product_option_value['product_option_value_id'] . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'"); $product_option_value_data[] = array( 'product_option_value_id' => $product_option_value['product_option_value_id'], 'name' => $product_option_value_description_query->row['name'], 'price' => $product_option_value['price'], 'prefix' => $product_option_value['prefix'], 'quantity' => $product_option_value['quantity'] /* webme - options show|hide - mod */ ); } $product_option_description_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option_description WHERE product_option_id = '" . (int)$product_option['product_option_id'] . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'"); $product_option_data[] = array( 'product_option_id' => $product_option['product_option_id'], 'name' => $product_option_description_query->row['name'], 'option_value' => $product_option_value_data, 'sort_order' => $product_option['sort_order'] ); } return $product_option_data; } public function getProductImages($product_id) { $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_image WHERE product_id = '" . (int)$product_id . "'"); return $query->rows; } public function getProductTags($product_id) { $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_tags WHERE product_id = '" . (int)$product_id . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'"); return $query->rows; } public function getProductDiscount($product_id) { if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $query = $this->db->query("SELECT price FROM " . DB_PREFIX . "product_discount WHERE product_id = '" . (int)$product_id . "' AND customer_group_id = '" . (int)$customer_group_id . "' AND quantity = '1' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY priority ASC, price ASC LIMIT 1"); if ($query->num_rows) { return $query->row['price']; } else { return FALSE; } } public function getProductDiscounts($product_id) { if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_discount WHERE product_id = '" . (int)$product_id . "' AND customer_group_id = '" . (int)$customer_group_id . "' AND quantity > 1 AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY quantity ASC, priority ASC, price ASC"); return $query->rows; } public function getProductSpecial($product_id) { if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $query = $this->db->query("SELECT price FROM " . DB_PREFIX . "product_special WHERE product_id = '" . (int)$product_id . "' AND customer_group_id = '" . (int)$customer_group_id . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY priority ASC, price ASC LIMIT 1"); if ($query->num_rows) { return $query->row['price']; } else { return FALSE; } } public function getProductSpecials($sort = 'p.sort_order', $order = 'ASC', $start = 0, $limit = 20) { if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $sql = "SELECT *, pd.name AS name, p.price, (SELECT ps2.price FROM " . DB_PREFIX . "product_special ps2 WHERE p.product_id = ps2.product_id AND ps2.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps2.date_start = '0000-00-00' OR ps2.date_start < NOW()) AND (ps2.date_end = '0000-00-00' OR ps2.date_end > NOW())) ORDER BY ps2.priority ASC, ps2.price ASC LIMIT 1) AS special, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "product_special ps ON (p.product_id = ps.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND ps.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW())AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) AND ps.product_id NOT IN (SELECT pd2.product_id FROM " . DB_PREFIX . "product_discount pd2 WHERE p.product_id = pd2.product_id AND pd2.customer_group_id = '" . (int)$customer_group_id . "' AND pd2.quantity = '1' AND ((pd2.date_start = '0000-00-00' OR pd2.date_start < NOW()) AND (pd2.date_end = '0000-00-00' OR pd2.date_end > NOW()))) GROUP BY p.product_id"; $sort_data = array( 'pd.name', 'p.sort_order', 'special', 'rating', 'p.price', 'p.model' ); if (in_array($sort, $sort_data)) { if ($sort == 'pd.name' || $sort == 'p.model') { $sql .= " ORDER BY LCASE(" . $sort . ")"; } else { $sql .= " ORDER BY " . $sort; } } else { $sql .= " ORDER BY p.sort_order"; } if ($order == 'DESC') { $sql .= " DESC"; } else { $sql .= " ASC"; } if ($start < 0) { $start = 0; } $sql .= " LIMIT " . (int)$start . "," . (int)$limit; $query = $this->db->query($sql); return $query->rows; } public function getTotalProductSpecials() { if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $query = $this->db->query("SELECT COUNT(DISTINCT ps.product_id) AS total FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "product_special ps ON (p.product_id = ps.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) AND ps.product_id NOT IN (SELECT pd2.product_id FROM " . DB_PREFIX . "product_discount pd2 WHERE p.product_id = pd2.product_id AND pd2.customer_group_id = '" . (int)$customer_group_id . "' AND pd2.quantity = '1' AND ((pd2.date_start = '0000-00-00' OR pd2.date_start < NOW()) AND (pd2.date_end = '0000-00-00' OR pd2.date_end > NOW())))"); if (isset($query->row['total'])) { return $query->row['total']; } else { return 0; } } public function getProductRelated($product_id) { $product_data = array(); $product_related_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$product_id . "'"); foreach ($product_related_query->rows as $result) { $product_query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.product_id = '" . (int)$result['related_id'] . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.date_available <= NOW() AND p.status = '1'"); if ($product_query->num_rows) { $product_data[$result['related_id']] = $product_query->row; } } return $product_data; } public function getCategories($product_id) { $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_to_category WHERE product_id = '" . (int)$product_id . "'"); return $query->rows; } } ?> Тему можно закрыть с пометкой решено и сделать на нее ссылку в FAQ) Змінено 16 березня 2012 користувачем 1roma1 Надіслати Поділитися на інших сайтах More sharing options...
freelancer Опубліковано: 16 березня 2012 Share Опубліковано: 16 березня 2012 Спасибо большое! все работает! В блоке $sort_data = array нужно было не добавить 's_price', а заменить ним 'p.price'. .. это вовсе не обязательно. важное исправление было в другом месте.ну да не суть Надіслати Поділитися на інших сайтах More sharing options... DAN Опубліковано: 22 березня 2012 Share Опубліковано: 22 березня 2012 я описал для версии 0.2.2, для 1.5.1.3 не подойдет А для версии 1.5.1.3 как сделать не подскажите? Надіслати Поділитися на інших сайтах More sharing options... 7 months later... mybay Опубліковано: 31 жовтня 2012 Share Опубліковано: 31 жовтня 2012 большое спасибо! и мне помогло))) Надіслати Поділитися на інших сайтах More sharing options... 7 months later... hon2012 Опубліковано: 10 червня 2013 Share Опубліковано: 10 червня 2013 Добрый день, Скажите а как должен выглядеть код для 1.5.1.3 я попытался добавить но не получилось.?я описал для версии 0.2.2, для 1.5.1.3 не подойдет Уважаемый freelancer, подскажите как сделать для версии 1.5.13 Спасибо Надіслати Поділитися на інших сайтах More sharing options... freelancer Опубліковано: 10 червня 2013 Share Опубліковано: 10 червня 2013 по аналогии. разжевывать не буду Надіслати Поділитися на інших сайтах More sharing options... 3 months later... NoobMan Опубліковано: 7 жовтня 2013 Share Опубліковано: 7 жовтня 2013 Всем привет! Собственно наткнулся на такую проблему/недоработку пока не знаю как назвать. Версия OcStore 0.2.2. Есть каталог продукции с установленной ценой. Например на 2 месяца устанавливаю специальную цену. Она может быть разной относительно первоначальной одинаковой цены в похожих моделях. Например есть 2 товара по цене 700. На один делаю скидку 100, на другой 150. Итого новые цены выходят 600 и 550 соответственно. Проблема заключается в том, что когда в каталоге выбираю сортировку по цене, скрипт сортирует относительно первоначальной цены, без учета специальной. Т.е. таким образом: 700 600, 700 550, 720 610, 740 630, 750 650. Вопрос: это у всех так или только у меня? И если у всех, то кто-то может подсказать как это решить? Поиском пользовался, решений не нашел. Спасибо. Для opencart 1.5.4.1 решение не подскажите? Надіслати Поділитися на інших сайтах More sharing options... 1 year later... Marinka Опубліковано: 11 квітня 2015 Share Опубліковано: 11 квітня 2015 Да, для 1.5.4.1 тоже не могу найти решение! хэлп!!! Надіслати Поділитися на інших сайтах More sharing options... 1 year later... newjey Опубліковано: 11 січня 2017 Share Опубліковано: 11 січня 2017 Подскажите под ocStore 2.1.0.2 как сделать сортировку с учётом акционной цены? Надіслати Поділитися на інших сайтах More sharing options... Створіть аккаунт або увійдіть для коментування Ви повинні бути користувачем, щоб залишити коментар Створити обліковий запис Зареєструйтеся для отримання облікового запису. Це просто! Зареєструвати аккаунт Вхід Уже зареєстровані? Увійдіть тут. Вхід зараз Share More sharing options... Передплатники 0 Перейти до списку тем Зараз на сторінці 0 користувачів Ні користувачів, які переглядиють цю сторінку
DAN Опубліковано: 22 березня 2012 Share Опубліковано: 22 березня 2012 я описал для версии 0.2.2, для 1.5.1.3 не подойдет А для версии 1.5.1.3 как сделать не подскажите? Надіслати Поділитися на інших сайтах More sharing options...
mybay Опубліковано: 31 жовтня 2012 Share Опубліковано: 31 жовтня 2012 большое спасибо! и мне помогло))) Надіслати Поділитися на інших сайтах More sharing options...
hon2012 Опубліковано: 10 червня 2013 Share Опубліковано: 10 червня 2013 Добрый день, Скажите а как должен выглядеть код для 1.5.1.3 я попытался добавить но не получилось.?я описал для версии 0.2.2, для 1.5.1.3 не подойдет Уважаемый freelancer, подскажите как сделать для версии 1.5.13 Спасибо Надіслати Поділитися на інших сайтах More sharing options...
freelancer Опубліковано: 10 червня 2013 Share Опубліковано: 10 червня 2013 по аналогии. разжевывать не буду Надіслати Поділитися на інших сайтах More sharing options... 3 months later... NoobMan Опубліковано: 7 жовтня 2013 Share Опубліковано: 7 жовтня 2013 Всем привет! Собственно наткнулся на такую проблему/недоработку пока не знаю как назвать. Версия OcStore 0.2.2. Есть каталог продукции с установленной ценой. Например на 2 месяца устанавливаю специальную цену. Она может быть разной относительно первоначальной одинаковой цены в похожих моделях. Например есть 2 товара по цене 700. На один делаю скидку 100, на другой 150. Итого новые цены выходят 600 и 550 соответственно. Проблема заключается в том, что когда в каталоге выбираю сортировку по цене, скрипт сортирует относительно первоначальной цены, без учета специальной. Т.е. таким образом: 700 600, 700 550, 720 610, 740 630, 750 650. Вопрос: это у всех так или только у меня? И если у всех, то кто-то может подсказать как это решить? Поиском пользовался, решений не нашел. Спасибо. Для opencart 1.5.4.1 решение не подскажите? Надіслати Поділитися на інших сайтах More sharing options... 1 year later... Marinka Опубліковано: 11 квітня 2015 Share Опубліковано: 11 квітня 2015 Да, для 1.5.4.1 тоже не могу найти решение! хэлп!!! Надіслати Поділитися на інших сайтах More sharing options... 1 year later... newjey Опубліковано: 11 січня 2017 Share Опубліковано: 11 січня 2017 Подскажите под ocStore 2.1.0.2 как сделать сортировку с учётом акционной цены? Надіслати Поділитися на інших сайтах More sharing options... Створіть аккаунт або увійдіть для коментування Ви повинні бути користувачем, щоб залишити коментар Створити обліковий запис Зареєструйтеся для отримання облікового запису. Це просто! Зареєструвати аккаунт Вхід Уже зареєстровані? Увійдіть тут. Вхід зараз Share More sharing options... Передплатники 0
NoobMan Опубліковано: 7 жовтня 2013 Share Опубліковано: 7 жовтня 2013 Всем привет! Собственно наткнулся на такую проблему/недоработку пока не знаю как назвать. Версия OcStore 0.2.2. Есть каталог продукции с установленной ценой. Например на 2 месяца устанавливаю специальную цену. Она может быть разной относительно первоначальной одинаковой цены в похожих моделях. Например есть 2 товара по цене 700. На один делаю скидку 100, на другой 150. Итого новые цены выходят 600 и 550 соответственно. Проблема заключается в том, что когда в каталоге выбираю сортировку по цене, скрипт сортирует относительно первоначальной цены, без учета специальной. Т.е. таким образом: 700 600, 700 550, 720 610, 740 630, 750 650. Вопрос: это у всех так или только у меня? И если у всех, то кто-то может подсказать как это решить? Поиском пользовался, решений не нашел. Спасибо. Для opencart 1.5.4.1 решение не подскажите? Надіслати Поділитися на інших сайтах More sharing options...
Marinka Опубліковано: 11 квітня 2015 Share Опубліковано: 11 квітня 2015 Да, для 1.5.4.1 тоже не могу найти решение! хэлп!!! Надіслати Поділитися на інших сайтах More sharing options...
newjey Опубліковано: 11 січня 2017 Share Опубліковано: 11 січня 2017 Подскажите под ocStore 2.1.0.2 как сделать сортировку с учётом акционной цены? Надіслати Поділитися на інших сайтах More sharing options...
Recommended Posts