first commit
This commit is contained in:
4
modules/leoproductsearch/Readme.md
Normal file
4
modules/leoproductsearch/Readme.md
Normal file
@@ -0,0 +1,4 @@
|
||||
# Onlide guide
|
||||
http://www.leotheme.com/support/prestashop-16x-guides.html
|
||||
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2015 Leotheme
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* Quick product search by category block
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* @author leotheme <leotheme@gmail.com>
|
||||
* @copyright 2007-2015 Leotheme
|
||||
* @license http://leotheme.com - prestashop template provider
|
||||
*/
|
||||
|
||||
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchProviderInterface;
|
||||
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchContext;
|
||||
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchQuery;
|
||||
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchResult;
|
||||
use PrestaShop\PrestaShop\Core\Product\Search\SortOrderFactory;
|
||||
use Symfony\Component\Translation\TranslatorInterface;
|
||||
|
||||
// use Search;
|
||||
// use Tools;
|
||||
if (file_exists(_PS_MODULE_DIR_ . 'leoproductsearch/classes/ProductSearch.php')) {
|
||||
require_once(_PS_MODULE_DIR_ . 'leoproductsearch/classes/ProductSearch.php');
|
||||
}
|
||||
|
||||
// use ProductSearch\ProductSearch;
|
||||
// if (file_exists(_PS_MODULE_DIR_.'leoproductsearch/classes/ProductSearch.php')) {
|
||||
// require_once(_PS_MODULE_DIR_.'leoproductsearch/classes/ProductSearch.php');
|
||||
// }
|
||||
|
||||
class LeoSearchProductSearchProvider implements ProductSearchProviderInterface
|
||||
{
|
||||
|
||||
private $translator;
|
||||
private $category;
|
||||
private $sortOrderFactory;
|
||||
|
||||
public function __construct(TranslatorInterface $translator)
|
||||
{
|
||||
$this->translator = $translator;
|
||||
$this->sortOrderFactory = new SortOrderFactory($this->translator);
|
||||
}
|
||||
|
||||
public function runQuery(ProductSearchContext $context, ProductSearchQuery $query)
|
||||
{
|
||||
$products = array();
|
||||
$count = 0;
|
||||
|
||||
if (($string = $query->getSearchString())) {
|
||||
// $class = new ProductSearch;
|
||||
// echo '<pre>';
|
||||
// print_r();die();
|
||||
$queryString = Tools::replaceAccentedChars(urldecode($string));
|
||||
$result = ProductSearch::find($context->getIdLang(), $queryString, $query->getPage(), $query->getResultsPerPage(), $query->getSortOrder()->toLegacyOrderBy(), $query->getSortOrder()->toLegacyOrderWay(), false, false, null, $query->getIdCategory());
|
||||
$products = $result['result'];
|
||||
$count = $result['total'];
|
||||
|
||||
Hook::exec('actionSearch', array(
|
||||
'searched_query' => $queryString,
|
||||
'total' => $count,
|
||||
// deprecated since 1.7.x
|
||||
'expr' => $queryString,
|
||||
));
|
||||
} elseif (($tag = $query->getSearchTag())) {
|
||||
// $class = new ProductSearch;
|
||||
$queryString = urldecode($tag);
|
||||
|
||||
$products = ProductSearch::searchTag($context->getIdLang(), $queryString, false, $query->getPage(), $query->getResultsPerPage(), $query->getSortOrder()->toLegacyOrderBy(true), $query->getSortOrder()->toLegacyOrderWay(), false, null);
|
||||
|
||||
$count = ProductSearch::searchTag($context->getIdLang(), $queryString, true, $query->getPage(), $query->getResultsPerPage(), $query->getSortOrder()->toLegacyOrderBy(true), $query->getSortOrder()->toLegacyOrderWay(), false, null);
|
||||
|
||||
Hook::exec('actionSearch', array(
|
||||
'searched_query' => $queryString,
|
||||
'total' => $count,
|
||||
// deprecated since 1.7.x
|
||||
'expr' => $queryString,
|
||||
));
|
||||
}
|
||||
|
||||
$result = new ProductSearchResult();
|
||||
if (!empty($products)) {
|
||||
$result
|
||||
->setProducts($products)
|
||||
->setTotalProductsCount($count);
|
||||
|
||||
$result->setAvailableSortOrders(
|
||||
$this->sortOrderFactory->getDefaultSortOrders()
|
||||
);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
861
modules/leoproductsearch/classes/ProductSearch.php
Normal file
861
modules/leoproductsearch/classes/ProductSearch.php
Normal file
@@ -0,0 +1,861 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2015 Leotheme
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* Quick product search by category block
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* @author leotheme <leotheme@gmail.com>
|
||||
* @copyright 2007-2015 Leotheme
|
||||
* @license http://leotheme.com - prestashop template provider
|
||||
*/
|
||||
|
||||
// use Context;
|
||||
// use Db;
|
||||
// use Validate;
|
||||
// use Tools;
|
||||
// use Alias;
|
||||
// use Configuration;
|
||||
// use Group;
|
||||
// use FrontController;
|
||||
// use Shop;
|
||||
// use Combination;
|
||||
// use Product;
|
||||
|
||||
define('PS_SEARCH_MAX_WORD_LENGTH', 15);
|
||||
|
||||
/* Copied from Drupal search module, except for \x{0}-\x{2f} that has been replaced by \x{0}-\x{2c}\x{2e}-\x{2f} in order to keep the char '-' */
|
||||
define('PREG_CLASS_SEARCH_EXCLUDE', '\x{0}-\x{2c}\x{2e}-\x{2f}\x{3a}-\x{40}\x{5b}-\x{60}\x{7b}-\x{bf}\x{d7}\x{f7}\x{2b0}-' .
|
||||
'\x{385}\x{387}\x{3f6}\x{482}-\x{489}\x{559}-\x{55f}\x{589}-\x{5c7}\x{5f3}-' .
|
||||
'\x{61f}\x{640}\x{64b}-\x{65e}\x{66a}-\x{66d}\x{670}\x{6d4}\x{6d6}-\x{6ed}' .
|
||||
'\x{6fd}\x{6fe}\x{700}-\x{70f}\x{711}\x{730}-\x{74a}\x{7a6}-\x{7b0}\x{901}-' .
|
||||
'\x{903}\x{93c}\x{93e}-\x{94d}\x{951}-\x{954}\x{962}-\x{965}\x{970}\x{981}-' .
|
||||
'\x{983}\x{9bc}\x{9be}-\x{9cd}\x{9d7}\x{9e2}\x{9e3}\x{9f2}-\x{a03}\x{a3c}-' .
|
||||
'\x{a4d}\x{a70}\x{a71}\x{a81}-\x{a83}\x{abc}\x{abe}-\x{acd}\x{ae2}\x{ae3}' .
|
||||
'\x{af1}-\x{b03}\x{b3c}\x{b3e}-\x{b57}\x{b70}\x{b82}\x{bbe}-\x{bd7}\x{bf0}-' .
|
||||
'\x{c03}\x{c3e}-\x{c56}\x{c82}\x{c83}\x{cbc}\x{cbe}-\x{cd6}\x{d02}\x{d03}' .
|
||||
'\x{d3e}-\x{d57}\x{d82}\x{d83}\x{dca}-\x{df4}\x{e31}\x{e34}-\x{e3f}\x{e46}-' .
|
||||
'\x{e4f}\x{e5a}\x{e5b}\x{eb1}\x{eb4}-\x{ebc}\x{ec6}-\x{ecd}\x{f01}-\x{f1f}' .
|
||||
'\x{f2a}-\x{f3f}\x{f71}-\x{f87}\x{f90}-\x{fd1}\x{102c}-\x{1039}\x{104a}-' .
|
||||
'\x{104f}\x{1056}-\x{1059}\x{10fb}\x{10fc}\x{135f}-\x{137c}\x{1390}-\x{1399}' .
|
||||
'\x{166d}\x{166e}\x{1680}\x{169b}\x{169c}\x{16eb}-\x{16f0}\x{1712}-\x{1714}' .
|
||||
'\x{1732}-\x{1736}\x{1752}\x{1753}\x{1772}\x{1773}\x{17b4}-\x{17db}\x{17dd}' .
|
||||
'\x{17f0}-\x{180e}\x{1843}\x{18a9}\x{1920}-\x{1945}\x{19b0}-\x{19c0}\x{19c8}' .
|
||||
'\x{19c9}\x{19de}-\x{19ff}\x{1a17}-\x{1a1f}\x{1d2c}-\x{1d61}\x{1d78}\x{1d9b}-' .
|
||||
'\x{1dc3}\x{1fbd}\x{1fbf}-\x{1fc1}\x{1fcd}-\x{1fcf}\x{1fdd}-\x{1fdf}\x{1fed}-' .
|
||||
'\x{1fef}\x{1ffd}-\x{2070}\x{2074}-\x{207e}\x{2080}-\x{2101}\x{2103}-\x{2106}' .
|
||||
'\x{2108}\x{2109}\x{2114}\x{2116}-\x{2118}\x{211e}-\x{2123}\x{2125}\x{2127}' .
|
||||
'\x{2129}\x{212e}\x{2132}\x{213a}\x{213b}\x{2140}-\x{2144}\x{214a}-\x{2b13}' .
|
||||
'\x{2ce5}-\x{2cff}\x{2d6f}\x{2e00}-\x{3005}\x{3007}-\x{303b}\x{303d}-\x{303f}' .
|
||||
'\x{3099}-\x{309e}\x{30a0}\x{30fb}\x{30fd}\x{30fe}\x{3190}-\x{319f}\x{31c0}-' .
|
||||
'\x{31cf}\x{3200}-\x{33ff}\x{4dc0}-\x{4dff}\x{a015}\x{a490}-\x{a716}\x{a802}' .
|
||||
'\x{e000}-\x{f8ff}\x{fb29}\x{fd3e}-\x{fd3f}\x{fdfc}-\x{fdfd}' .
|
||||
'\x{fd3f}\x{fdfc}-\x{fe6b}\x{feff}-\x{ff0f}\x{ff1a}-\x{ff20}\x{ff3b}-\x{ff40}' .
|
||||
'\x{ff5b}-\x{ff65}\x{ff70}\x{ff9e}\x{ff9f}\x{ffe0}-\x{fffd}');
|
||||
|
||||
define('PREG_CLASS_NUMBERS', '\x{30}-\x{39}\x{b2}\x{b3}\x{b9}\x{bc}-\x{be}\x{660}-\x{669}\x{6f0}-\x{6f9}' .
|
||||
'\x{966}-\x{96f}\x{9e6}-\x{9ef}\x{9f4}-\x{9f9}\x{a66}-\x{a6f}\x{ae6}-\x{aef}' .
|
||||
'\x{b66}-\x{b6f}\x{be7}-\x{bf2}\x{c66}-\x{c6f}\x{ce6}-\x{cef}\x{d66}-\x{d6f}' .
|
||||
'\x{e50}-\x{e59}\x{ed0}-\x{ed9}\x{f20}-\x{f33}\x{1040}-\x{1049}\x{1369}-' .
|
||||
'\x{137c}\x{16ee}-\x{16f0}\x{17e0}-\x{17e9}\x{17f0}-\x{17f9}\x{1810}-\x{1819}' .
|
||||
'\x{1946}-\x{194f}\x{2070}\x{2074}-\x{2079}\x{2080}-\x{2089}\x{2153}-\x{2183}' .
|
||||
'\x{2460}-\x{249b}\x{24ea}-\x{24ff}\x{2776}-\x{2793}\x{3007}\x{3021}-\x{3029}' .
|
||||
'\x{3038}-\x{303a}\x{3192}-\x{3195}\x{3220}-\x{3229}\x{3251}-\x{325f}\x{3280}-' .
|
||||
'\x{3289}\x{32b1}-\x{32bf}\x{ff10}-\x{ff19}');
|
||||
|
||||
define('PREG_CLASS_PUNCTUATION', '\x{21}-\x{23}\x{25}-\x{2a}\x{2c}-\x{2f}\x{3a}\x{3b}\x{3f}\x{40}\x{5b}-\x{5d}' .
|
||||
'\x{5f}\x{7b}\x{7d}\x{a1}\x{ab}\x{b7}\x{bb}\x{bf}\x{37e}\x{387}\x{55a}-\x{55f}' .
|
||||
'\x{589}\x{58a}\x{5be}\x{5c0}\x{5c3}\x{5f3}\x{5f4}\x{60c}\x{60d}\x{61b}\x{61f}' .
|
||||
'\x{66a}-\x{66d}\x{6d4}\x{700}-\x{70d}\x{964}\x{965}\x{970}\x{df4}\x{e4f}' .
|
||||
'\x{e5a}\x{e5b}\x{f04}-\x{f12}\x{f3a}-\x{f3d}\x{f85}\x{104a}-\x{104f}\x{10fb}' .
|
||||
'\x{1361}-\x{1368}\x{166d}\x{166e}\x{169b}\x{169c}\x{16eb}-\x{16ed}\x{1735}' .
|
||||
'\x{1736}\x{17d4}-\x{17d6}\x{17d8}-\x{17da}\x{1800}-\x{180a}\x{1944}\x{1945}' .
|
||||
'\x{2010}-\x{2027}\x{2030}-\x{2043}\x{2045}-\x{2051}\x{2053}\x{2054}\x{2057}' .
|
||||
'\x{207d}\x{207e}\x{208d}\x{208e}\x{2329}\x{232a}\x{23b4}-\x{23b6}\x{2768}-' .
|
||||
'\x{2775}\x{27e6}-\x{27eb}\x{2983}-\x{2998}\x{29d8}-\x{29db}\x{29fc}\x{29fd}' .
|
||||
'\x{3001}-\x{3003}\x{3008}-\x{3011}\x{3014}-\x{301f}\x{3030}\x{303d}\x{30a0}' .
|
||||
'\x{30fb}\x{fd3e}\x{fd3f}\x{fe30}-\x{fe52}\x{fe54}-\x{fe61}\x{fe63}\x{fe68}' .
|
||||
'\x{fe6a}\x{fe6b}\x{ff01}-\x{ff03}\x{ff05}-\x{ff0a}\x{ff0c}-\x{ff0f}\x{ff1a}' .
|
||||
'\x{ff1b}\x{ff1f}\x{ff20}\x{ff3b}-\x{ff3d}\x{ff3f}\x{ff5b}\x{ff5d}\x{ff5f}-' .
|
||||
'\x{ff65}');
|
||||
|
||||
/**
|
||||
* Matches all CJK characters that are candidates for auto-splitting
|
||||
* (Chinese, Japanese, Korean).
|
||||
* Contains kana and BMP ideographs.
|
||||
*/
|
||||
define('PREG_CLASS_CJK', '\x{3041}-\x{30ff}\x{31f0}-\x{31ff}\x{3400}-\x{4db5}\x{4e00}-\x{9fbb}\x{f900}-\x{fad9}');
|
||||
|
||||
class ProductSearch
|
||||
{
|
||||
|
||||
public static function sanitize($string, $id_lang, $indexation = false, $iso_code = false)
|
||||
{
|
||||
$string = trim($string);
|
||||
if (empty($string)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$string = Tools::strtolower(strip_tags($string));
|
||||
$string = html_entity_decode($string, ENT_NOQUOTES, 'utf-8');
|
||||
|
||||
$string = preg_replace('/([' . PREG_CLASS_NUMBERS . ']+)[' . PREG_CLASS_PUNCTUATION . ']+(?=[' . PREG_CLASS_NUMBERS . '])/u', '\1', $string);
|
||||
$string = preg_replace('/[' . PREG_CLASS_SEARCH_EXCLUDE . ']+/u', ' ', $string);
|
||||
|
||||
if ($indexation) {
|
||||
$string = preg_replace('/[._-]+/', ' ', $string);
|
||||
} else {
|
||||
$words = explode(' ', $string);
|
||||
$processed_words = array();
|
||||
// search for aliases for each word of the query
|
||||
foreach ($words as $word) {
|
||||
$alias = new Alias(null, $word);
|
||||
if (Validate::isLoadedObject($alias)) {
|
||||
$processed_words[] = $alias->search;
|
||||
} else {
|
||||
$processed_words[] = $word;
|
||||
}
|
||||
}
|
||||
$string = implode(' ', $processed_words);
|
||||
$string = preg_replace('/[._]+/', '', $string);
|
||||
$string = ltrim(preg_replace('/([^ ])-/', '$1 ', ' ' . $string));
|
||||
$string = preg_replace('/[._]+/', '', $string);
|
||||
$string = preg_replace('/[^\s]-+/', '', $string);
|
||||
}
|
||||
|
||||
$blacklist = Tools::strtolower(Configuration::get('PS_SEARCH_BLACKLIST', $id_lang));
|
||||
if (!empty($blacklist)) {
|
||||
$string = preg_replace('/(?<=\s)(' . $blacklist . ')(?=\s)/Su', '', $string);
|
||||
$string = preg_replace('/^(' . $blacklist . ')(?=\s)/Su', '', $string);
|
||||
$string = preg_replace('/(?<=\s)(' . $blacklist . ')$/Su', '', $string);
|
||||
$string = preg_replace('/^(' . $blacklist . ')$/Su', '', $string);
|
||||
}
|
||||
|
||||
// If the language is constituted with symbol and there is no "words", then split every chars
|
||||
if (in_array($iso_code, array('zh', 'tw', 'ja')) && function_exists('mb_strlen')) {
|
||||
// Cut symbols from letters
|
||||
$symbols = '';
|
||||
$letters = '';
|
||||
foreach (explode(' ', $string) as $mb_word) {
|
||||
if (Tools::strlen(Tools::replaceAccentedChars($mb_word)) == mb_strlen(Tools::replaceAccentedChars($mb_word))) {
|
||||
$letters .= $mb_word . ' ';
|
||||
} else {
|
||||
$symbols .= $mb_word . ' ';
|
||||
}
|
||||
}
|
||||
|
||||
if (preg_match_all('/./u', $symbols, $matches)) {
|
||||
$symbols = implode(' ', $matches[0]);
|
||||
}
|
||||
|
||||
$string = $letters . $symbols;
|
||||
} elseif ($indexation) {
|
||||
$minWordLen = (int) Configuration::get('PS_SEARCH_MINWORDLEN');
|
||||
if ($minWordLen > 1) {
|
||||
$minWordLen -= 1;
|
||||
$string = preg_replace('/(?<=\s)[^\s]{1,' . $minWordLen . '}(?=\s)/Su', ' ', $string);
|
||||
$string = preg_replace('/^[^\s]{1,' . $minWordLen . '}(?=\s)/Su', '', $string);
|
||||
$string = preg_replace('/(?<=\s)[^\s]{1,' . $minWordLen . '}$/Su', '', $string);
|
||||
$string = preg_replace('/^[^\s]{1,' . $minWordLen . '}$/Su', '', $string);
|
||||
}
|
||||
}
|
||||
|
||||
$string = Tools::replaceAccentedChars(trim(preg_replace('/\s+/', ' ', $string)));
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
public static function find($id_lang, $expr, $page_number = 1, $page_size = 1, $order_by = 'position', $order_way = 'desc', $ajax = false, $use_cookie = true, Context $context = null, $id_cate = null)
|
||||
{
|
||||
# VALIDATE MODULE
|
||||
unset($use_cookie);
|
||||
|
||||
if (!$context) {
|
||||
$context = Context::getContext();
|
||||
}
|
||||
$db = Db::getInstance(_PS_USE_SQL_SLAVE_);
|
||||
|
||||
// TODO : smart page management
|
||||
if ($page_number < 1) {
|
||||
$page_number = 1;
|
||||
}
|
||||
if ($page_size < 1) {
|
||||
$page_size = 1;
|
||||
}
|
||||
|
||||
if (!Validate::isOrderBy($order_by) || !Validate::isOrderWay($order_way)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$intersect_array = array();
|
||||
$score_array = array();
|
||||
$words = explode(' ', ProductSearch::sanitize($expr, $id_lang, false, $context->language->iso_code));
|
||||
|
||||
foreach ($words as $key => $word) {
|
||||
if (!empty($word) && Tools::strlen($word) >= (int) Configuration::get('PS_SEARCH_MINWORDLEN')) {
|
||||
$word = str_replace(array('%', '_'), array('\\%', '\\_'), $word);
|
||||
$start_search = Configuration::get('PS_SEARCH_START') ? '%' : '';
|
||||
$end_search = Configuration::get('PS_SEARCH_END') ? '' : '%';
|
||||
|
||||
$intersect_array[] = 'SELECT si.id_product
|
||||
FROM ' . _DB_PREFIX_ . 'search_word sw
|
||||
LEFT JOIN ' . _DB_PREFIX_ . 'search_index si ON sw.id_word = si.id_word
|
||||
WHERE sw.id_lang = ' . (int) $id_lang . '
|
||||
AND sw.id_shop = ' . $context->shop->id . '
|
||||
AND sw.word LIKE
|
||||
' . ($word[0] == '-' ? ' \'' . $start_search . pSQL(Tools::substr($word, 1, PS_SEARCH_MAX_WORD_LENGTH)) . $end_search . '\'' : ' \'' . $start_search . pSQL(Tools::substr($word, 0, PS_SEARCH_MAX_WORD_LENGTH)) . $end_search . '\''
|
||||
);
|
||||
|
||||
if ($word[0] != '-') {
|
||||
$score_array[] = 'sw.word LIKE \'' . $start_search . pSQL(Tools::substr($word, 0, PS_SEARCH_MAX_WORD_LENGTH)) . $end_search . '\'';
|
||||
}
|
||||
} else {
|
||||
unset($words[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
if (!count($words)) {
|
||||
return ($ajax ? array() : array('total' => 0, 'result' => array()));
|
||||
}
|
||||
|
||||
$score = '';
|
||||
if (is_array($score_array) && !empty($score_array)) {
|
||||
$score = ',(
|
||||
SELECT SUM(weight)
|
||||
FROM ' . _DB_PREFIX_ . 'search_word sw
|
||||
LEFT JOIN ' . _DB_PREFIX_ . 'search_index si ON sw.id_word = si.id_word
|
||||
WHERE sw.id_lang = ' . (int) $id_lang . '
|
||||
AND sw.id_shop = ' . $context->shop->id . '
|
||||
AND si.id_product = p.id_product
|
||||
AND (' . implode(' OR ', $score_array) . ')
|
||||
) position';
|
||||
}
|
||||
|
||||
$sql_groups = '';
|
||||
if (Group::isFeatureActive()) {
|
||||
$groups = FrontController::getCurrentCustomerGroups();
|
||||
$sql_groups = 'AND cg.`id_group` ' . (count($groups) ? 'IN (' . implode(',', $groups) . ')' : '= 1');
|
||||
}
|
||||
|
||||
$results = $db->executeS('
|
||||
SELECT cp.`id_product`
|
||||
FROM `' . _DB_PREFIX_ . 'category_product` cp
|
||||
' . (Group::isFeatureActive() ? 'INNER JOIN `' . _DB_PREFIX_ . 'category_group` cg ON cp.`id_category` = cg.`id_category`' : '') . '
|
||||
INNER JOIN `' . _DB_PREFIX_ . 'category` c ON cp.`id_category` = c.`id_category`
|
||||
INNER JOIN `' . _DB_PREFIX_ . 'product` p ON cp.`id_product` = p.`id_product`
|
||||
' . Shop::addSqlAssociation('product', 'p', false) . '
|
||||
WHERE c.`active` = 1
|
||||
AND product_shop.`active` = 1
|
||||
AND product_shop.`visibility` IN ("both", "search")
|
||||
AND product_shop.indexed = 1
|
||||
' . $sql_groups . ($id_cate ? ' AND c.`id_category` = ' . $id_cate : ''), true, false);
|
||||
|
||||
$eligible_products = array();
|
||||
foreach ($results as $row) {
|
||||
$eligible_products[] = $row['id_product'];
|
||||
}
|
||||
foreach ($intersect_array as $query) {
|
||||
$eligible_products2 = array();
|
||||
foreach ($db->executeS($query, true, false) as $row) {
|
||||
$eligible_products2[] = $row['id_product'];
|
||||
}
|
||||
|
||||
$eligible_products = array_intersect($eligible_products, $eligible_products2);
|
||||
if (!count($eligible_products)) {
|
||||
return ($ajax ? array() : array('total' => 0, 'result' => array()));
|
||||
}
|
||||
}
|
||||
|
||||
$eligible_products = array_unique($eligible_products);
|
||||
|
||||
$product_pool = '';
|
||||
foreach ($eligible_products as $id_product) {
|
||||
if ($id_product) {
|
||||
$product_pool .= (int) $id_product . ',';
|
||||
}
|
||||
}
|
||||
if (empty($product_pool)) {
|
||||
return ($ajax ? array() : array('total' => 0, 'result' => array()));
|
||||
}
|
||||
$product_pool = ((strpos($product_pool, ',') === false) ? (' = ' . (int) $product_pool . ' ') : (' IN (' . rtrim($product_pool, ',') . ') '));
|
||||
|
||||
if ($ajax) {
|
||||
$sql = 'SELECT DISTINCT p.id_product, pl.name pname, cl.name cname,
|
||||
cl.link_rewrite crewrite, pl.link_rewrite prewrite ' . $score . '
|
||||
FROM ' . _DB_PREFIX_ . 'product p
|
||||
INNER JOIN `' . _DB_PREFIX_ . 'product_lang` pl ON (
|
||||
p.`id_product` = pl.`id_product`
|
||||
AND pl.`id_lang` = ' . (int) $id_lang . Shop::addSqlRestrictionOnLang('pl') . '
|
||||
)
|
||||
' . Shop::addSqlAssociation('product', 'p') . '
|
||||
INNER JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON ( cl.`id_category`= ' .
|
||||
($id_cate ? $id_cate : 'product_shop.`id_category_default`') .
|
||||
' AND cl.`id_lang` = ' . (int) $id_lang . Shop::addSqlRestrictionOnLang('cl') . '
|
||||
)
|
||||
WHERE p.`id_product` ' . pSQL($product_pool) . '
|
||||
ORDER BY position DESC LIMIT 10';
|
||||
return $db->executeS($sql, true, false);
|
||||
}
|
||||
|
||||
if (strpos($order_by, '.') > 0) {
|
||||
$order_by = explode('.', $order_by);
|
||||
$order_by = pSQL($order_by[0]) . '.`' . pSQL($order_by[1]) . '`';
|
||||
}
|
||||
$alias = '';
|
||||
if ($order_by == 'price') {
|
||||
$alias = 'product_shop.';
|
||||
} elseif (in_array($order_by, array('date_upd', 'date_add'))) {
|
||||
$alias = 'p.';
|
||||
}
|
||||
$sql = 'SELECT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity,
|
||||
pl.`description_short`, pl.`available_now`, pl.`available_later`, pl.`link_rewrite`, pl.`name`,
|
||||
image_shop.`id_image` id_image, il.`legend`, m.`name` manufacturer_name ' . $score . ',
|
||||
DATEDIFF(
|
||||
p.`date_add`,
|
||||
DATE_SUB(
|
||||
"' . date('Y-m-d') . ' 00:00:00",
|
||||
INTERVAL ' . (Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20) . ' DAY
|
||||
)
|
||||
) > 0 new' . (Combination::isFeatureActive() ? ', product_attribute_shop.minimal_quantity AS product_attribute_minimal_quantity, IFNULL(product_attribute_shop.`id_product_attribute`,0) id_product_attribute' : '') . '
|
||||
FROM ' . _DB_PREFIX_ . 'product p
|
||||
' . Shop::addSqlAssociation('product', 'p') . '
|
||||
INNER JOIN `' . _DB_PREFIX_ . 'product_lang` pl ON (
|
||||
p.`id_product` = pl.`id_product`
|
||||
AND pl.`id_lang` = ' . (int) $id_lang . Shop::addSqlRestrictionOnLang('pl') . '
|
||||
)
|
||||
' . (Combination::isFeatureActive() ? 'LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute_shop` product_attribute_shop
|
||||
ON (p.`id_product` = product_attribute_shop.`id_product` AND product_attribute_shop.`default_on` = 1 AND product_attribute_shop.id_shop=' . (int) $context->shop->id . ')' : '') . '
|
||||
' . Product::sqlStock('p', 0) . '
|
||||
LEFT JOIN `' . _DB_PREFIX_ . 'manufacturer` m ON m.`id_manufacturer` = p.`id_manufacturer`
|
||||
LEFT JOIN `' . _DB_PREFIX_ . 'image_shop` image_shop
|
||||
ON (image_shop.`id_product` = p.`id_product` AND image_shop.cover=1 AND image_shop.id_shop=' . (int) $context->shop->id . ')
|
||||
LEFT JOIN `' . _DB_PREFIX_ . 'image_lang` il ON (image_shop.`id_image` = il.`id_image` AND il.`id_lang` = ' . (int) $id_lang . ')
|
||||
WHERE p.`id_product` ' . pSQL($product_pool) . '
|
||||
GROUP BY product_shop.id_product
|
||||
' . ($order_by ? 'ORDER BY ' . $alias . $order_by : '') . ($order_way ? ' ' . $order_way : '') . '
|
||||
LIMIT ' . (int) (($page_number - 1) * $page_size) . ',' . (int) $page_size;
|
||||
$result = $db->executeS($sql, true, false);
|
||||
|
||||
$sql = 'SELECT COUNT(*)
|
||||
FROM ' . _DB_PREFIX_ . 'product p
|
||||
' . Shop::addSqlAssociation('product', 'p') . '
|
||||
INNER JOIN `' . _DB_PREFIX_ . 'product_lang` pl ON (
|
||||
p.`id_product` = pl.`id_product`
|
||||
AND pl.`id_lang` = ' . (int) $id_lang . Shop::addSqlRestrictionOnLang('pl') . '
|
||||
)
|
||||
LEFT JOIN `' . _DB_PREFIX_ . 'manufacturer` m ON m.`id_manufacturer` = p.`id_manufacturer`
|
||||
WHERE p.`id_product` ' . pSQL($product_pool);
|
||||
$total = $db->getValue($sql, false);
|
||||
|
||||
if (!$result) {
|
||||
$result_properties = false;
|
||||
} else {
|
||||
$result_properties = Product::getProductsProperties((int) $id_lang, $result);
|
||||
}
|
||||
|
||||
return array('total' => $total, 'result' => $result_properties);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Db $db
|
||||
* @param int $id_product
|
||||
* @param int $id_lang
|
||||
* @return string
|
||||
*/
|
||||
public static function getTags($db, $id_product, $id_lang)
|
||||
{
|
||||
$tags = '';
|
||||
$tagsArray = $db->executeS('
|
||||
SELECT t.name FROM ' . _DB_PREFIX_ . 'product_tag pt
|
||||
LEFT JOIN ' . _DB_PREFIX_ . 'tag t ON (pt.id_tag = t.id_tag AND t.id_lang = ' . (int) $id_lang . ')
|
||||
WHERE pt.id_product = ' . (int) $id_product, true, false);
|
||||
foreach ($tagsArray as $tag) {
|
||||
$tags .= $tag['name'] . ' ';
|
||||
}
|
||||
return $tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Db $db
|
||||
* @param int $id_product
|
||||
* @param int $id_lang
|
||||
* @return string
|
||||
*/
|
||||
public static function getAttributes($db, $id_product, $id_lang)
|
||||
{
|
||||
if (!Combination::isFeatureActive()) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$attributes = '';
|
||||
$attributesArray = $db->executeS('
|
||||
SELECT al.name FROM ' . _DB_PREFIX_ . 'product_attribute pa
|
||||
INNER JOIN ' . _DB_PREFIX_ . 'product_attribute_combination pac ON pa.id_product_attribute = pac.id_product_attribute
|
||||
INNER JOIN ' . _DB_PREFIX_ . 'attribute_lang al ON (pac.id_attribute = al.id_attribute AND al.id_lang = ' . (int) $id_lang . ')
|
||||
' . Shop::addSqlAssociation('product_attribute', 'pa') . '
|
||||
WHERE pa.id_product = ' . (int) $id_product, true, false);
|
||||
foreach ($attributesArray as $attribute) {
|
||||
$attributes .= $attribute['name'] . ' ';
|
||||
}
|
||||
return $attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Db $db
|
||||
* @param int $id_product
|
||||
* @param int $id_lang
|
||||
* @return string
|
||||
*/
|
||||
public static function getFeatures($db, $id_product, $id_lang)
|
||||
{
|
||||
if (!Feature::isFeatureActive()) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$features = '';
|
||||
$featuresArray = $db->executeS('
|
||||
SELECT fvl.value FROM ' . _DB_PREFIX_ . 'feature_product fp
|
||||
LEFT JOIN ' . _DB_PREFIX_ . 'feature_value_lang fvl ON (fp.id_feature_value = fvl.id_feature_value AND fvl.id_lang = ' . (int) $id_lang . ')
|
||||
WHERE fp.id_product = ' . (int) $id_product, true, false);
|
||||
foreach ($featuresArray as $feature) {
|
||||
$features .= $feature['value'] . ' ';
|
||||
}
|
||||
return $features;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $weight_array
|
||||
* @return string
|
||||
*/
|
||||
protected static function getSQLProductAttributeFields(&$weight_array)
|
||||
{
|
||||
$sql = '';
|
||||
if (is_array($weight_array)) {
|
||||
foreach ($weight_array as $key => $weight) {
|
||||
if ((int) $weight) {
|
||||
switch ($key) {
|
||||
case 'pa_reference':
|
||||
$sql .= ', pa.reference AS pa_reference';
|
||||
break;
|
||||
case 'pa_supplier_reference':
|
||||
$sql .= ', pa.supplier_reference AS pa_supplier_reference';
|
||||
break;
|
||||
case 'pa_ean13':
|
||||
$sql .= ', pa.ean13 AS pa_ean13';
|
||||
break;
|
||||
case 'pa_upc':
|
||||
$sql .= ', pa.upc AS pa_upc';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $sql;
|
||||
}
|
||||
|
||||
protected static function getProductsToIndex($total_languages, $id_product = false, $limit = 50, $weight_array = array())
|
||||
{
|
||||
# VALIDATE MODULE
|
||||
unset($total_languages);
|
||||
|
||||
$ids = null;
|
||||
if (!$id_product) {
|
||||
// Limit products for each step but be sure that each attribute is taken into account
|
||||
$sql = 'SELECT p.id_product FROM ' . _DB_PREFIX_ . 'product p
|
||||
' . Shop::addSqlAssociation('product', 'p', true, null, true) . '
|
||||
WHERE product_shop.`indexed` = 0
|
||||
AND product_shop.`visibility` IN ("both", "search")
|
||||
AND product_shop.`active` = 1
|
||||
ORDER BY product_shop.`id_product` ASC
|
||||
LIMIT ' . (int) $limit;
|
||||
|
||||
|
||||
$res = Db::getInstance()->executeS($sql, false);
|
||||
while ($row = Db::getInstance()->nextRow($res)) {
|
||||
$ids[] = $row['id_product'];
|
||||
}
|
||||
}
|
||||
|
||||
// Now get every attribute in every language
|
||||
$sql = 'SELECT p.id_product, pl.id_lang, pl.id_shop, l.iso_code';
|
||||
|
||||
if (is_array($weight_array)) {
|
||||
foreach ($weight_array as $key => $weight) {
|
||||
if ((int) $weight) {
|
||||
switch ($key) {
|
||||
case 'pname':
|
||||
$sql .= ', pl.name pname';
|
||||
break;
|
||||
case 'reference':
|
||||
$sql .= ', p.reference';
|
||||
break;
|
||||
case 'supplier_reference':
|
||||
$sql .= ', p.supplier_reference';
|
||||
break;
|
||||
case 'ean13':
|
||||
$sql .= ', p.ean13';
|
||||
break;
|
||||
case 'upc':
|
||||
$sql .= ', p.upc';
|
||||
break;
|
||||
case 'description_short':
|
||||
$sql .= ', pl.description_short';
|
||||
break;
|
||||
case 'description':
|
||||
$sql .= ', pl.description';
|
||||
break;
|
||||
case 'cname':
|
||||
$sql .= ', cl.name cname';
|
||||
break;
|
||||
case 'mname':
|
||||
$sql .= ', m.name mname';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$sql .= ' FROM ' . _DB_PREFIX_ . 'product p
|
||||
LEFT JOIN ' . _DB_PREFIX_ . 'product_lang pl
|
||||
ON p.id_product = pl.id_product
|
||||
' . Shop::addSqlAssociation('product', 'p', true, null, true) . '
|
||||
LEFT JOIN ' . _DB_PREFIX_ . 'category_lang cl
|
||||
ON (cl.id_category = product_shop.id_category_default AND pl.id_lang = cl.id_lang AND cl.id_shop = product_shop.id_shop)
|
||||
LEFT JOIN ' . _DB_PREFIX_ . 'manufacturer m
|
||||
ON m.id_manufacturer = p.id_manufacturer
|
||||
LEFT JOIN ' . _DB_PREFIX_ . 'lang l
|
||||
ON l.id_lang = pl.id_lang
|
||||
WHERE product_shop.indexed = 0
|
||||
AND product_shop.visibility IN ("both", "search")
|
||||
' . ($id_product ? 'AND p.id_product = ' . (int) $id_product : '') . '
|
||||
' . ($ids ? 'AND p.id_product IN (' . implode(',', array_map('intval', $ids)) . ')' : '') . '
|
||||
AND product_shop.`active` = 1
|
||||
AND pl.`id_shop` = product_shop.`id_shop`';
|
||||
|
||||
return Db::getInstance()->executeS($sql, true, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Db $db
|
||||
* @param int $id_product
|
||||
* @param string $sql_attribute
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
protected static function getAttributesFields($db, $id_product, $sql_attribute)
|
||||
{
|
||||
return $db->executeS('SELECT id_product ' . $sql_attribute . ' FROM ' .
|
||||
_DB_PREFIX_ . 'product_attribute pa WHERE pa.id_product = ' . (int) $id_product, true, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $product_array
|
||||
* @param $weight_array
|
||||
* @param $key
|
||||
* @param $value
|
||||
* @param $id_lang
|
||||
* @param $iso_code
|
||||
*/
|
||||
protected static function fillProductArray(&$product_array, $weight_array, $key, $value, $id_lang, $iso_code)
|
||||
{
|
||||
if (strncmp($key, 'id_', 3) && isset($weight_array[$key])) {
|
||||
$words = explode(' ', ProductSearch::sanitize($value, (int) $id_lang, true, $iso_code));
|
||||
foreach ($words as $word) {
|
||||
if (!empty($word)) {
|
||||
$word = Tools::substr($word, 0, PS_SEARCH_MAX_WORD_LENGTH);
|
||||
|
||||
if (!isset($product_array[$word])) {
|
||||
$product_array[$word] = 0;
|
||||
}
|
||||
$product_array[$word] += $weight_array[$key];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function indexation($full = false, $id_product = false)
|
||||
{
|
||||
$db = Db::getInstance();
|
||||
|
||||
if ($id_product) {
|
||||
$full = false;
|
||||
}
|
||||
|
||||
if ($full && Context::getContext()->shop->getContext() == Shop::CONTEXT_SHOP) {
|
||||
$db->execute('DELETE si, sw FROM `' . _DB_PREFIX_ . 'search_index` si
|
||||
INNER JOIN `' . _DB_PREFIX_ . 'product` p ON (p.id_product = si.id_product)
|
||||
' . Shop::addSqlAssociation('product', 'p') . '
|
||||
INNER JOIN `' . _DB_PREFIX_ . 'search_word` sw ON (sw.id_word = si.id_word AND product_shop.id_shop = sw.id_shop)
|
||||
WHERE product_shop.`visibility` IN ("both", "search")
|
||||
AND product_shop.`active` = 1');
|
||||
$db->execute('UPDATE `' . _DB_PREFIX_ . 'product` p
|
||||
' . Shop::addSqlAssociation('product', 'p') . '
|
||||
SET p.`indexed` = 0, product_shop.`indexed` = 0
|
||||
WHERE product_shop.`visibility` IN ("both", "search")
|
||||
AND product_shop.`active` = 1
|
||||
');
|
||||
} elseif ($full) {
|
||||
$db->execute('TRUNCATE ' . _DB_PREFIX_ . 'search_index');
|
||||
$db->execute('TRUNCATE ' . _DB_PREFIX_ . 'search_word');
|
||||
ObjectModel::updateMultishopTable('Product', array('indexed' => 0));
|
||||
} else {
|
||||
$db->execute('DELETE si FROM `' . _DB_PREFIX_ . 'search_index` si
|
||||
INNER JOIN `' . _DB_PREFIX_ . 'product` p ON (p.id_product = si.id_product)
|
||||
' . Shop::addSqlAssociation('product', 'p') . '
|
||||
WHERE product_shop.`visibility` IN ("both", "search")
|
||||
AND product_shop.`active` = 1
|
||||
AND ' . ($id_product ? 'p.`id_product` = ' . (int) $id_product : 'product_shop.`indexed` = 0'));
|
||||
|
||||
$db->execute('UPDATE `' . _DB_PREFIX_ . 'product` p
|
||||
' . Shop::addSqlAssociation('product', 'p') . '
|
||||
SET p.`indexed` = 0, product_shop.`indexed` = 0
|
||||
WHERE product_shop.`visibility` IN ("both", "search")
|
||||
AND product_shop.`active` = 1
|
||||
AND ' . ($id_product ? 'p.`id_product` = ' . (int) $id_product : 'product_shop.`indexed` = 0'));
|
||||
}
|
||||
|
||||
// Every fields are weighted according to the configuration in the backend
|
||||
$weight_array = array(
|
||||
'pname' => Configuration::get('PS_SEARCH_WEIGHT_PNAME'),
|
||||
'reference' => Configuration::get('PS_SEARCH_WEIGHT_REF'),
|
||||
'pa_reference' => Configuration::get('PS_SEARCH_WEIGHT_REF'),
|
||||
'supplier_reference' => Configuration::get('PS_SEARCH_WEIGHT_REF'),
|
||||
'pa_supplier_reference' => Configuration::get('PS_SEARCH_WEIGHT_REF'),
|
||||
'ean13' => Configuration::get('PS_SEARCH_WEIGHT_REF'),
|
||||
'pa_ean13' => Configuration::get('PS_SEARCH_WEIGHT_REF'),
|
||||
'upc' => Configuration::get('PS_SEARCH_WEIGHT_REF'),
|
||||
'pa_upc' => Configuration::get('PS_SEARCH_WEIGHT_REF'),
|
||||
'description_short' => Configuration::get('PS_SEARCH_WEIGHT_SHORTDESC'),
|
||||
'description' => Configuration::get('PS_SEARCH_WEIGHT_DESC'),
|
||||
'cname' => Configuration::get('PS_SEARCH_WEIGHT_CNAME'),
|
||||
'mname' => Configuration::get('PS_SEARCH_WEIGHT_MNAME'),
|
||||
'tags' => Configuration::get('PS_SEARCH_WEIGHT_TAG'),
|
||||
'attributes' => Configuration::get('PS_SEARCH_WEIGHT_ATTRIBUTE'),
|
||||
'features' => Configuration::get('PS_SEARCH_WEIGHT_FEATURE')
|
||||
);
|
||||
|
||||
// Those are kind of global variables required to save the processed data in the database every X occurrences, in order to avoid overloading MySQL
|
||||
$count_words = 0;
|
||||
$query_array3 = array();
|
||||
|
||||
// Retrieve the number of languages
|
||||
$total_languages = count(Language::getIDs(false));
|
||||
|
||||
$sql_attribute = Search::getSQLProductAttributeFields($weight_array);
|
||||
// Products are processed 50 by 50 in order to avoid overloading MySQL
|
||||
while (($products = Search::getProductsToIndex($total_languages, $id_product, 50, $weight_array)) && (count($products) > 0)) {
|
||||
$products_array = array();
|
||||
// Now each non-indexed product is processed one by one, langage by langage
|
||||
foreach ($products as $product) {
|
||||
if ((int) $weight_array['tags']) {
|
||||
$product['tags'] = Search::getTags($db, (int) $product['id_product'], (int) $product['id_lang']);
|
||||
}
|
||||
if ((int) $weight_array['attributes']) {
|
||||
$product['attributes'] = Search::getAttributes($db, (int) $product['id_product'], (int) $product['id_lang']);
|
||||
}
|
||||
if ((int) $weight_array['features']) {
|
||||
$product['features'] = Search::getFeatures($db, (int) $product['id_product'], (int) $product['id_lang']);
|
||||
}
|
||||
if ($sql_attribute) {
|
||||
$attribute_fields = Search::getAttributesFields($db, (int) $product['id_product'], $sql_attribute);
|
||||
if ($attribute_fields) {
|
||||
$product['attributes_fields'] = $attribute_fields;
|
||||
}
|
||||
}
|
||||
|
||||
// Data must be cleaned of html, bad characters, spaces and anything, then if the resulting words are long enough, they're added to the array
|
||||
$product_array = array();
|
||||
foreach ($product as $key => $value) {
|
||||
if ($key == 'attributes_fields') {
|
||||
foreach ($value as $pa_array) {
|
||||
foreach ($pa_array as $pa_key => $pa_value) {
|
||||
Search::fillProductArray($product_array, $weight_array, $pa_key, $pa_value, $product['id_lang'], $product['iso_code']);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Search::fillProductArray($product_array, $weight_array, $key, $value, $product['id_lang'], $product['iso_code']);
|
||||
}
|
||||
}
|
||||
|
||||
// If we find words that need to be indexed, they're added to the word table in the database
|
||||
if (is_array($product_array) && !empty($product_array)) {
|
||||
$query_array = $query_array2 = array();
|
||||
foreach ($product_array as $word => $weight) {
|
||||
if ($weight) {
|
||||
$query_array[$word] = '(' . (int) $product['id_lang'] . ', ' . (int) $product['id_shop'] . ', \'' . pSQL($word) . '\')';
|
||||
$query_array2[] = '\'' . pSQL($word) . '\'';
|
||||
}
|
||||
}
|
||||
|
||||
if (is_array($query_array) && !empty($query_array)) {
|
||||
// The words are inserted...
|
||||
$db->execute('
|
||||
INSERT IGNORE INTO ' . _DB_PREFIX_ . 'search_word (id_lang, id_shop, word)
|
||||
VALUES ' . implode(',', $query_array), false);
|
||||
}
|
||||
$word_ids_by_word = array();
|
||||
if (is_array($query_array2) && !empty($query_array2)) {
|
||||
// ...then their IDs are retrieved
|
||||
$added_words = $db->executeS('
|
||||
SELECT sw.id_word, sw.word
|
||||
FROM ' . _DB_PREFIX_ . 'search_word sw
|
||||
WHERE sw.word IN (' . implode(',', $query_array2) . ')
|
||||
AND sw.id_lang = ' . (int) $product['id_lang'] . '
|
||||
AND sw.id_shop = ' . (int) $product['id_shop'], true, false);
|
||||
foreach ($added_words as $word_id) {
|
||||
$word_ids_by_word['_' . $word_id['word']] = (int) $word_id['id_word'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($product_array as $word => $weight) {
|
||||
if (!$weight) {
|
||||
continue;
|
||||
}
|
||||
if (!isset($word_ids_by_word['_' . $word])) {
|
||||
continue;
|
||||
}
|
||||
$id_word = $word_ids_by_word['_' . $word];
|
||||
if (!$id_word) {
|
||||
continue;
|
||||
}
|
||||
$query_array3[] = '(' . (int) $product['id_product'] . ',' .
|
||||
(int) $id_word . ',' . (int) $weight . ')';
|
||||
// Force save every 200 words in order to avoid overloading MySQL
|
||||
if (++$count_words % 200 == 0) {
|
||||
Search::saveIndex($query_array3);
|
||||
}
|
||||
}
|
||||
|
||||
$products_array[] = (int) $product['id_product'];
|
||||
}
|
||||
$products_array = array_unique($products_array);
|
||||
Search::setProductsAsIndexed($products_array);
|
||||
|
||||
// One last save is done at the end in order to save what's left
|
||||
Search::saveIndex($query_array3);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function removeProductsSearchIndex($products)
|
||||
{
|
||||
if (is_array($products) && !empty($products)) {
|
||||
Db::getInstance()->execute('DELETE FROM ' . _DB_PREFIX_ . 'search_index WHERE id_product IN (' . implode(',', array_unique(array_map('intval', $products))) . ')');
|
||||
ObjectModel::updateMultishopTable('Product', array('indexed' => 0), 'a.id_product IN (' . implode(',', array_map('intval', $products)) . ')');
|
||||
}
|
||||
}
|
||||
|
||||
protected static function setProductsAsIndexed(&$products)
|
||||
{
|
||||
if (is_array($products) && !empty($products)) {
|
||||
ObjectModel::updateMultishopTable('Product', array('indexed' => 1), 'a.id_product IN (' . implode(',', array_map('intval', $products)) . ')');
|
||||
}
|
||||
}
|
||||
|
||||
/** $queryArray3 is automatically emptied in order to be reused immediatly */
|
||||
protected static function saveIndex(&$queryArray3)
|
||||
{
|
||||
if (is_array($queryArray3) && !empty($queryArray3)) {
|
||||
Db::getInstance()->execute('INSERT INTO ' . _DB_PREFIX_ . 'search_index (id_product, id_word, weight)
|
||||
VALUES ' . implode(',', $queryArray3) . ' ON DUPLICATE KEY UPDATE weight = weight + VALUES(weight)', false);
|
||||
}
|
||||
$queryArray3 = array();
|
||||
}
|
||||
|
||||
public static function searchTag($id_lang, $tag, $count = false, $pageNumber = 0, $pageSize = 10, $orderBy = false, $orderWay = false, $useCookie = true, Context $context = null)
|
||||
{
|
||||
if (!$context) {
|
||||
$context = Context::getContext();
|
||||
}
|
||||
|
||||
// Only use cookie if id_customer is not present
|
||||
if ($useCookie) {
|
||||
$id_customer = (int) $context->customer->id;
|
||||
} else {
|
||||
$id_customer = 0;
|
||||
}
|
||||
|
||||
# VALIDATE MODULE
|
||||
unset($id_customer);
|
||||
|
||||
if (!is_numeric($pageNumber) || !is_numeric($pageSize) || !Validate::isBool($count) || !Validate::isValidSearch($tag) || $orderBy && !$orderWay || ($orderBy && !Validate::isOrderBy($orderBy)) || ($orderWay && !Validate::isOrderBy($orderWay))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($pageNumber < 1) {
|
||||
$pageNumber = 1;
|
||||
}
|
||||
if ($pageSize < 1) {
|
||||
$pageSize = 10;
|
||||
}
|
||||
|
||||
$id = Context::getContext()->shop->id;
|
||||
$id_shop = $id ? $id : Configuration::get('PS_SHOP_DEFAULT');
|
||||
|
||||
$sql_groups = '';
|
||||
if (Group::isFeatureActive()) {
|
||||
$groups = FrontController::getCurrentCustomerGroups();
|
||||
$sql_groups = 'AND cg.`id_group` ' . (count($groups) ? 'IN (' . implode(',', $groups) . ')' : '= 1');
|
||||
}
|
||||
|
||||
if ($count) {
|
||||
return (int) Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT COUNT(DISTINCT pt.`id_product`) nb
|
||||
FROM `' . _DB_PREFIX_ . 'tag` t
|
||||
STRAIGHT_JOIN `' . _DB_PREFIX_ . 'product_tag` pt ON (pt.`id_tag` = t.`id_tag` AND t.`id_lang` = ' . (int) $id_lang . ')
|
||||
STRAIGHT_JOIN `' . _DB_PREFIX_ . 'product` p ON (p.`id_product` = pt.`id_product`)
|
||||
' . Shop::addSqlAssociation('product', 'p') . '
|
||||
LEFT JOIN `' . _DB_PREFIX_ . 'category_product` cp ON (cp.`id_product` = p.`id_product`)
|
||||
LEFT JOIN `' . _DB_PREFIX_ . 'category_shop` cs ON (cp.`id_category` = cs.`id_category` AND cs.`id_shop` = ' . (int) $id_shop . ')
|
||||
' . (Group::isFeatureActive() ? 'LEFT JOIN `' . _DB_PREFIX_ . 'category_group` cg ON (cg.`id_category` = cp.`id_category`)' : '') . '
|
||||
WHERE product_shop.`active` = 1
|
||||
AND p.visibility IN (\'both\', \'search\')
|
||||
AND cs.`id_shop` = ' . (int) Context::getContext()->shop->id . '
|
||||
' . $sql_groups . ' AND t.`name` LIKE \'%' . pSQL($tag) . '%\'');
|
||||
}
|
||||
|
||||
$sql = 'SELECT DISTINCT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, pl.`description_short`, pl.`link_rewrite`, pl.`name`, pl.`available_now`, pl.`available_later`,
|
||||
MAX(image_shop.`id_image`) id_image, il.`legend`, m.`name` manufacturer_name, 1 position,
|
||||
DATEDIFF(
|
||||
p.`date_add`,
|
||||
DATE_SUB(
|
||||
"' . date('Y-m-d') . ' 00:00:00",
|
||||
INTERVAL ' . (Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20) . ' DAY
|
||||
)
|
||||
) > 0 new
|
||||
FROM
|
||||
`' . _DB_PREFIX_ . 'tag` t
|
||||
STRAIGHT_JOIN `' . _DB_PREFIX_ . 'product_tag` pt ON (pt.`id_tag` = t.`id_tag` AND t.`id_lang` = ' . (int) $id_lang . ')
|
||||
STRAIGHT_JOIN `' . _DB_PREFIX_ . 'product` p ON (p.`id_product` = pt.`id_product`)
|
||||
INNER JOIN `' . _DB_PREFIX_ . 'product_lang` pl ON (
|
||||
p.`id_product` = pl.`id_product`
|
||||
AND pl.`id_lang` = ' . (int) $id_lang . Shop::addSqlRestrictionOnLang('pl') . '
|
||||
)
|
||||
' . Shop::addSqlAssociation('product', 'p', false) . '
|
||||
LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute_shop` product_attribute_shop
|
||||
ON (p.`id_product` = product_attribute_shop.`id_product` AND product_attribute_shop.`default_on` = 1 AND product_attribute_shop.id_shop=' . (int) $context->shop->id . ')
|
||||
LEFT JOIN `' . _DB_PREFIX_ . 'image_shop` image_shop
|
||||
ON (image_shop.`id_product` = p.`id_product` AND image_shop.cover=1 AND image_shop.id_shop=' . (int) $context->shop->id . ')
|
||||
LEFT JOIN `' . _DB_PREFIX_ . 'image_lang` il ON (image_shop.`id_image` = il.`id_image` AND il.`id_lang` = ' . (int) $id_lang . ')
|
||||
LEFT JOIN `' . _DB_PREFIX_ . 'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`)
|
||||
LEFT JOIN `' . _DB_PREFIX_ . 'category_product` cp ON (cp.`id_product` = p.`id_product`)
|
||||
' . (Group::isFeatureActive() ? 'LEFT JOIN `' . _DB_PREFIX_ . 'category_group` cg ON (cg.`id_category` = cp.`id_category`)' : '') . '
|
||||
LEFT JOIN `' . _DB_PREFIX_ . 'category_shop` cs ON (cp.`id_category` = cs.`id_category` AND cs.`id_shop` = ' . (int) $id_shop . ')
|
||||
' . Product::sqlStock('p', 0) . '
|
||||
WHERE product_shop.`active` = 1
|
||||
AND cs.`id_shop` = ' . (int) Context::getContext()->shop->id . '
|
||||
' . $sql_groups . '
|
||||
AND t.`name` LIKE \'%' . pSQL($tag) . '%\'
|
||||
GROUP BY product_shop.id_product
|
||||
ORDER BY position DESC' . ($orderBy ? ', ' . $orderBy : '') . ($orderWay ? ' ' . $orderWay : '') . '
|
||||
LIMIT ' . (int) (($pageNumber - 1) * $pageSize) . ',' . (int) $pageSize;
|
||||
if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql, true, false)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return Product::getProductsProperties((int) $id_lang, $result);
|
||||
}
|
||||
}
|
||||
35
modules/leoproductsearch/classes/index.php
Normal file
35
modules/leoproductsearch/classes/index.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2014 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/afl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2014 PrestaShop SA
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
||||
12
modules/leoproductsearch/config.xml
Normal file
12
modules/leoproductsearch/config.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<module>
|
||||
<name>leoproductsearch</name>
|
||||
<displayName><![CDATA[Quick product search by category block]]></displayName>
|
||||
<version><![CDATA[2.1.6]]></version>
|
||||
<description><![CDATA[Adds a quick product search field to your website.]]></description>
|
||||
<author><![CDATA[LeoTheme]]></author>
|
||||
<tab><![CDATA[search_filter]]></tab>
|
||||
<is_configurable>0</is_configurable>
|
||||
<need_instance>0</need_instance>
|
||||
<limited_countries></limited_countries>
|
||||
</module>
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2015 Leotheme
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* Quick product search by category block
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* @author leotheme <leotheme@gmail.com>
|
||||
* @copyright 2007-2015 Leotheme
|
||||
* @license http://leotheme.com - prestashop template provider
|
||||
*/
|
||||
|
||||
if (!defined('_PS_VERSION_')) {
|
||||
# module validation
|
||||
exit;
|
||||
}
|
||||
|
||||
class AdminLeoProductSearchModuleController extends ModuleAdminControllerCore
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$url = 'index.php?controller=AdminModules&configure=leoproductsearch&token=' . Tools::getAdminTokenLite('AdminModules');
|
||||
Tools::redirectAdmin($url);
|
||||
}
|
||||
}
|
||||
36
modules/leoproductsearch/controllers/admin/index.php
Normal file
36
modules/leoproductsearch/controllers/admin/index.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2014 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/osl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2014 PrestaShop SA
|
||||
* @version Release: $Revision$
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
||||
36
modules/leoproductsearch/controllers/front/index.php
Normal file
36
modules/leoproductsearch/controllers/front/index.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2014 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/osl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2014 PrestaShop SA
|
||||
* @version Release: $Revision$
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
||||
559
modules/leoproductsearch/controllers/front/productsearch.php
Normal file
559
modules/leoproductsearch/controllers/front/productsearch.php
Normal file
@@ -0,0 +1,559 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2015 Leotheme
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* Quick product search by category block
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* @author leotheme <leotheme@gmail.com>
|
||||
* @copyright 2007-2015 Leotheme
|
||||
* @license http://leotheme.com - prestashop template provider
|
||||
*/
|
||||
|
||||
if (!defined('_PS_VERSION_')) {
|
||||
# module validation
|
||||
exit;
|
||||
}
|
||||
if (file_exists(_PS_MODULE_DIR_ . 'leoproductsearch/classes/LeoSearchProductSearchProvider.php')) {
|
||||
require_once(_PS_MODULE_DIR_ . 'leoproductsearch/classes/LeoSearchProductSearchProvider.php');
|
||||
}
|
||||
|
||||
use PrestaShop\PrestaShop\Core\Module\WidgetInterface;
|
||||
// use PrestaShop\PrestaShop\Adapter\Category\CategoryProductSearchProvider;
|
||||
use PrestaShop\PrestaShop\Adapter\Image\ImageRetriever;
|
||||
use PrestaShop\PrestaShop\Adapter\Product\PriceFormatter;
|
||||
use PrestaShop\PrestaShop\Core\Product\ProductListingPresenter;
|
||||
use PrestaShop\PrestaShop\Adapter\Product\ProductColorsRetriever;
|
||||
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchContext;
|
||||
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchQuery;
|
||||
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchResult;
|
||||
use PrestaShop\PrestaShop\Core\Product\Search\SortOrder;
|
||||
// use PrestaShop\PrestaShop\Adapter\Search\SearchProductSearchProvider;
|
||||
use PrestaShop\PrestaShop\Core\Product\Search\Pagination;
|
||||
use PrestaShop\PrestaShop\Core\Product\Search\FacetsRendererInterface;
|
||||
|
||||
// use LeoSearch\LeoSearchProductSearchProvider;
|
||||
|
||||
class LeoproductsearchproductsearchModuleFrontController extends ModuleFrontController
|
||||
{
|
||||
|
||||
public $php_self;
|
||||
public $instant_search;
|
||||
public $ajax_search;
|
||||
private $search_string;
|
||||
private $search_tag;
|
||||
private $search_cate;
|
||||
private $search_manufacture;
|
||||
|
||||
/**
|
||||
* Initialize search controller
|
||||
* @see FrontController::init()
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
$this->instant_search = Tools::getValue('instantSearch');
|
||||
|
||||
$this->ajax_search = Tools::getValue('ajaxSearch');
|
||||
|
||||
$this->search_string = Tools::getValue('q');
|
||||
if (!$this->search_string) {
|
||||
$this->search_string = Tools::getValue('search_query');
|
||||
}
|
||||
|
||||
$this->search_tag = Tools::getValue('tag');
|
||||
$this->search_cate = Tools::getValue('cate');
|
||||
$this->search_manufacture = Tools::getValue('manufac');
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign template vars related to page content
|
||||
* @see FrontController::initContent()
|
||||
*/
|
||||
public function initContent()
|
||||
{
|
||||
$this->php_self = 'productsearch';
|
||||
|
||||
parent::initContent();
|
||||
|
||||
if ($this->ajax_search && !$this->isTokenValid()) {
|
||||
# validate module
|
||||
$this->ajaxDie(Tools::jsonEncode(array('products' => array())));
|
||||
}
|
||||
|
||||
// if (!$this->isTokenValid()) {
|
||||
// # validate module
|
||||
// Tools::redirect('index.php');
|
||||
// }
|
||||
|
||||
if ($this->ajax || $this->ajax_search) {
|
||||
$this->ajaxDie(Tools::jsonEncode($this->getAjaxProductSearchVariables()));
|
||||
}
|
||||
// $products = $this->getProducts();
|
||||
$search_products = $this->getProducts();
|
||||
// $search_products['products'] = $products;
|
||||
$this->context->smarty->assign(array(
|
||||
'search_products' => $search_products,
|
||||
'search_query' => $this->search_string,
|
||||
'nbProducts' => $search_products['pagination']['total_items'],
|
||||
));
|
||||
$this->setTemplate('module:leoproductsearch/views/templates/front/search.tpl');
|
||||
}
|
||||
|
||||
protected function getAjaxProductSearchVariables()
|
||||
{
|
||||
$search = $this->getProducts();
|
||||
|
||||
if (!$this->ajax_search) {
|
||||
$rendered_products_top = $this->render('catalog/_partials/products-top', array('listing' => $search));
|
||||
$rendered_products = $this->render('catalog/_partials/products', array('listing' => $search));
|
||||
$rendered_products_bottom = $this->render('catalog/_partials/products-bottom', array('listing' => $search));
|
||||
|
||||
$data = array(
|
||||
'rendered_products_top' => $rendered_products_top,
|
||||
'rendered_products' => $rendered_products,
|
||||
'rendered_products_bottom' => $rendered_products_bottom,
|
||||
);
|
||||
}
|
||||
|
||||
//DONGND:: update 1.7.2.4
|
||||
foreach ($search as $key => $value) {
|
||||
if ($key === 'products') {
|
||||
$value = $this->prepareProductArrayForAjaxReturn($value);
|
||||
}
|
||||
$data[$key] = $value;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleans the products array with only whitelisted properties.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function prepareProductArrayForAjaxReturn(array $products)
|
||||
{
|
||||
$allowed_properties = array('id_product', 'price', 'reference', 'active', 'description_short', 'link',
|
||||
'link_rewrite', 'name', 'manufacturer_name', 'position', 'url', 'canonical_url', 'add_to_cart_url',
|
||||
'has_discount', 'discount_type', 'discount_percentage', 'discount_percentage_absolute', 'discount_amount',
|
||||
'price_amount', 'regular_price_amount', 'regular_price', 'discount_to_display', 'labels', 'main_variants',
|
||||
'unit_price', 'tax_name', 'rate', 'cover'
|
||||
);
|
||||
foreach ($products as $product_key => $product) {
|
||||
foreach ($product as $product_property => $data) {
|
||||
# VALIDATE MODULE
|
||||
unset($data);
|
||||
if (!in_array($product_property, $allowed_properties)) {
|
||||
unset($products[$product_key][$product_property]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $products;
|
||||
}
|
||||
|
||||
protected function getProducts()
|
||||
{
|
||||
$searchProvider = new LeoSearchProductSearchProvider(
|
||||
$this->context->getTranslator()
|
||||
);
|
||||
|
||||
$context = new ProductSearchContext($this->context);
|
||||
|
||||
if ($this->ajax_search && Tools::getValue('limit')) {
|
||||
$products_per_page = Tools::getValue('limit');
|
||||
} else {
|
||||
$products_per_page = Configuration::get('PS_PRODUCTS_PER_PAGE');
|
||||
}
|
||||
|
||||
//DONGND:: fix to display filter default Sort by
|
||||
if (version_compare(_PS_VERSION_, '1.7.3.0', '>')) {
|
||||
$sort_oder_by = 'position';
|
||||
$sort_oder_way = 'desc';
|
||||
} else {
|
||||
$sort_oder_by = Tools::getProductsOrder('by');
|
||||
$sort_oder_way = Tools::getProductsOrder('way');
|
||||
}
|
||||
|
||||
$query = new ProductSearchQuery();
|
||||
$query
|
||||
->setSortOrder(new SortOrder('product', $sort_oder_by, $sort_oder_way))
|
||||
->setSearchString($this->search_string)
|
||||
->setSearchTag($this->search_tag)
|
||||
->setResultsPerPage($products_per_page)
|
||||
->setPage(max((int) Tools::getValue('page'), 1))
|
||||
;
|
||||
|
||||
if ($this->search_cate && $this->search_cate != '') {
|
||||
$query->setIdCategory((int) $this->search_cate);
|
||||
}
|
||||
if ($this->search_manufacture && $this->search_manufacture != '') {
|
||||
$query->setIdManufacturer((int) $this->search_manufacture);
|
||||
}
|
||||
|
||||
// set the sort order if provided in the URL
|
||||
if (($encodedSortOrder = Tools::getValue('order'))) {
|
||||
$query->setSortOrder(SortOrder::newFromString($encodedSortOrder));
|
||||
}
|
||||
|
||||
$result = $searchProvider->runQuery($context, $query);
|
||||
|
||||
$assembler = new ProductAssembler($this->context);
|
||||
|
||||
$presenterFactory = new ProductPresenterFactory($this->context);
|
||||
$presentationSettings = $presenterFactory->getPresentationSettings();
|
||||
$presenter = new ProductListingPresenter(new ImageRetriever($this->context->link), $this->context->link, new PriceFormatter(), new ProductColorsRetriever(), $this->context->getTranslator());
|
||||
|
||||
$products_for_template = array();
|
||||
|
||||
foreach ($result->getProducts() as $rawProduct) {
|
||||
$product_temp = $presenter->present(
|
||||
$presentationSettings,
|
||||
$assembler->assembleProduct($rawProduct),
|
||||
$this->context->language
|
||||
);
|
||||
# FIX 1.7.5.0
|
||||
if (is_object($product_temp) && method_exists($product_temp, 'jsonSerialize')) {
|
||||
$product_temp = $product_temp->jsonSerialize();
|
||||
}
|
||||
$products_for_template[] = $product_temp;
|
||||
}
|
||||
|
||||
if ($this->ajax_search) {
|
||||
$searchVariables = array(
|
||||
'link' => 'index.php?fc=module&module=leoproductsearch&controller=productsearch&cate='.$this->search_cate.'&q='.$this->search_string.'&limit='.Configuration::get('PS_PRODUCTS_PER_PAGE').'&leoproductsearch_static_token='.Tools::getValue('leoproductsearch_static_token'),
|
||||
'total_items' => isset($this->getTemplateVarPagination($query, $result)['total_items']) ? $this->getTemplateVarPagination($query, $result)['total_items'] : 0,
|
||||
'suggest' => $this->getSearchSuggest(),
|
||||
'category' => $this->getCategoryProductCount($products_for_template),
|
||||
'manufacturer' => $this->getManufacturerProductCount($products_for_template),
|
||||
'products' => $products_for_template,
|
||||
);
|
||||
return $searchVariables;
|
||||
}
|
||||
|
||||
// render the facets
|
||||
if ($searchProvider instanceof FacetsRendererInterface) {
|
||||
// with the provider if it wants to
|
||||
$rendered_facets = $searchProvider->renderFacets($context, $result);
|
||||
$rendered_active_filters = $searchProvider->renderActiveFilters($context, $result);
|
||||
} else {
|
||||
// with the core
|
||||
$rendered_facets = $this->renderFacets($result);
|
||||
$rendered_active_filters = $this->renderActiveFilters($result);
|
||||
}
|
||||
|
||||
$pagination = $this->getTemplateVarPagination($query, $result);
|
||||
$sort_orders = $this->getTemplateVarSortOrders(
|
||||
$result->getAvailableSortOrders(),
|
||||
$query->getSortOrder()->toString()
|
||||
);
|
||||
|
||||
$sort_selected = false;
|
||||
if (!empty($sort_orders)) {
|
||||
foreach ($sort_orders as $order) {
|
||||
if (isset($order['current']) && true === $order['current']) {
|
||||
$sort_selected = $order['label'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$searchVariables = array(
|
||||
'products' => $products_for_template,
|
||||
'pagination' => $pagination,
|
||||
'sort_orders' => $sort_orders,
|
||||
'sort_selected' => $sort_selected,
|
||||
'rendered_facets' => $rendered_facets,
|
||||
'rendered_active_filters' => $rendered_active_filters,
|
||||
'js_enabled' => $this->ajax,
|
||||
'current_url' => $this->updateQueryString(array('q' => $result->getEncodedFacets())),
|
||||
'suggest' => $this->getSearchSuggest(),
|
||||
'category' => $this->getCategoryProductCount($products_for_template),
|
||||
'manufacturer' => $this->getManufacturerProductCount($products_for_template),
|
||||
);
|
||||
|
||||
Hook::exec('actionProductSearchComplete', $searchVariables);
|
||||
|
||||
return $searchVariables;
|
||||
}
|
||||
|
||||
protected function getTemplateVarPagination(ProductSearchQuery $query, ProductSearchResult $result)
|
||||
{
|
||||
$pagination = new Pagination();
|
||||
$pagination
|
||||
->setPage($query->getPage())
|
||||
->setPagesCount((int) ceil($result->getTotalProductsCount() / $query->getResultsPerPage()));
|
||||
|
||||
$totalItems = $result->getTotalProductsCount();
|
||||
$itemsShownFrom = ($query->getResultsPerPage() * ($query->getPage() - 1)) + 1;
|
||||
$itemsShownTo = $query->getResultsPerPage() * $query->getPage();
|
||||
return array(
|
||||
'total_items' => $totalItems,
|
||||
'items_shown_from' => $itemsShownFrom,
|
||||
'items_shown_to' => ($itemsShownTo <= $totalItems) ? $itemsShownTo : $totalItems,
|
||||
// 'pages' => array_map(function ($link) {
|
||||
// $link['url'] = $this->updateQueryString(array(
|
||||
// 'page' => $link['page'],
|
||||
// ));
|
||||
//
|
||||
// return $link;
|
||||
// }, $pagination->buildLinks()),
|
||||
'pages' => $this->leoGetLink($pagination),
|
||||
'should_be_displayed' => (count($pagination->buildLinks()) > 3)
|
||||
);
|
||||
}
|
||||
|
||||
public function leoGetLink($pagination)
|
||||
{
|
||||
|
||||
$links = $pagination->buildLinks();
|
||||
foreach ($links as &$link) {
|
||||
$link['url'] = $this->updateQueryString(array('page' => $link['page']));
|
||||
}
|
||||
|
||||
return $links;
|
||||
}
|
||||
|
||||
protected function renderFacets(ProductSearchResult $result)
|
||||
{
|
||||
$facetCollection = $result->getFacetCollection();
|
||||
// not all search providers generate menus
|
||||
if (empty($facetCollection)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$facetsVar = array_map(array($this, 'prepareFacetForTemplate'), $facetCollection->getFacets());
|
||||
|
||||
$activeFilters = array();
|
||||
foreach ($facetsVar as $facet) {
|
||||
foreach ($facet['filters'] as $filter) {
|
||||
if ($filter['active']) {
|
||||
$activeFilters[] = $filter;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render('catalog/_partials/facets', array(
|
||||
'facets' => $facetsVar,
|
||||
'js_enabled' => $this->ajax,
|
||||
'activeFilters' => $activeFilters,
|
||||
'sort_order' => $result->getCurrentSortOrder()->toString(),
|
||||
'clear_all_link' => $this->updateQueryString(array('q' => null, 'page' => null))
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders an array of active filters.
|
||||
*
|
||||
* @param array $facets
|
||||
*
|
||||
* @return string the HTML of the facets
|
||||
*/
|
||||
protected function renderActiveFilters(ProductSearchResult $result)
|
||||
{
|
||||
$facetCollection = $result->getFacetCollection();
|
||||
// not all search providers generate menus
|
||||
if (empty($facetCollection)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$facetsVar = array_map(array($this, 'prepareFacetForTemplate'), $facetCollection->getFacets());
|
||||
|
||||
$activeFilters = array();
|
||||
foreach ($facetsVar as $facet) {
|
||||
foreach ($facet['filters'] as $filter) {
|
||||
if ($filter['active']) {
|
||||
$activeFilters[] = $filter;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render('catalog/_partials/active_filters', array(
|
||||
'activeFilters' => $activeFilters,
|
||||
'clear_all_link' => $this->updateQueryString(array('q' => null, 'page' => null))
|
||||
));
|
||||
}
|
||||
|
||||
//DONGND:: get layout
|
||||
public function getLayout()
|
||||
{
|
||||
$entity = 'module-leoproductsearch-' . $this->php_self;
|
||||
|
||||
$layout = $this->context->shop->theme->getLayoutRelativePathForPage($entity);
|
||||
|
||||
if ($overridden_layout = Hook::exec('overrideLayoutTemplate', array(
|
||||
'default_layout' => $layout,
|
||||
'entity' => $entity,
|
||||
'locale' => $this->context->language->locale,
|
||||
'controller' => $this))) {
|
||||
return $overridden_layout;
|
||||
}
|
||||
|
||||
if ((int) Tools::getValue('content_only')) {
|
||||
$layout = 'layouts/layout-content-only.tpl';
|
||||
}
|
||||
|
||||
return $layout;
|
||||
}
|
||||
|
||||
protected function getTemplateVarSortOrders(array $sortOrders, $currentSortOrderURLParameter)
|
||||
{
|
||||
# VALIDATE MODULE
|
||||
foreach ($sortOrders as &$sortOrder) {
|
||||
$order = $sortOrder->toArray();
|
||||
$order['current'] = $order['urlParameter'] === $currentSortOrderURLParameter;
|
||||
$order['url'] = $this->updateQueryString(array(
|
||||
'order' => $order['urlParameter'],
|
||||
'page' => null,
|
||||
));
|
||||
$sortOrder = $order;
|
||||
}
|
||||
return $sortOrders;
|
||||
// return array_map(function ($sortOrder) use ($currentSortOrderURLParameter) {
|
||||
// $order = $sortOrder->toArray();
|
||||
// $order['current'] = $order['urlParameter'] === $currentSortOrderURLParameter;
|
||||
// $order['url'] = $this->updateQueryString(array(
|
||||
// 'order' => $order['urlParameter'],
|
||||
// 'page' => null,
|
||||
// ));
|
||||
//
|
||||
// return $order;
|
||||
// }, $sortOrders);
|
||||
}
|
||||
|
||||
public function getBreadcrumbLinks()
|
||||
{
|
||||
$breadcrumb = parent::getBreadcrumbLinks();
|
||||
|
||||
$breadcrumb['links'][] = array(
|
||||
'title' => $this->l('Search', 'productsearch'),
|
||||
'url' => '',
|
||||
);
|
||||
|
||||
return $breadcrumb;
|
||||
}
|
||||
|
||||
public function isTokenValid()
|
||||
{
|
||||
if (!Configuration::get('PS_TOKEN_ENABLE')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return strcasecmp(Tools::getToken(false), Tools::getValue('leoproductsearch_static_token')) == 0;
|
||||
}
|
||||
|
||||
protected function getCategoryProductCount($products){
|
||||
if (Configuration::get('LEOPRODUCTSEARCH_ENABLE_SUGGEST')) {
|
||||
$arr_cat = array();
|
||||
$i=0;
|
||||
foreach ($products as $key => $value) {
|
||||
$status = 1;
|
||||
for($j=0; $j<count($arr_cat); $j++){
|
||||
if($arr_cat[$j]['id'] == $value['id_category_default']){
|
||||
$status = 0;
|
||||
}
|
||||
}
|
||||
if ($status) {
|
||||
$arr_cat[$i]['id'] = $value['id_category_default'];
|
||||
$arr_cat[$i]['name'] = $value['category_name'];
|
||||
$arr_cat[$i]['link'] = 'index.php?fc=module&module=leoproductsearch&controller=productsearch&cate='.$value['id_category_default'].'&q='.$this->search_string.'&limit='.Configuration::get('PS_PRODUCTS_PER_PAGE').'&leoproductsearch_static_token='.Tools::getValue('leoproductsearch_static_token');
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
for ($i=0; $i < count($arr_cat); $i++) {
|
||||
for ($j=0; $j < count($arr_cat); $j++) {
|
||||
if(strtolower($arr_cat[$i]['name']) < strtolower($arr_cat[$j]['name'])) {
|
||||
$tg = $arr_cat[$i];
|
||||
$arr_cat[$i] = $arr_cat[$j];
|
||||
$arr_cat[$j] = $tg;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for ($i=0; $i < count($arr_cat); $i++) {
|
||||
$count = 0;
|
||||
foreach ($products as $key => $value) {
|
||||
if ($arr_cat[$i]['id'] == $value['id_category_default']){
|
||||
$count ++;
|
||||
}
|
||||
}
|
||||
$arr_cat[$i]['count'] = $count;
|
||||
}
|
||||
|
||||
return $arr_cat;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
protected function getManufacturerProductCount($products){
|
||||
$arr_manufacturer = array();
|
||||
$i=0;
|
||||
foreach ($products as $key => $value) {
|
||||
$status = 1;
|
||||
for($j=0; $j<count($arr_manufacturer); $j++){
|
||||
if($arr_manufacturer[$j]['id'] == $value['id_manufacturer']){
|
||||
$status = 0;
|
||||
}
|
||||
}
|
||||
if ($status) {
|
||||
$arr_manufacturer[$i]['id'] = $value['id_manufacturer'];
|
||||
$arr_manufacturer[$i]['name'] = $value['manufacturer_name'];
|
||||
$arr_manufacturer[$i]['link'] = 'index.php?fc=module&module=leoproductsearch&controller=productsearch&manufac='.$value['id_manufacturer'].'&q='.$this->search_string.'&limit='.Configuration::get('PS_PRODUCTS_PER_PAGE').'&leoproductsearch_static_token='.Tools::getValue('leoproductsearch_static_token');
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
for ($i=0; $i < count($arr_manufacturer); $i++) {
|
||||
for ($j=0; $j < count($arr_manufacturer); $j++) {
|
||||
if(strtolower($arr_manufacturer[$i]['name']) < strtolower($arr_manufacturer[$j]['name'])) {
|
||||
$tg = $arr_manufacturer[$i];
|
||||
$arr_manufacturer[$i] = $arr_manufacturer[$j];
|
||||
$arr_manufacturer[$j] = $tg;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for ($i=0; $i < count($arr_manufacturer); $i++) {
|
||||
$count = 0;
|
||||
foreach ($products as $key => $value) {
|
||||
if ($arr_manufacturer[$i]['id'] == $value['id_manufacturer']){
|
||||
$count ++;
|
||||
}
|
||||
}
|
||||
$arr_manufacturer[$i]['count'] = $count;
|
||||
}
|
||||
|
||||
return $arr_manufacturer;
|
||||
}
|
||||
|
||||
protected function getSearchSuggest(){
|
||||
if (Configuration::get('LEOPRODUCTSEARCH_ENABLE_SUGGEST')) {
|
||||
$sql = 'SELECT word FROM ' . _DB_PREFIX_ . 'search_word WHERE word = "' . $this->search_string . '" GROUP BY word';
|
||||
$results = Db::getInstance()->ExecuteS($sql);
|
||||
|
||||
if (!$results) {
|
||||
$sql = 'SELECT word FROM ' . _DB_PREFIX_ . 'search_word WHERE word LIKE "' . $this->search_string . '%" GROUP BY word ORDER BY word ASC LIMIT 3';
|
||||
$results = Db::getInstance()->ExecuteS($sql);
|
||||
}
|
||||
if (!$results) {
|
||||
for ($i=2; $i < strlen($this->search_string); $i++) {
|
||||
$sql = 'SELECT word FROM ' . _DB_PREFIX_ . 'search_word WHERE word LIKE "' . substr($this->search_string, 0 ,$i * -1) . '%" GROUP BY word ORDER BY word ASC LIMIT 3';
|
||||
$results = Db::getInstance()->ExecuteS($sql);
|
||||
if ($results) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for ($i=0; $i<count($results); $i++){
|
||||
$results[$i]['link'] = 'index.php?fc=module&module=leoproductsearch&controller=productsearch&cate='.$this->search_cate.'&q='.$results[$i]['word'].'&limit='.Configuration::get('PS_PRODUCTS_PER_PAGE').'&leoproductsearch_static_token='.Tools::getValue('leoproductsearch_static_token');
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
36
modules/leoproductsearch/controllers/index.php
Normal file
36
modules/leoproductsearch/controllers/index.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2014 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/osl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2014 PrestaShop SA
|
||||
* @version Release: $Revision$
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
||||
35
modules/leoproductsearch/index.php
Normal file
35
modules/leoproductsearch/index.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2014 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/afl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2014 PrestaShop SA
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
||||
673
modules/leoproductsearch/leoproductsearch.php
Normal file
673
modules/leoproductsearch/leoproductsearch.php
Normal file
@@ -0,0 +1,673 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2015 Leotheme
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* Quick product search by category block
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* @author leotheme <leotheme@gmail.com>
|
||||
* @copyright 2007-2015 Leotheme
|
||||
* @license http://leotheme.com - prestashop template provider
|
||||
*/
|
||||
|
||||
if (!defined('_PS_VERSION_')) {
|
||||
# module validation
|
||||
exit;
|
||||
}
|
||||
|
||||
class LeoProductSearch extends Module
|
||||
{
|
||||
|
||||
public $tabs;
|
||||
protected $_postErrors = array();
|
||||
private $_html = '';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->name = 'leoproductsearch';
|
||||
$this->tab = 'search_filter';
|
||||
$this->version = '2.1.6';
|
||||
$this->author = 'LeoTheme';
|
||||
$this->need_instance = 0;
|
||||
$this->controllers = array('productsearch');
|
||||
$this->bootstrap = true;
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->displayName = $this->l('Quick product search by category block');
|
||||
$this->description = $this->l('Adds a quick product search field to your website.');
|
||||
$this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_);
|
||||
|
||||
//DONGND:: create tab array
|
||||
$this->tabs = array(
|
||||
array(
|
||||
'class_name' => 'AdminLeoProductSearchModule',
|
||||
'name' => 'Leo Product Search Configuration',
|
||||
'id_parent' => Tab::getIdFromClassName('AdminParentModulesSf'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
public function install()
|
||||
{
|
||||
if (parent::install() && $this->registerLeoHook()) {
|
||||
$res = true;
|
||||
//DONGND:: add tab
|
||||
foreach ($this->tabs as $tab) {
|
||||
$newtab = new Tab();
|
||||
$newtab->class_name = $tab['class_name'];
|
||||
$newtab->id_parent = isset($tab['id_parent']) ? $tab['id_parent'] : 0;
|
||||
$newtab->module = 'leoproductsearch';
|
||||
foreach (Language::getLanguages(false) as $l) {
|
||||
$newtab->name[$l['id_lang']] = $this->l($tab['name']);
|
||||
}
|
||||
$res &= $newtab->save();
|
||||
}
|
||||
|
||||
$this->_installDataSample();
|
||||
$this->createConfiguration();
|
||||
|
||||
return (bool) $res;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function uninstall()
|
||||
{
|
||||
if (parent::uninstall() && $this->unregisterLeoHook()) {
|
||||
$res = true;
|
||||
|
||||
foreach ($this->tabs as $tab) {
|
||||
$id = Tab::getIdFromClassName($tab['class_name']);
|
||||
if ($id) {
|
||||
$tab = new Tab($id);
|
||||
$tab->delete();
|
||||
}
|
||||
}
|
||||
|
||||
$this->deleteConfiguration();
|
||||
|
||||
return (bool) $res;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function registerLeoHook()
|
||||
{
|
||||
$res = true;
|
||||
$res &= $this->registerHook('top');
|
||||
$res &= $this->registerHook('header');
|
||||
$res &= $this->registerHook('displayMobileTopSiteMap');
|
||||
$res &= $this->registerHook('actionAdminControllerSetMedia');
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Common method
|
||||
* Unresgister all hook for module
|
||||
*/
|
||||
public function unregisterLeoHook()
|
||||
{
|
||||
$res = true;
|
||||
$res &= $this->unregisterHook('top');
|
||||
$res &= $this->unregisterHook('header');
|
||||
$res &= $this->unregisterHook('displayMobileTopSiteMap');
|
||||
$res &= $this->unregisterHook('actionAdminControllerSetMedia');
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
//DONGND:: create configs
|
||||
public function createConfiguration()
|
||||
{
|
||||
Configuration::updateValue('LEOPRODUCTSEARCH_ENABLE', 1);
|
||||
Configuration::updateValue('LEOPRODUCTSEARCH_ENABLE_AJAXSEARCH', 1);
|
||||
Configuration::updateValue('LEOPRODUCTSEARCH_NUMPRO_DISPLAY', 100);
|
||||
Configuration::updateValue('LEOPRODUCTSEARCH_ENABLE_CATEGORY', 1);
|
||||
Configuration::updateValue('LEOPRODUCTSEARCH_ENABLE_SUGGEST', 1);
|
||||
Configuration::updateValue('LEOPRODUCTSEARCH_ENABLE_CATEGORYPRODUCTCOUNT', 1);
|
||||
Configuration::updateValue('LEOPRODUCTSEARCH_CATEGORY_MAXDEPTH', 0);
|
||||
Configuration::updateValue('LEOPRODUCTSEARCH_ENABLE_PRODUCTIMG', 1);
|
||||
Configuration::updateValue('LEOPRODUCTSEARCH_ENABLE_PRODUCTPRICE', 1);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//DONGND:: delete configs
|
||||
public function deleteConfiguration()
|
||||
{
|
||||
Configuration::deleteByName('LEOPRODUCTSEARCH_ENABLE');
|
||||
Configuration::deleteByName('LEOPRODUCTSEARCH_ENABLE_AJAXSEARCH');
|
||||
Configuration::deleteByName('LEOPRODUCTSEARCH_NUMPRO_DISPLAY');
|
||||
Configuration::deleteByName('LEOPRODUCTSEARCH_ENABLE_CATEGORY');
|
||||
Configuration::deleteByName('LEOPRODUCTSEARCH_ENABLE_SUGGEST', 1);
|
||||
Configuration::deleteByName('LEOPRODUCTSEARCH_ENABLE_CATEGORYPRODUCTCOUNT', 1);
|
||||
Configuration::deleteByName('LEOPRODUCTSEARCH_CATEGORY_MAXDEPTH');
|
||||
Configuration::deleteByName('LEOPRODUCTSEARCH_ENABLE_PRODUCTIMG');
|
||||
Configuration::deleteByName('LEOPRODUCTSEARCH_ENABLE_PRODUCTPRICE');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function postProcess()
|
||||
{
|
||||
if (count($this->errors) > 0) {
|
||||
$this->ajax = Tools::getValue('ajax') || Tools::isSubmit('ajax');
|
||||
if ($this->ajax) {
|
||||
$array = array('hasError' => true, 'errors' => $this->errors[0]);
|
||||
die(Tools::jsonEncode($array));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
//DONGND:: correct module
|
||||
if (Tools::getValue('correctmodule')) {
|
||||
$this->correctModule();
|
||||
}
|
||||
|
||||
if (((bool) Tools::isSubmit('submitLeoproductsearchConfig')) == true) {
|
||||
if (!Validate::isUnsignedInt(Tools::getValue('LEOPRODUCTSEARCH_CATEGORY_MAXDEPTH'))) {
|
||||
$this->_html .= $this->displayError($this->l('"Max Depth Of Category" is invalid. Must an integer validity (unsigned).'));
|
||||
} elseif (!Validate::isUnsignedInt(Tools::getValue('LEOPRODUCTSEARCH_NUMPRO_DISPLAY'))) {
|
||||
$this->_html .= $this->displayError($this->l('"Number product display with AJAX Search" is invalid. Must an integer validity (unsigned).'));
|
||||
} else {
|
||||
$form_values = $this->getGroupFieldsValues();
|
||||
|
||||
foreach (array_keys($form_values) as $key) {
|
||||
Configuration::updateValue($key, Tools::getValue($key));
|
||||
}
|
||||
|
||||
$this->_html = $this->displayConfirmation($this->trans('Successful update.', array(), 'Admin.Notifications.Success'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getContent()
|
||||
{
|
||||
$this->errors = array();
|
||||
if (!$this->access('configure')) {
|
||||
$this->errors[] = $this->trans('You do not have permission to configure this.', array(), 'Admin.Notifications.Error');
|
||||
// $this->context->smarty->assign('errors', $this->errors);
|
||||
$this->_html .= $this->displayError($this->trans('You do not have permission to configure this.', array(), 'Admin.Notifications.Error'));
|
||||
}
|
||||
|
||||
$this->postProcess();
|
||||
|
||||
$this->_html .= $this->renderGroupConfig();
|
||||
|
||||
return $this->_html;
|
||||
}
|
||||
|
||||
public function renderGroupConfig()
|
||||
{
|
||||
$fields_form = array();
|
||||
$fields_form[0]['form'] = array(
|
||||
'input' => array(
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Enable Leo Product Search'),
|
||||
'name' => 'LEOPRODUCTSEARCH_ENABLE',
|
||||
'is_bool' => true,
|
||||
'values' => array(
|
||||
array(
|
||||
'id' => 'LEOPRODUCTSEARCH_ENABLE_on',
|
||||
'value' => true,
|
||||
'label' => $this->l('Enabled')
|
||||
),
|
||||
array(
|
||||
'id' => 'LEOPRODUCTSEARCH_ENABLE_off',
|
||||
'value' => false,
|
||||
'label' => $this->l('Disabled')
|
||||
)
|
||||
),
|
||||
),
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Enable Ajax Search'),
|
||||
'name' => 'LEOPRODUCTSEARCH_ENABLE_AJAXSEARCH',
|
||||
'is_bool' => true,
|
||||
'values' => array(
|
||||
array(
|
||||
'id' => 'LEOPRODUCTSEARCH_ENABLE_AJAXSEARCH_on',
|
||||
'value' => true,
|
||||
'label' => $this->l('Enabled')
|
||||
),
|
||||
array(
|
||||
'id' => 'LEOPRODUCTSEARCH_ENABLE_AJAXSEARCH_off',
|
||||
'value' => false,
|
||||
'label' => $this->l('Disabled')
|
||||
)
|
||||
),
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Number product display with AJAX Search'),
|
||||
'name' => 'LEOPRODUCTSEARCH_NUMPRO_DISPLAY',
|
||||
'desc' => $this->l('Default is 100'),
|
||||
'lang' => false,
|
||||
),
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Enable Search By Category'),
|
||||
'name' => 'LEOPRODUCTSEARCH_ENABLE_CATEGORY',
|
||||
'is_bool' => true,
|
||||
'values' => array(
|
||||
array(
|
||||
'id' => 'LEOPRODUCTSEARCH_ENABLE_CATEGORY_on',
|
||||
'value' => true,
|
||||
'label' => $this->l('Enabled')
|
||||
),
|
||||
array(
|
||||
'id' => 'LEOPRODUCTSEARCH_ENABLE_CATEGORY_off',
|
||||
'value' => false,
|
||||
'label' => $this->l('Disabled')
|
||||
)
|
||||
),
|
||||
),
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Enable Search suggest'),
|
||||
'name' => 'LEOPRODUCTSEARCH_ENABLE_SUGGEST',
|
||||
'is_bool' => true,
|
||||
'values' => array(
|
||||
array(
|
||||
'id' => 'LEOPRODUCTSEARCH_ENABLE_SUGGEST_on',
|
||||
'value' => true,
|
||||
'label' => $this->l('Enabled')
|
||||
),
|
||||
array(
|
||||
'id' => 'LEOPRODUCTSEARCH_ENABLE_SUGGEST_off',
|
||||
'value' => false,
|
||||
'label' => $this->l('Disabled')
|
||||
)
|
||||
),
|
||||
),
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Enable count products Category'),
|
||||
'name' => 'LEOPRODUCTSEARCH_ENABLE_CATEGORYPRODUCTCOUNT',
|
||||
'is_bool' => true,
|
||||
'values' => array(
|
||||
array(
|
||||
'id' => 'LEOPRODUCTSEARCH_ENABLE_CATEGORYPRODUCTCOUNT_on',
|
||||
'value' => true,
|
||||
'label' => $this->l('Enabled')
|
||||
),
|
||||
array(
|
||||
'id' => 'LEOPRODUCTSEARCH_ENABLE_CATEGORYPRODUCTCOUNT_off',
|
||||
'value' => false,
|
||||
'label' => $this->l('Disabled')
|
||||
)
|
||||
),
|
||||
),
|
||||
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Maximum Depth Of Category'),
|
||||
'name' => 'LEOPRODUCTSEARCH_CATEGORY_MAXDEPTH',
|
||||
'desc' => $this->l('Set the maximum depth of category sublevels displayed in this block (0 = infinite). '),
|
||||
'lang' => false,
|
||||
),
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Show Product Image'),
|
||||
'name' => 'LEOPRODUCTSEARCH_ENABLE_PRODUCTIMG',
|
||||
'is_bool' => true,
|
||||
'values' => array(
|
||||
array(
|
||||
'id' => 'LEOPRODUCTSEARCH_ENABLE_PRODUCTIMG_on',
|
||||
'value' => true,
|
||||
'label' => $this->l('Enabled')
|
||||
),
|
||||
array(
|
||||
'id' => 'LEOPRODUCTSEARCH_ENABLE_PRODUCTIMG_off',
|
||||
'value' => false,
|
||||
'label' => $this->l('Disabled')
|
||||
)
|
||||
),
|
||||
),
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Show Product Price'),
|
||||
'name' => 'LEOPRODUCTSEARCH_ENABLE_PRODUCTPRICE',
|
||||
'is_bool' => true,
|
||||
'values' => array(
|
||||
array(
|
||||
'id' => 'LEOPRODUCTSEARCH_ENABLE_PRODUCTPRICE_on',
|
||||
'value' => true,
|
||||
'label' => $this->l('Enabled')
|
||||
),
|
||||
array(
|
||||
'id' => 'LEOPRODUCTSEARCH_ENABLE_PRODUCTPRICE_off',
|
||||
'value' => false,
|
||||
'label' => $this->l('Disabled')
|
||||
)
|
||||
),
|
||||
),
|
||||
),
|
||||
'submit' => array(
|
||||
'title' => $this->l('Save'),
|
||||
'class' => 'btn btn-default'
|
||||
)
|
||||
);
|
||||
|
||||
$helper = new HelperForm();
|
||||
$helper->show_toolbar = false;
|
||||
$helper->table = $this->table;
|
||||
$helper->module = $this;
|
||||
$helper->name_controller = 'leoproductsearch';
|
||||
$lang = new Language((int) Configuration::get('PS_LANG_DEFAULT'));
|
||||
$helper->default_form_language = $lang->id;
|
||||
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
|
||||
$this->fields_form = array();
|
||||
|
||||
$helper->identifier = $this->identifier;
|
||||
$helper->submit_action = 'submitLeoproductsearchConfig';
|
||||
$helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false) . '&configure=' . $this->name;
|
||||
$helper->token = Tools::getAdminTokenLite('AdminModules');
|
||||
$helper->tpl_vars = array(
|
||||
'fields_value' => $this->getGroupFieldsValues(),
|
||||
'languages' => $this->context->controller->getLanguages(),
|
||||
'id_language' => $this->context->language->id,
|
||||
);
|
||||
|
||||
$globalform = $helper->generateForm($fields_form);
|
||||
|
||||
//DONGND::
|
||||
$this->context->smarty->assign(array(
|
||||
'globalform' => $globalform,
|
||||
'url_admin' => $this->context->link->getAdminLink('AdminModules') . '&configure=' . $this->name,
|
||||
));
|
||||
return $this->context->smarty->fetch($this->local_path . 'views/templates/admin/panel.tpl');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set values for the inputs.
|
||||
*/
|
||||
protected function getGroupFieldsValues()
|
||||
{
|
||||
$list_value = array();
|
||||
$list_value['LEOPRODUCTSEARCH_ENABLE'] = Configuration::get('LEOPRODUCTSEARCH_ENABLE');
|
||||
$list_value['LEOPRODUCTSEARCH_ENABLE_AJAXSEARCH'] = Configuration::get('LEOPRODUCTSEARCH_ENABLE_AJAXSEARCH');
|
||||
$list_value['LEOPRODUCTSEARCH_NUMPRO_DISPLAY'] = Configuration::get('LEOPRODUCTSEARCH_NUMPRO_DISPLAY');
|
||||
$list_value['LEOPRODUCTSEARCH_ENABLE_CATEGORY'] = Configuration::get('LEOPRODUCTSEARCH_ENABLE_CATEGORY');
|
||||
$list_value['LEOPRODUCTSEARCH_ENABLE_SUGGEST'] = Configuration::get('LEOPRODUCTSEARCH_ENABLE_SUGGEST');
|
||||
$list_value['LEOPRODUCTSEARCH_ENABLE_CATEGORYPRODUCTCOUNT'] = Configuration::get('LEOPRODUCTSEARCH_ENABLE_CATEGORYPRODUCTCOUNT');
|
||||
$list_value['LEOPRODUCTSEARCH_CATEGORY_MAXDEPTH'] = Configuration::get('LEOPRODUCTSEARCH_CATEGORY_MAXDEPTH');
|
||||
$list_value['LEOPRODUCTSEARCH_ENABLE_PRODUCTIMG'] = Configuration::get('LEOPRODUCTSEARCH_ENABLE_PRODUCTIMG');
|
||||
$list_value['LEOPRODUCTSEARCH_ENABLE_PRODUCTPRICE'] = Configuration::get('LEOPRODUCTSEARCH_ENABLE_PRODUCTPRICE');
|
||||
|
||||
return $list_value;
|
||||
}
|
||||
|
||||
private function _installDataSample()
|
||||
{
|
||||
if (!file_exists(_PS_MODULE_DIR_ . 'appagebuilder/libs/LeoDataSample.php')) {
|
||||
return false;
|
||||
}
|
||||
require_once(_PS_MODULE_DIR_ . 'appagebuilder/libs/LeoDataSample.php');
|
||||
|
||||
$sample = new Datasample(1);
|
||||
return $sample->processImport($this->name);
|
||||
}
|
||||
|
||||
public function hookdisplayMobileTopSiteMap($params)
|
||||
{
|
||||
$this->smarty->assign(array('hook_mobile' => true, 'instantsearch' => false));
|
||||
$params['hook_mobile'] = true;
|
||||
return $this->hookTop($params);
|
||||
}
|
||||
|
||||
public function hookHeader($params)
|
||||
{
|
||||
if (Configuration::get('LEOPRODUCTSEARCH_ENABLE')) {
|
||||
$media_dir = $this->getMediaDir();
|
||||
$this->context->controller->registerStylesheet('modules-leosearch', $media_dir.'css/leosearch.css', array('media' => 'all', 'priority' => 150));
|
||||
$this->context->controller->registerStylesheet('modules-product_list', _THEME_CSS_DIR_ . 'product_list.css', array('media' => 'all', 'priority' => 150));
|
||||
$this->context->controller->registerJavascript('modules-productsearchjs', $media_dir.'js/jquery.autocomplete_productsearch.js', array('position' => 'bottom', 'priority' => 150));
|
||||
$this->context->controller->registerStylesheet('modules-autocomplete_productsearch', $media_dir.'css/jquery.autocomplete_productsearch.css', array('media' => 'all', 'priority' => 150));
|
||||
Media::addJsDef(array(
|
||||
'leo_search_url' => $this->context->link->getModuleLink('leoproductsearch', 'productsearch', array(), Tools::usingSecureMode()),
|
||||
'ajaxsearch' => Configuration::get('LEOPRODUCTSEARCH_ENABLE_AJAXSEARCH'),
|
||||
'numpro_display' => Configuration::get('LEOPRODUCTSEARCH_NUMPRO_DISPLAY'),
|
||||
'lps_show_product_img' => Configuration::get('LEOPRODUCTSEARCH_ENABLE_PRODUCTIMG'),
|
||||
'lps_show_product_price' => Configuration::get('LEOPRODUCTSEARCH_ENABLE_PRODUCTPRICE'),
|
||||
'leoproductsearch_static_token' => Tools::getToken(false),
|
||||
'leoproductsearch_token' => Tools::getToken(),
|
||||
));
|
||||
$this->context->controller->registerJavascript('modules-leosearchjs', $media_dir.'js/leosearch.js', array('position' => 'bottom', 'priority' => 150));
|
||||
}
|
||||
}
|
||||
|
||||
public function hookLeftColumn($params)
|
||||
{
|
||||
if (Configuration::get('LEOPRODUCTSEARCH_ENABLE')) {
|
||||
if (Tools::getValue('search_query') || !$this->isCached('module:leoproductsearch/views/templates/front/leosearch.tpl', $this->getCacheId())) {
|
||||
$this->calculHookCommon($params);
|
||||
$selectedCateName = '';
|
||||
if (Tools::getValue('cate') && Tools::getValue('cate') != '' && $category_obj = new Category(Tools::getValue('cate'))) {
|
||||
$selectedCateName = $category_obj->name;
|
||||
}
|
||||
$category = new Category((int) Category::getRootCategory()->id, $this->context->language->id);
|
||||
$this->smarty->assign(array(
|
||||
'blocksearch_type' => 'block',
|
||||
'search_query' => (string) Tools::getValue('search_query'),
|
||||
'selectedCate' => (string) Tools::getValue('cate'),
|
||||
'selectedCateName' => $selectedCateName,
|
||||
'cates' => $this->getCategories($category),
|
||||
'en_search_by_cat' => Configuration::get('LEOPRODUCTSEARCH_ENABLE_CATEGORY'),
|
||||
));
|
||||
}
|
||||
Media::addJsDef(array('blocksearch_type' => 'block'));
|
||||
// return $this->display(__FILE__, 'leosearch.tpl', Tools::getValue('search_query') ? null : $this->getCacheId());
|
||||
return $this->fetch('module:leoproductsearch/views/templates/front/leosearch.tpl', Tools::getValue('search_query') ? null : $this->getCacheId());
|
||||
}
|
||||
}
|
||||
|
||||
public function hookTop($params)
|
||||
{
|
||||
if (Configuration::get('LEOPRODUCTSEARCH_ENABLE')) {
|
||||
if (Tools::getValue('search_query') || !$this->isCached('module:leoproductsearch/views/templates/front/leosearch_top.tpl', $this->getCacheId())) {
|
||||
$this->calculHookCommon($params);
|
||||
$selectedCateName = '';
|
||||
if (Tools::getValue('cate') && Tools::getValue('cate') != '' && $category_obj = new Category(Tools::getValue('cate'), $this->context->language->id)) {
|
||||
$selectedCateName = $category_obj->name;
|
||||
}
|
||||
$category = new Category((int) Category::getRootCategory()->id, $this->context->language->id);
|
||||
|
||||
$this->smarty->assign(array(
|
||||
'blocksearch_type' => 'top',
|
||||
'search_query' => (string) Tools::getValue('search_query'),
|
||||
'selectedCate' => (string) Tools::getValue('cate'),
|
||||
'selectedCateName' => $selectedCateName,
|
||||
'cates' => $this->getCategories($category),
|
||||
'en_search_by_cat' => Configuration::get('LEOPRODUCTSEARCH_ENABLE_CATEGORY'),
|
||||
'leoproductsearch_static_token' => Tools::getToken(false),
|
||||
'leoproductsearch_token' => Tools::getToken(),
|
||||
));
|
||||
}
|
||||
// Media::addJsDef(array('blocksearch_type' => 'top'));
|
||||
// return $this->display(__FILE__, 'leosearch_top.tpl', Tools::getValue('search_query') ? null : $this->getCacheId());
|
||||
return $this->fetch('module:leoproductsearch/views/templates/front/leosearch_top.tpl', Tools::getValue('search_query') ? null : $this->getCacheId());
|
||||
}
|
||||
}
|
||||
|
||||
public function hookDisplayNav($params)
|
||||
{
|
||||
return $this->hookTop($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the CSS & JavaScript files you want to be loaded in the BO.
|
||||
*/
|
||||
// public function hookActionAdminControllerSetMedia()
|
||||
// {
|
||||
// $this->autoRestoreSampleData();
|
||||
// }
|
||||
|
||||
private function calculHookCommon($params)
|
||||
{
|
||||
$this->smarty->assign(array(
|
||||
'ENT_QUOTES' => ENT_QUOTES,
|
||||
'search_ssl' => Tools::usingSecureMode(),
|
||||
'ajaxsearch' => Configuration::get('LEOPRODUCTSEARCH_ENABLE_AJAXSEARCH'),
|
||||
'numpro_display' => Configuration::get('LEOPRODUCTSEARCH_NUMPRO_DISPLAY'),
|
||||
// 'ajaxsearch' => 1,
|
||||
'instantsearch' => Configuration::get('PS_INSTANT_SEARCH'),
|
||||
'self' => dirname(__FILE__),
|
||||
));
|
||||
|
||||
unset($params);
|
||||
return true;
|
||||
}
|
||||
|
||||
private function getCategories($category)
|
||||
{
|
||||
$range = '';
|
||||
$maxdepth = Configuration::get('LEOPRODUCTSEARCH_CATEGORY_MAXDEPTH');
|
||||
if (Validate::isLoadedObject($category)) {
|
||||
// if ($maxdepth > 0) {
|
||||
// $maxdepth += $category->level_depth;
|
||||
// }
|
||||
$range = 'AND nleft >= ' . (int) $category->nleft . ' AND nright <= ' . (int) $category->nright;
|
||||
}
|
||||
|
||||
$resultIds = array();
|
||||
$resultParents = array();
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
||||
SELECT c.id_parent, c.id_category, c.level_depth, cl.name, cl.link_rewrite
|
||||
FROM `' . _DB_PREFIX_ . 'category` c
|
||||
INNER JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (c.`id_category` = cl.`id_category` AND cl.`id_lang` = ' . (int) $this->context->language->id . Shop::addSqlRestrictionOnLang('cl') . ')
|
||||
INNER JOIN `' . _DB_PREFIX_ . 'category_shop` cs ON (cs.`id_category` = c.`id_category` AND cs.`id_shop` = ' . (int) $this->context->shop->id . ')
|
||||
WHERE (c.`active` = 1 OR c.`id_category` = ' . (int) Configuration::get('PS_HOME_CATEGORY') . ')
|
||||
AND c.`id_category` != ' . (int) Configuration::get('PS_ROOT_CATEGORY') . '
|
||||
' . ((int) $maxdepth != 0 ? ' AND `level_depth` <= ' . (int) $maxdepth : '') . '
|
||||
' . $range . '
|
||||
AND c.id_category IN (
|
||||
SELECT id_category
|
||||
FROM `' . _DB_PREFIX_ . 'category_group`
|
||||
WHERE `id_group` IN (' . pSQL(implode(', ', Customer::getGroupsStatic((int) $this->context->customer->id))) . ')
|
||||
)
|
||||
ORDER BY `level_depth` ASC, ' . (Configuration::get('BLOCK_CATEG_SORT') ? 'cl.`name`' : 'cs.`position`') . ' ' . (Configuration::get('BLOCK_CATEG_SORT_WAY') ? 'DESC' : 'ASC'));
|
||||
foreach ($result as &$row) {
|
||||
$resultParents[$row['id_parent']][] = &$row;
|
||||
$resultIds[$row['id_category']] = &$row;
|
||||
}
|
||||
|
||||
return $this->getTree($resultParents, $resultIds, $maxdepth, ($category ? $category->id : null));
|
||||
}
|
||||
|
||||
public function getTree($resultParents, $resultIds, $maxDepth, $id_category = null, $currentDepth = 0)
|
||||
{
|
||||
if (is_null($id_category)) {
|
||||
$id_category = $this->context->shop->getCategory();
|
||||
}
|
||||
|
||||
$children = array();
|
||||
|
||||
if (isset($resultParents[$id_category]) && count($resultParents[$id_category]) && ($maxDepth == 0 || $currentDepth < $maxDepth)) {
|
||||
foreach ($resultParents[$id_category] as $subcat) {
|
||||
$children[] = $this->getTree($resultParents, $resultIds, $maxDepth, $subcat['id_category'], $currentDepth + 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($resultIds[$id_category])) {
|
||||
$link = $this->context->link->getCategoryLink($id_category, $resultIds[$id_category]['link_rewrite']);
|
||||
$name = $resultIds[$id_category]['name'];
|
||||
// $desc = $resultIds[$id_category]['description'];
|
||||
$level_depth = $resultIds[$id_category]['level_depth'];
|
||||
} else {
|
||||
// $link = $name = $desc = '';
|
||||
$link = $name = '';
|
||||
}
|
||||
|
||||
return array(
|
||||
'id_category' => $id_category,
|
||||
'level_depth' => $level_depth,
|
||||
'link' => $link,
|
||||
'name' => $name,
|
||||
// 'desc'=> $desc,
|
||||
'children' => $children
|
||||
);
|
||||
}
|
||||
|
||||
public function correctModule()
|
||||
{
|
||||
if (!Configuration::hasKey('LEOPRODUCTSEARCH_ENABLE_AJAXSEARCH')) {
|
||||
Configuration::updateValue('LEOPRODUCTSEARCH_ENABLE_AJAXSEARCH', 1);
|
||||
}
|
||||
if (!Configuration::hasKey('LEOPRODUCTSEARCH_NUMPRO_DISPLAY')) {
|
||||
Configuration::updateValue('LEOPRODUCTSEARCH_NUMPRO_DISPLAY', 100);
|
||||
}
|
||||
if (Tools::getValue('success')) {
|
||||
switch (Tools::getValue('success')) {
|
||||
case 'correct':
|
||||
$this->_html .= $this->displayConfirmation($this->l('Correct Module is successful'));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// public function isCached($template, $cache_id = null, $compile_id = null)
|
||||
// {
|
||||
// if (version_compare(_PS_VERSION_, '1.7.4.0', '>=') || version_compare(Configuration::get('PS_VERSION_DB'), '1.7.4.0', '>=')) {
|
||||
// return false;
|
||||
// }
|
||||
// return parent::isCached($template, $cache_id, $compile_id);
|
||||
// }
|
||||
|
||||
/**
|
||||
* FIX BUG 1.7.3.3 : install theme lose hook displayHome, displayLeoProfileProduct
|
||||
* because ajax not run hookActionAdminBefore();
|
||||
*/
|
||||
// public function autoRestoreSampleData()
|
||||
// {
|
||||
// if (Hook::isModuleRegisteredOnHook($this, 'actionAdminBefore', (int)Context::getContext()->shop->id)) {
|
||||
// $theme_manager = new stdclass();
|
||||
// $theme_manager->theme_manager = 'theme_manager';
|
||||
// $this->hookActionAdminBefore(array(
|
||||
// 'controller' => $theme_manager,
|
||||
// ));
|
||||
// }
|
||||
// }
|
||||
|
||||
//DONGND:: update direction css, js, img for 1.7.4.0
|
||||
public function getMediaDir()
|
||||
{
|
||||
$media_dir = '';
|
||||
if (version_compare(_PS_VERSION_, '1.7.4.0', '>=') || version_compare(Configuration::get('PS_VERSION_DB'), '1.7.4.0', '>=')) {
|
||||
$media_dir = 'modules/'.$this->name.'/views/';
|
||||
} else {
|
||||
$media_dir = 'modules/'.$this->name.'/';
|
||||
}
|
||||
return $media_dir;
|
||||
}
|
||||
|
||||
/**
|
||||
* PERMISSION ACCOUNT demo@demo.com
|
||||
*/
|
||||
public function getPermission($variable, $employee = null)
|
||||
{
|
||||
if ($variable == 'configure') {
|
||||
// Allow see form if permission is : configure, view
|
||||
$configure = Module::getPermissionStatic($this->id, 'configure', $employee);
|
||||
$view = Module::getPermissionStatic($this->id, 'view', $employee);
|
||||
return ($configure || $view);
|
||||
}
|
||||
|
||||
return Module::getPermissionStatic($this->id, $variable, $employee);
|
||||
}
|
||||
|
||||
/**
|
||||
* PERMISSION ACCOUNT demo@demo.com
|
||||
*/
|
||||
public function access($action)
|
||||
{
|
||||
$employee = null;
|
||||
return Module::getPermissionStatic($this->id, $action, $employee);
|
||||
}
|
||||
}
|
||||
BIN
modules/leoproductsearch/logo.gif
Normal file
BIN
modules/leoproductsearch/logo.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 615 B |
BIN
modules/leoproductsearch/logo.png
Normal file
BIN
modules/leoproductsearch/logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.8 KiB |
21
modules/leoproductsearch/translations/ar.php
Normal file
21
modules/leoproductsearch/translations/ar.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
global $_MODULE;
|
||||
$_MODULE = array();
|
||||
$_MODULE['<{leoproductsearch}prestashop>leoproductsearch_78f9aa1218f71a20d84b4d719030f44f'] = 'بحث سريع المنتج من قبل فئة كتلة';
|
||||
$_MODULE['<{leoproductsearch}prestashop>leoproductsearch_da80ebe916ef5d16126e76660d38b193'] = 'يضيف حقل البحث المنتجات سريعة إلى موقع الويب الخاص بك.';
|
||||
$_MODULE['<{leoproductsearch}prestashop>leosearch_13348442cc6a27032d2b4aa28b75a5d3'] = 'بحث';
|
||||
$_MODULE['<{leoproductsearch}prestashop>leosearch_b9af8635591dc44009ccd8e5389722ec'] = 'لم يتم العثور على منتج';
|
||||
$_MODULE['<{leoproductsearch}prestashop>leosearch_ce1b00a24b52e74de46971b174d2aaa6'] = 'البحث عن المنتجات:';
|
||||
$_MODULE['<{leoproductsearch}prestashop>leosearch_a6a2a55bea8760389dfca77132905b7c'] = 'جميع الفئات';
|
||||
$_MODULE['<{leoproductsearch}prestashop>leosearch_top_13348442cc6a27032d2b4aa28b75a5d3'] = 'بحث';
|
||||
$_MODULE['<{leoproductsearch}prestashop>leosearch_top_b9af8635591dc44009ccd8e5389722ec'] = 'لم يتم العثور على منتج';
|
||||
$_MODULE['<{leoproductsearch}prestashop>leosearch_top_ce1b00a24b52e74de46971b174d2aaa6'] = 'البحث عن المنتجات:';
|
||||
$_MODULE['<{leoproductsearch}prestashop>leosearch_top_a6a2a55bea8760389dfca77132905b7c'] = 'جميع الفئات';
|
||||
$_MODULE['<{leoproductsearch}prestashop>productsearch_13348442cc6a27032d2b4aa28b75a5d3'] = 'بحث';
|
||||
$_MODULE['<{leoproductsearch}prestashop>search_13348442cc6a27032d2b4aa28b75a5d3'] = 'بحث';
|
||||
$_MODULE['<{leoproductsearch}prestashop>search_05cf990f79d935b0ea6105855adef686'] = 'العودة إلى الصفحة السابقة';
|
||||
$_MODULE['<{leoproductsearch}prestashop>search_3a93aed43691aed28d2ce3a53d3c63f8'] = '%d تم العثور على نتيجة.';
|
||||
$_MODULE['<{leoproductsearch}prestashop>search_a09e4037d02313230a191007246e1694'] = '%d تم العثور على نتيجة.';
|
||||
$_MODULE['<{leoproductsearch}prestashop>search_b2c56c8b57680e576c61c1b5df0d0c2d'] = 'لم يتم العثور على نتائج لبحثك';
|
||||
$_MODULE['<{leoproductsearch}prestashop>search_a4bb6bf91165c149d73930f43ad4ef69'] = 'الرجاء إدخال كلمة البحث';
|
||||
21
modules/leoproductsearch/translations/de.php
Normal file
21
modules/leoproductsearch/translations/de.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
global $_MODULE;
|
||||
$_MODULE = array();
|
||||
$_MODULE['<{leoproductsearch}prestashop>leoproductsearch_78f9aa1218f71a20d84b4d719030f44f'] = 'Schnelle Produktsuche nach Kategorienblock';
|
||||
$_MODULE['<{leoproductsearch}prestashop>leoproductsearch_da80ebe916ef5d16126e76660d38b193'] = 'Fügt ein schnelles Produktsuchfeld zu Ihrer Website hinzu.';
|
||||
$_MODULE['<{leoproductsearch}prestashop>leosearch_13348442cc6a27032d2b4aa28b75a5d3'] = 'Suche';
|
||||
$_MODULE['<{leoproductsearch}prestashop>leosearch_b9af8635591dc44009ccd8e5389722ec'] = 'Es wurde kein Produkt gefunden';
|
||||
$_MODULE['<{leoproductsearch}prestashop>leosearch_ce1b00a24b52e74de46971b174d2aaa6'] = 'Produktsuche:';
|
||||
$_MODULE['<{leoproductsearch}prestashop>leosearch_a6a2a55bea8760389dfca77132905b7c'] = 'Alle Kategorien';
|
||||
$_MODULE['<{leoproductsearch}prestashop>leosearch_top_13348442cc6a27032d2b4aa28b75a5d3'] = 'Suche';
|
||||
$_MODULE['<{leoproductsearch}prestashop>leosearch_top_b9af8635591dc44009ccd8e5389722ec'] = 'Es wurde kein Produkt gefunden';
|
||||
$_MODULE['<{leoproductsearch}prestashop>leosearch_top_ce1b00a24b52e74de46971b174d2aaa6'] = 'Produktsuche:';
|
||||
$_MODULE['<{leoproductsearch}prestashop>leosearch_top_a6a2a55bea8760389dfca77132905b7c'] = 'Alle Kategorien';
|
||||
$_MODULE['<{leoproductsearch}prestashop>productsearch_13348442cc6a27032d2b4aa28b75a5d3'] = 'Suche';
|
||||
$_MODULE['<{leoproductsearch}prestashop>search_13348442cc6a27032d2b4aa28b75a5d3'] = 'Suche';
|
||||
$_MODULE['<{leoproductsearch}prestashop>search_05cf990f79d935b0ea6105855adef686'] = 'Kehre zur vorherigen Seite zurück';
|
||||
$_MODULE['<{leoproductsearch}prestashop>search_3a93aed43691aed28d2ce3a53d3c63f8'] = '%d ergebnis gefunden.';
|
||||
$_MODULE['<{leoproductsearch}prestashop>search_a09e4037d02313230a191007246e1694'] = '%d ergebnisse gefunden.';
|
||||
$_MODULE['<{leoproductsearch}prestashop>search_b2c56c8b57680e576c61c1b5df0d0c2d'] = 'Es wurden keine Resultate für Ihre Suche gefunden';
|
||||
$_MODULE['<{leoproductsearch}prestashop>search_a4bb6bf91165c149d73930f43ad4ef69'] = 'Bitte geben Sie einen Suchbegriff ein';
|
||||
22
modules/leoproductsearch/translations/en.php
Normal file
22
modules/leoproductsearch/translations/en.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
/**
|
||||
* Leo Theme for Prestashop 1.6.x
|
||||
*
|
||||
* @author http://www.leotheme.com
|
||||
* @copyright Copyright (C) October 2013 LeoThemes.com <@emai:leotheme@gmail.com>
|
||||
* <info@leotheme.com>.All rights reserved.
|
||||
* @license GNU General Public License version 2
|
||||
*/
|
||||
|
||||
global $_MODULE;
|
||||
$_MODULE = array();
|
||||
|
||||
$_MODULE['<{blocksearch}prestashop>blocksearch_e2ca130372651672ba285abd796412ed'] = 'Quick search block';
|
||||
$_MODULE['<{blocksearch}prestashop>blocksearch_be305c865235f417d9b4d22fcdf9f1c5'] = 'Adds a quick search field to your website.';
|
||||
$_MODULE['<{blocksearch}prestashop>blocksearch-top_13348442cc6a27032d2b4aa28b75a5d3'] = 'Search';
|
||||
$_MODULE['<{blocksearch}prestashop>blocksearch_13348442cc6a27032d2b4aa28b75a5d3'] = 'Search';
|
||||
$_MODULE['<{blocksearch}prestashop>blocksearch_ce1b00a24b52e74de46971b174d2aaa6'] = 'Search products:';
|
||||
$_MODULE['<{blocksearch}prestashop>blocksearch_5f075ae3e1f9d0382bb8c4632991f96f'] = 'Go';
|
||||
|
||||
|
||||
return $_MODULE;
|
||||
21
modules/leoproductsearch/translations/es.php
Normal file
21
modules/leoproductsearch/translations/es.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
global $_MODULE;
|
||||
$_MODULE = array();
|
||||
$_MODULE['<{leoproductsearch}prestashop>leoproductsearch_78f9aa1218f71a20d84b4d719030f44f'] = 'Búsqueda rápida de productos por categoría';
|
||||
$_MODULE['<{leoproductsearch}prestashop>leoproductsearch_da80ebe916ef5d16126e76660d38b193'] = 'Añade un campo de búsqueda rápida de productos a su sitio web.';
|
||||
$_MODULE['<{leoproductsearch}prestashop>leosearch_13348442cc6a27032d2b4aa28b75a5d3'] = 'Buscar';
|
||||
$_MODULE['<{leoproductsearch}prestashop>leosearch_b9af8635591dc44009ccd8e5389722ec'] = 'no se encontró producto';
|
||||
$_MODULE['<{leoproductsearch}prestashop>leosearch_ce1b00a24b52e74de46971b174d2aaa6'] = 'Buscar Productos:';
|
||||
$_MODULE['<{leoproductsearch}prestashop>leosearch_a6a2a55bea8760389dfca77132905b7c'] = 'Toda categoría';
|
||||
$_MODULE['<{leoproductsearch}prestashop>leosearch_top_13348442cc6a27032d2b4aa28b75a5d3'] = 'Buscar';
|
||||
$_MODULE['<{leoproductsearch}prestashop>leosearch_top_b9af8635591dc44009ccd8e5389722ec'] = 'no se encontró producto';
|
||||
$_MODULE['<{leoproductsearch}prestashop>leosearch_top_ce1b00a24b52e74de46971b174d2aaa6'] = 'Buscar Productos:';
|
||||
$_MODULE['<{leoproductsearch}prestashop>leosearch_top_a6a2a55bea8760389dfca77132905b7c'] = 'Toda categoría';
|
||||
$_MODULE['<{leoproductsearch}prestashop>productsearch_13348442cc6a27032d2b4aa28b75a5d3'] = 'Buscar';
|
||||
$_MODULE['<{leoproductsearch}prestashop>search_13348442cc6a27032d2b4aa28b75a5d3'] = 'Buscar';
|
||||
$_MODULE['<{leoproductsearch}prestashop>search_05cf990f79d935b0ea6105855adef686'] = 'Regresar a la página anterior';
|
||||
$_MODULE['<{leoproductsearch}prestashop>search_3a93aed43691aed28d2ce3a53d3c63f8'] = '%d resultado.';
|
||||
$_MODULE['<{leoproductsearch}prestashop>search_a09e4037d02313230a191007246e1694'] = '%d se han encontrado resultados.';
|
||||
$_MODULE['<{leoproductsearch}prestashop>search_b2c56c8b57680e576c61c1b5df0d0c2d'] = 'No se encontraron resultados para tu búsqueda';
|
||||
$_MODULE['<{leoproductsearch}prestashop>search_a4bb6bf91165c149d73930f43ad4ef69'] = 'Introduzca una palabra clave de búsqueda';
|
||||
21
modules/leoproductsearch/translations/fr.php
Normal file
21
modules/leoproductsearch/translations/fr.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
global $_MODULE;
|
||||
$_MODULE = array();
|
||||
$_MODULE['<{leoproductsearch}prestashop>leoproductsearch_78f9aa1218f71a20d84b4d719030f44f'] = 'Recherche rapide de produits par bloc de catégorie';
|
||||
$_MODULE['<{leoproductsearch}prestashop>leoproductsearch_da80ebe916ef5d16126e76660d38b193'] = 'Ajoute un champ de recherche rapide de produits à votre site Web.';
|
||||
$_MODULE['<{leoproductsearch}prestashop>productsearch_13348442cc6a27032d2b4aa28b75a5d3'] = 'Chercher';
|
||||
$_MODULE['<{leoproductsearch}prestashop>leosearch_13348442cc6a27032d2b4aa28b75a5d3'] = 'Chercher';
|
||||
$_MODULE['<{leoproductsearch}prestashop>leosearch_b9af8635591dc44009ccd8e5389722ec'] = 'Aucun produit trouvé';
|
||||
$_MODULE['<{leoproductsearch}prestashop>leosearch_ce1b00a24b52e74de46971b174d2aaa6'] = 'Recherche de produits:';
|
||||
$_MODULE['<{leoproductsearch}prestashop>leosearch_a6a2a55bea8760389dfca77132905b7c'] = 'Toutes catégories';
|
||||
$_MODULE['<{leoproductsearch}prestashop>leosearch_top_13348442cc6a27032d2b4aa28b75a5d3'] = 'Chercher';
|
||||
$_MODULE['<{leoproductsearch}prestashop>leosearch_top_b9af8635591dc44009ccd8e5389722ec'] = 'Aucun produit trouvé';
|
||||
$_MODULE['<{leoproductsearch}prestashop>leosearch_top_ce1b00a24b52e74de46971b174d2aaa6'] = 'Recherche de produits:';
|
||||
$_MODULE['<{leoproductsearch}prestashop>leosearch_top_a6a2a55bea8760389dfca77132905b7c'] = 'Toutes catégories';
|
||||
$_MODULE['<{leoproductsearch}prestashop>search_13348442cc6a27032d2b4aa28b75a5d3'] = 'Chercher';
|
||||
$_MODULE['<{leoproductsearch}prestashop>search_05cf990f79d935b0ea6105855adef686'] = 'Retournez à la page précédente';
|
||||
$_MODULE['<{leoproductsearch}prestashop>search_3a93aed43691aed28d2ce3a53d3c63f8'] = '%d résultat a été trouvé.';
|
||||
$_MODULE['<{leoproductsearch}prestashop>search_a09e4037d02313230a191007246e1694'] = '%d résultats ont été trouvés.';
|
||||
$_MODULE['<{leoproductsearch}prestashop>search_b2c56c8b57680e576c61c1b5df0d0c2d'] = 'Aucun résultat n\'a été trouvé pour votre recherche';
|
||||
$_MODULE['<{leoproductsearch}prestashop>search_a4bb6bf91165c149d73930f43ad4ef69'] = 'Veuillez saisir un mot-clé de recherche';
|
||||
35
modules/leoproductsearch/translations/index.php
Normal file
35
modules/leoproductsearch/translations/index.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2014 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/afl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2014 PrestaShop SA
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
||||
21
modules/leoproductsearch/translations/it.php
Normal file
21
modules/leoproductsearch/translations/it.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
global $_MODULE;
|
||||
$_MODULE = array();
|
||||
$_MODULE['<{leoproductsearch}prestashop>leoproductsearch_78f9aa1218f71a20d84b4d719030f44f'] = 'Ricerca rapida di prodotti per categoria blocco';
|
||||
$_MODULE['<{leoproductsearch}prestashop>leoproductsearch_da80ebe916ef5d16126e76660d38b193'] = 'Aggiunge un rapido campo di ricerca prodotto al vostro sito web.';
|
||||
$_MODULE['<{leoproductsearch}prestashop>leosearch_13348442cc6a27032d2b4aa28b75a5d3'] = 'Ricerca';
|
||||
$_MODULE['<{leoproductsearch}prestashop>leosearch_b9af8635591dc44009ccd8e5389722ec'] = 'nessun prodotto trovato';
|
||||
$_MODULE['<{leoproductsearch}prestashop>leosearch_ce1b00a24b52e74de46971b174d2aaa6'] = 'Prodotti della ricerca:';
|
||||
$_MODULE['<{leoproductsearch}prestashop>leosearch_a6a2a55bea8760389dfca77132905b7c'] = 'Tutte le categorie';
|
||||
$_MODULE['<{leoproductsearch}prestashop>leosearch_top_13348442cc6a27032d2b4aa28b75a5d3'] = 'Ricerca';
|
||||
$_MODULE['<{leoproductsearch}prestashop>leosearch_top_b9af8635591dc44009ccd8e5389722ec'] = 'nessun prodotto trovato';
|
||||
$_MODULE['<{leoproductsearch}prestashop>leosearch_top_ce1b00a24b52e74de46971b174d2aaa6'] = 'Prodotti della ricerca:';
|
||||
$_MODULE['<{leoproductsearch}prestashop>leosearch_top_a6a2a55bea8760389dfca77132905b7c'] = 'Tutte le categorie';
|
||||
$_MODULE['<{leoproductsearch}prestashop>productsearch_13348442cc6a27032d2b4aa28b75a5d3'] = 'Ricerca';
|
||||
$_MODULE['<{leoproductsearch}prestashop>search_13348442cc6a27032d2b4aa28b75a5d3'] = 'Ricerca';
|
||||
$_MODULE['<{leoproductsearch}prestashop>search_05cf990f79d935b0ea6105855adef686'] = 'Ritorna alla pagina precedente';
|
||||
$_MODULE['<{leoproductsearch}prestashop>search_3a93aed43691aed28d2ce3a53d3c63f8'] = '%d risultato è stato trovato.';
|
||||
$_MODULE['<{leoproductsearch}prestashop>search_a09e4037d02313230a191007246e1694'] = '%d risultati sono stati trovati.';
|
||||
$_MODULE['<{leoproductsearch}prestashop>search_b2c56c8b57680e576c61c1b5df0d0c2d'] = 'Nessun risultato è stato trovato per la tua ricerca';
|
||||
$_MODULE['<{leoproductsearch}prestashop>search_a4bb6bf91165c149d73930f43ad4ef69'] = 'Si prega di inserire una parola chiave di ricerca';
|
||||
26
modules/leoproductsearch/validate/DataSample.php
Normal file
26
modules/leoproductsearch/validate/DataSample.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2015 Leotheme
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* Quick product search by category block
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* @author leotheme <leotheme@gmail.com>
|
||||
* @copyright 2007-2015 Leotheme
|
||||
* @license http://leotheme.com - prestashop template provider
|
||||
*/
|
||||
|
||||
if (!defined('_CAN_LOAD_FILES_')) {
|
||||
# module validation
|
||||
exit;
|
||||
}
|
||||
|
||||
class Datasample
|
||||
{
|
||||
/**
|
||||
* Validate module
|
||||
*/
|
||||
}
|
||||
36
modules/leoproductsearch/validate/index.php
Normal file
36
modules/leoproductsearch/validate/index.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2012 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/afl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2012 PrestaShop SA
|
||||
* @version Release: $Revision: 13573 $
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
||||
36
modules/leoproductsearch/views/css/index.php
Normal file
36
modules/leoproductsearch/views/css/index.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2014 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/osl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2014 PrestaShop SA
|
||||
* @version Release: $Revision$
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
||||
@@ -0,0 +1,56 @@
|
||||
.ac_results {
|
||||
text-align: left;
|
||||
padding: 0px;
|
||||
border: 1px solid black;
|
||||
background-color: white;
|
||||
overflow: hidden;
|
||||
z-index: 99999;
|
||||
display: none;
|
||||
padding-bottom: 35px;
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
.ac_results ul {
|
||||
width: 100%;
|
||||
list-style-position: outside;
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.ac_results li {
|
||||
margin: 0px;
|
||||
padding: 5px 10px;
|
||||
cursor: default;
|
||||
display: block;
|
||||
/*
|
||||
if width will be 100% horizontal scrollbar will apear
|
||||
when scroll mode will be used
|
||||
*/
|
||||
/*width: 100%;*/
|
||||
font: menu;
|
||||
font-size: 12px;
|
||||
/*
|
||||
it is very important, if line-height not setted or setted
|
||||
in relative units scroll will be broken in firefox
|
||||
*/
|
||||
line-height: 16px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/*
|
||||
.ac_loading {
|
||||
background: white url('indicator.gif') right center no-repeat;
|
||||
}
|
||||
*/
|
||||
|
||||
.ac_odd {
|
||||
background-color: #eee;
|
||||
}
|
||||
|
||||
.ac_over {
|
||||
background-color: #0A246A;
|
||||
color: white;
|
||||
}
|
||||
230
modules/leoproductsearch/views/css/leosearch.css
Normal file
230
modules/leoproductsearch/views/css/leosearch.css
Normal file
@@ -0,0 +1,230 @@
|
||||
/* block top search */
|
||||
#search_block_top {
|
||||
position:absolute;
|
||||
right: 26%;
|
||||
top: 34px;
|
||||
}
|
||||
#search_block_top p {padding:0;}
|
||||
#search_block_top #search_query_top {
|
||||
padding:0 5px;
|
||||
height:23px;
|
||||
width:300px;/* 310 */
|
||||
border:1px solid #666;
|
||||
border-right: 0 !important;
|
||||
color:#666;
|
||||
background:url(img/bg_search_input.png) repeat-x 0 0 #fff;
|
||||
float: left;
|
||||
}
|
||||
|
||||
#search_block_top .button {
|
||||
border:none;
|
||||
border-radius:0;
|
||||
color:#fff;
|
||||
text-transform:uppercase;
|
||||
background:url(img/bg_search_submit.png) repeat-x 0 0 #101010;
|
||||
float: left;
|
||||
height: 25px;
|
||||
}
|
||||
|
||||
form#searchbox{padding-top:5px}
|
||||
form#searchbox label{color:#333;margin-bottom:1px}
|
||||
form#searchbox input#leo_search_query_block{
|
||||
border: 1px solid #CCCCCC;
|
||||
-webkit-border-radius:3px !important;
|
||||
-moz-border-radius:3px !important;
|
||||
border-radius:3px !important;
|
||||
height: 18px;
|
||||
margin-top:10px;
|
||||
}
|
||||
form#searchbox input#search_button{padding: 1px 4px;}
|
||||
|
||||
.list-cate-wrapper
|
||||
{
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.list-cate
|
||||
{
|
||||
width: 100%;
|
||||
padding: 0px;
|
||||
}
|
||||
|
||||
.cate-item
|
||||
{
|
||||
display: block;
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
#leosearchtopbox a.cate-item.active, #leosearchtopbox a.cate-item:hover, #leosearchbox a.cate-item.active, #leosearchbox a.cate-item:hover
|
||||
{
|
||||
background: #2fb5d2;
|
||||
color: #414141;
|
||||
}
|
||||
|
||||
#dropdownListCate, #dropdownListCateTop
|
||||
{
|
||||
cursor: pointer;
|
||||
display: block;
|
||||
padding: 5px 0px 5px 15px;
|
||||
}
|
||||
|
||||
#leosearchtopbox #dropdownListCateTop:hover, #leosearchbox #dropdownListCate:hover
|
||||
{
|
||||
color: #414141;
|
||||
}
|
||||
/*****************molify****************/
|
||||
#leo_search_block_top .block_content{
|
||||
border: 1px solid rgba(0,0,0,.25);
|
||||
}
|
||||
#leosearchtopbox input {
|
||||
background: transparent;
|
||||
border: 1px solid transparent;
|
||||
}
|
||||
#leo_search_top_button{
|
||||
padding: 9px 16px;
|
||||
position: absolute;
|
||||
right: 0;
|
||||
background: #2fb5d2;
|
||||
color: #fff;
|
||||
}
|
||||
#leo_search_top_button .search{
|
||||
color: white;
|
||||
}
|
||||
#leosearchtopbox .list-cate-wrapper{
|
||||
display: inline-block;
|
||||
padding: 0 19px;
|
||||
}
|
||||
#leo_search_block_top {
|
||||
margin-top: 20px;
|
||||
}
|
||||
.ac_results{
|
||||
width: 100%;
|
||||
}
|
||||
.search-in-product ul li > a{
|
||||
float: left;
|
||||
width: 60px;
|
||||
}
|
||||
.search-in-product ul li > div{
|
||||
float: right;
|
||||
width: calc(100% - 60px);
|
||||
}
|
||||
@media (max-width: 1199px){
|
||||
#leosearchtopbox input {
|
||||
width: 60%;
|
||||
}
|
||||
|
||||
#leo_search_block_top .block_content{
|
||||
background: #fff;
|
||||
}
|
||||
}
|
||||
@media (max-width: 575px){
|
||||
#leosearchtopbox .list-cate-wrapper {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
#leo_search_block_top{
|
||||
float: left;
|
||||
width: 100%;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
#leo_search_block_top .title_block{
|
||||
display: none;
|
||||
}
|
||||
|
||||
#leosearchtopbox > label{
|
||||
display: none;
|
||||
}
|
||||
|
||||
#leo_search_block_top .leoproductsearch-result{
|
||||
width: 73%;
|
||||
display: inline-block;
|
||||
margin: 3px 0;
|
||||
border-left: 1px solid rgba(0,0,0,.25);
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.leoproductsearch-loading.cssload-speeding-wheel{
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
text-align: center;
|
||||
position: absolute;
|
||||
top: 4px;
|
||||
right: 4px;
|
||||
display: none;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.ac_results.lps_results> div:first-child{
|
||||
overflow-y: scroll;
|
||||
height: 308px;
|
||||
}
|
||||
#leo_search_block_top .ac_results .search-in-suggest .search-value-title,
|
||||
#leo_search_block_top .ac_results .search-in-cat .search-value-title,
|
||||
#leo_search_block_top .ac_results .search-in-product .search-value-title{
|
||||
color: #000;
|
||||
background: #efefef;
|
||||
padding: 10px 5px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.ac_results li{
|
||||
font-size: 13px;
|
||||
padding: 5px;
|
||||
border-bottom: 1px solid #e5e5e5;
|
||||
transition: all ease .4s;
|
||||
}
|
||||
|
||||
.ac_results li:hover{
|
||||
background: #efefef;
|
||||
}
|
||||
.ac_results li:hover a{
|
||||
color: #fff;
|
||||
}
|
||||
.ac_results li a{
|
||||
display: inline-block;
|
||||
width: 100%;
|
||||
transition: all ease .4s;
|
||||
}
|
||||
#leo_search_block_top .ac_results li:hover .lps-result-title,
|
||||
#leo_search_block_top .ac_results li:hover .lps-result-price{
|
||||
color: #333;
|
||||
}
|
||||
#leo_search_block_top .ac_results .all-search-product{
|
||||
text-align: center;
|
||||
padding: 8px 0;
|
||||
background: #f85f5f;
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
bottom: 0;
|
||||
}
|
||||
#leo_search_block_top .ac_results .all-search-product a{
|
||||
color: #fff;
|
||||
text-transform: capitalize;
|
||||
font-weight: 600;
|
||||
}
|
||||
#leo_search_block_top .ac_results .search-in-product ul li{
|
||||
position: relative;
|
||||
}
|
||||
#leo_search_block_top .ac_results .search-in-product ul li .lps-result-content{
|
||||
position: absolute;
|
||||
left: 60px;
|
||||
}
|
||||
#leo_search_block_top .ac_results .lps-result-content {
|
||||
width: calc(100% - 50px);
|
||||
display: inline-block;
|
||||
padding-left: 7px;
|
||||
}
|
||||
.head-leosearch-product.ac_results{
|
||||
display: block;
|
||||
position: relative;
|
||||
padding: 20px;
|
||||
padding-bottom: 0;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.head-leosearch-product.ac_results > div{
|
||||
padding-bottom: 20px;
|
||||
}
|
||||
.head-leosearch-product.ac_results a{
|
||||
color: #000;
|
||||
}
|
||||
BIN
modules/leoproductsearch/views/img/bg_search_input.png
Normal file
BIN
modules/leoproductsearch/views/img/bg_search_input.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 102 B |
BIN
modules/leoproductsearch/views/img/bg_search_submit.png
Normal file
BIN
modules/leoproductsearch/views/img/bg_search_submit.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 192 B |
35
modules/leoproductsearch/views/img/index.php
Normal file
35
modules/leoproductsearch/views/img/index.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2014 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/afl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2014 PrestaShop SA
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
||||
36
modules/leoproductsearch/views/index.php
Normal file
36
modules/leoproductsearch/views/index.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2014 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/osl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2014 PrestaShop SA
|
||||
* @version Release: $Revision$
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
||||
36
modules/leoproductsearch/views/js/index.php
Normal file
36
modules/leoproductsearch/views/js/index.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2014 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/osl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2014 PrestaShop SA
|
||||
* @version Release: $Revision$
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
||||
@@ -0,0 +1,862 @@
|
||||
/**
|
||||
* @copyright Commercial License By LeoTheme.Com
|
||||
* @email leotheme.com
|
||||
* @visit http://www.leotheme.com
|
||||
*/
|
||||
|
||||
//DONGND:: fix missing $browser jquery 2.x
|
||||
var matched, browser;
|
||||
|
||||
jQuery.uaMatch = function( ua ) {
|
||||
ua = ua.toLowerCase();
|
||||
|
||||
var match = /(chrome)[ \/]([\w.]+)/.exec( ua ) ||
|
||||
/(webkit)[ \/]([\w.]+)/.exec( ua ) ||
|
||||
/(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua ) ||
|
||||
/(msie) ([\w.]+)/.exec( ua ) ||
|
||||
ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( ua ) ||
|
||||
[];
|
||||
|
||||
return {
|
||||
browser: match[ 1 ] || "",
|
||||
version: match[ 2 ] || "0"
|
||||
};
|
||||
};
|
||||
|
||||
matched = jQuery.uaMatch( navigator.userAgent );
|
||||
browser = {};
|
||||
|
||||
if ( matched.browser ) {
|
||||
browser[ matched.browser ] = true;
|
||||
browser.version = matched.version;
|
||||
}
|
||||
|
||||
// Chrome is Webkit, but Webkit is also Safari.
|
||||
if ( browser.chrome ) {
|
||||
browser.webkit = true;
|
||||
} else if ( browser.webkit ) {
|
||||
browser.safari = true;
|
||||
}
|
||||
|
||||
jQuery.browser = browser;
|
||||
|
||||
;(function($) {
|
||||
|
||||
$.fn.extend({
|
||||
autocomplete: function(urlOrData, options) {
|
||||
var isUrl = typeof urlOrData == "string";
|
||||
options = $.extend({}, $.Autocompleter.defaults, {
|
||||
url: isUrl ? urlOrData : null,
|
||||
data: isUrl ? null : urlOrData,
|
||||
delay: isUrl ? $.Autocompleter.defaults.delay : 10,
|
||||
max: options && !options.scroll ? 10 : 150
|
||||
}, options);
|
||||
|
||||
// if highlight is set to false, replace it with a do-nothing function
|
||||
options.highlight = options.highlight || function(value) { return value; };
|
||||
|
||||
// if the formatMatch option is not specified, then use formatItem for backwards compatibility
|
||||
options.formatMatch = options.formatMatch || options.formatItem;
|
||||
|
||||
return this.each(function() {
|
||||
new $.Autocompleter(this, options);
|
||||
});
|
||||
},
|
||||
result: function(handler) {
|
||||
return this.bind("result", handler);
|
||||
},
|
||||
search: function(handler) {
|
||||
return this.trigger("search", [handler]);
|
||||
},
|
||||
flushCache: function() {
|
||||
return this.trigger("flushCache");
|
||||
},
|
||||
setOptions: function(options){
|
||||
return this.trigger("setOptions", [options]);
|
||||
},
|
||||
unautocomplete: function() {
|
||||
return this.trigger("unautocomplete");
|
||||
}
|
||||
});
|
||||
|
||||
$.Autocompleter = function(input, options) {
|
||||
|
||||
var KEY = {
|
||||
UP: 38,
|
||||
DOWN: 40,
|
||||
DEL: 46,
|
||||
TAB: 9,
|
||||
RETURN: 13,
|
||||
ESC: 27,
|
||||
COMMA: 188,
|
||||
PAGEUP: 33,
|
||||
PAGEDOWN: 34,
|
||||
BACKSPACE: 8
|
||||
};
|
||||
|
||||
// Create $ object for input element
|
||||
var $input = $(input).attr("autocomplete", "off").addClass(options.inputClass);
|
||||
//DONGND:: add loading
|
||||
var $loading = $input.parent().find('.leoproductsearch-loading');
|
||||
var timeout;
|
||||
var previousValue = "";
|
||||
var cache = $.Autocompleter.Cache(options);
|
||||
var hasFocus = 0;
|
||||
var lastKeyPressCode;
|
||||
var config = {
|
||||
mouseDownOnSelect: false
|
||||
};
|
||||
var select = $.Autocompleter.Select(options, input, selectCurrent, config);
|
||||
|
||||
var blockSubmit;
|
||||
|
||||
// prevent form submit in opera when selecting with return key
|
||||
$.browser.opera && $(input.form).bind("submit.autocomplete", function() {
|
||||
if (blockSubmit) {
|
||||
blockSubmit = false;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
// only opera doesn't trigger keydown multiple times while pressed, others don't work with keypress at all
|
||||
$input.bind(($.browser.opera ? "keypress" : "keydown") + ".autocomplete", function(event) {
|
||||
// track last key pressed
|
||||
lastKeyPressCode = event.keyCode;
|
||||
switch(event.keyCode) {
|
||||
|
||||
case KEY.UP:
|
||||
event.preventDefault();
|
||||
if ( select.visible() ) {
|
||||
select.prev();
|
||||
} else {
|
||||
onChange(0, true);
|
||||
}
|
||||
break;
|
||||
|
||||
case KEY.DOWN:
|
||||
event.preventDefault();
|
||||
if ( select.visible() ) {
|
||||
select.next();
|
||||
} else {
|
||||
onChange(0, true);
|
||||
}
|
||||
break;
|
||||
|
||||
case KEY.PAGEUP:
|
||||
event.preventDefault();
|
||||
if ( select.visible() ) {
|
||||
select.pageUp();
|
||||
} else {
|
||||
onChange(0, true);
|
||||
}
|
||||
break;
|
||||
|
||||
case KEY.PAGEDOWN:
|
||||
event.preventDefault();
|
||||
if ( select.visible() ) {
|
||||
select.pageDown();
|
||||
} else {
|
||||
onChange(0, true);
|
||||
}
|
||||
break;
|
||||
|
||||
// matches also semicolon
|
||||
case options.multiple && $.trim(options.multipleSeparator) == "," && KEY.COMMA:
|
||||
case KEY.TAB:
|
||||
case KEY.RETURN:
|
||||
if( selectCurrent() ) {
|
||||
// stop default to prevent a form submit, Opera needs special handling
|
||||
event.preventDefault();
|
||||
blockSubmit = true;
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
case KEY.ESC:
|
||||
select.hide();
|
||||
break;
|
||||
|
||||
default:
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(onChange, options.delay);
|
||||
break;
|
||||
}
|
||||
}).focus(function(){
|
||||
// track whether the field has focus, we shouldn't process any
|
||||
// results if the field no longer has focus
|
||||
hasFocus++;
|
||||
}).blur(function() {
|
||||
hasFocus = 0;
|
||||
if (!config.mouseDownOnSelect) {
|
||||
hideResults();
|
||||
}
|
||||
}).click(function() {
|
||||
// show select when clicking in a focused field
|
||||
if ( hasFocus++ > 1 && !select.visible() ) {
|
||||
onChange(0, true);
|
||||
}
|
||||
}).bind("search", function() {
|
||||
// TODO why not just specifying both arguments?
|
||||
var fn = (arguments.length > 1) ? arguments[1] : null;
|
||||
function findValueCallback(q, data) {
|
||||
var result;
|
||||
if( data && data.length ) {
|
||||
for (var i=0; i < data.length; i++) {
|
||||
if( data[i].result.toLowerCase() == q.toLowerCase() ) {
|
||||
result = data[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if( typeof fn == "function" ) fn(result);
|
||||
else $input.trigger("result", result && [result.data, result.value]);
|
||||
}
|
||||
$.each(trimWords($input.val()), function(i, value) {
|
||||
request(value, findValueCallback, findValueCallback);
|
||||
});
|
||||
}).bind("flushCache", function() {
|
||||
cache.flush();
|
||||
}).bind("setOptions", function() {
|
||||
$.extend(options, arguments[1]);
|
||||
// if we've updated the data, repopulate
|
||||
if ( "data" in arguments[1] )
|
||||
cache.populate();
|
||||
}).bind("unautocomplete", function() {
|
||||
select.unbind();
|
||||
$input.unbind();
|
||||
$(input.form).unbind(".autocomplete");
|
||||
});
|
||||
|
||||
|
||||
function selectCurrent() {
|
||||
var selected = select.selected();
|
||||
if( !selected )
|
||||
return false;
|
||||
|
||||
var v = selected.result;
|
||||
previousValue = v;
|
||||
|
||||
if ( options.multiple ) {
|
||||
var words = trimWords($input.val());
|
||||
if ( words.length > 1 ) {
|
||||
v = words.slice(0, words.length - 1).join( options.multipleSeparator ) + options.multipleSeparator + v;
|
||||
}
|
||||
v += options.multipleSeparator;
|
||||
}
|
||||
|
||||
$input.val(v);
|
||||
hideResultsNow();
|
||||
$input.trigger("result", [selected.data, selected.value]);
|
||||
return true;
|
||||
}
|
||||
|
||||
function onChange(crap, skipPrevCheck) {
|
||||
if( lastKeyPressCode == KEY.DEL ) {
|
||||
select.hide();
|
||||
return;
|
||||
}
|
||||
|
||||
var currentValue = $input.val();
|
||||
|
||||
if ( !skipPrevCheck && currentValue == previousValue )
|
||||
return;
|
||||
|
||||
previousValue = currentValue;
|
||||
|
||||
currentValue = lastWord(currentValue);
|
||||
if ( currentValue.length >= options.minChars) {
|
||||
$input.addClass(options.loadingClass);
|
||||
if (!options.matchCase)
|
||||
currentValue = currentValue.toLowerCase();
|
||||
request(currentValue, receiveData, hideResultsNow);
|
||||
} else {
|
||||
stopLoading();
|
||||
select.hide();
|
||||
}
|
||||
};
|
||||
|
||||
function trimWords(value) {
|
||||
if ( !value ) {
|
||||
return [""];
|
||||
}
|
||||
var words = value.split( options.multipleSeparator );
|
||||
var result = [];
|
||||
$.each(words, function(i, value) {
|
||||
if ( $.trim(value) )
|
||||
result[i] = $.trim(value);
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
function lastWord(value) {
|
||||
if ( !options.multiple )
|
||||
return value;
|
||||
var words = trimWords(value);
|
||||
return words[words.length - 1];
|
||||
}
|
||||
|
||||
// fills in the input box w/the first match (assumed to be the best match)
|
||||
// q: the term entered
|
||||
// sValue: the first matching result
|
||||
function autoFill(q, sValue){
|
||||
// autofill in the complete box w/the first match as long as the user hasn't entered in more data
|
||||
// if the last user key pressed was backspace, don't autofill
|
||||
if( options.autoFill && (lastWord($input.val()).toLowerCase() == q.toLowerCase()) && lastKeyPressCode != KEY.BACKSPACE ) {
|
||||
// fill in the value (keep the case the user has typed)
|
||||
$input.val($input.val() + sValue.substring(lastWord(previousValue).length));
|
||||
// select the portion of the value not typed by the user (so the next character will erase)
|
||||
$.Autocompleter.Selection(input, previousValue.length, previousValue.length + sValue.length);
|
||||
}
|
||||
};
|
||||
|
||||
function hideResults() {
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(hideResultsNow, 200);
|
||||
};
|
||||
|
||||
function hideResultsNow() {
|
||||
var wasVisible = select.visible();
|
||||
select.hide();
|
||||
clearTimeout(timeout);
|
||||
stopLoading();
|
||||
if (options.mustMatch) {
|
||||
// call search and run callback
|
||||
$input.search(
|
||||
function (result){
|
||||
// if no value found, clear the input box
|
||||
if( !result ) {
|
||||
if (options.multiple) {
|
||||
var words = trimWords($input.val()).slice(0, -1);
|
||||
$input.val( words.join(options.multipleSeparator) + (words.length ? options.multipleSeparator : "") );
|
||||
}
|
||||
else
|
||||
$input.val( "" );
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
if (wasVisible)
|
||||
// position cursor at end of input field
|
||||
$.Autocompleter.Selection(input, input.value.length, input.value.length);
|
||||
};
|
||||
|
||||
function receiveData(q, data) {
|
||||
if ( data && data.length && hasFocus ) {
|
||||
stopLoading();
|
||||
select.display(data, q);
|
||||
autoFill(q, data[0].value);
|
||||
select.show();
|
||||
} else {
|
||||
hideResultsNow();
|
||||
}
|
||||
};
|
||||
|
||||
function request(term, success, failure) {
|
||||
//DONGND:: show loading
|
||||
$loading.show();
|
||||
//$(".leoproductsearch-result .ac_results").hide();
|
||||
if (!options.matchCase)
|
||||
term = term.toLowerCase();
|
||||
var data = cache.load(term);
|
||||
// recieve the cached data
|
||||
if (data && data.length) {
|
||||
success(term, data);
|
||||
// if an AJAX url has been supplied, try loading the data now
|
||||
} else if( (typeof options.url == "string") && (options.url.length > 0) ){
|
||||
|
||||
var extraParams = {
|
||||
timestamp: +new Date()
|
||||
};
|
||||
$.each(options.extraParams, function(key, param) {
|
||||
extraParams[key] = typeof param == "function" ? param() : param;
|
||||
});
|
||||
|
||||
$.ajax({
|
||||
// try to leverage ajaxQueue plugin to abort previous requests
|
||||
mode: "abort",
|
||||
// limit abortion to this input
|
||||
port: "autocomplete" + input.name,
|
||||
dataType: options.dataType,
|
||||
url: options.url,
|
||||
data: $.extend({
|
||||
cate:$('input[name="cate"]').val(),
|
||||
q: lastWord(term),
|
||||
limit: options.max
|
||||
}, extraParams),
|
||||
success: function(data) {
|
||||
var str = '<div>';
|
||||
|
||||
if(data.suggest.length){
|
||||
str += '<div class="search-in-suggest">';
|
||||
str += '<div class="search-value-title">'+$("#leosearchtopbox").data('label-suggestion')+'</div>';
|
||||
str += '<ul>';
|
||||
for(i=0;i<data.suggest.length;i++){
|
||||
str += '<li><a class="suggest-item" href="'+ data.suggest[i]['word'] +'">' + data.suggest[i]['word'] + '</a></li>';
|
||||
}
|
||||
str += '</ul>';
|
||||
str += '</div>';
|
||||
}
|
||||
if(data.category.length){
|
||||
str += '<div class="search-in-cat">';
|
||||
str += '<div class="search-value-title">'+$("#leosearchtopbox").data('search-for')+' "'+ $("#leo_search_query_top").val() +'"</div>';
|
||||
if(data.category.length){
|
||||
str += '<ul>';
|
||||
for(i=0;i<data.category.length;i++){
|
||||
str += '<li><a href="'+ data.category[i]['link'] +'">'+$("#leosearchtopbox").data('in-category')+': <strong>'+ data.category[i]['name'] +'</strong> ('+ data.category[i]['count'] +' produkty)</a></li>';
|
||||
}
|
||||
str += '</ul>';
|
||||
}
|
||||
// if(data.manufacturer.length){
|
||||
// str += '<ul>';
|
||||
// for(i=0;i<data.manufacturer.length;i++){
|
||||
// str += '<li><a href="'+ data.manufacturer[i]['link'] +'">in Manufacturer: <strong>'+ data.manufacturer[i]['name'] +'</strong> ('+ data.manufacturer[i]['count'] +' results)</a></li>';
|
||||
// }
|
||||
// str += '</ul>';
|
||||
// }
|
||||
str += '</div>';
|
||||
}
|
||||
|
||||
if(data.products.length){
|
||||
str += '<div class="search-in-product">';
|
||||
str += '<div class="search-value-title">'+$("#leosearchtopbox").data('products-for')+' "'+ $("#leo_search_query_top").val() +'"</div>';
|
||||
str += '<ul>';
|
||||
for(i=0;i<data.products.length;i++){
|
||||
str += '<li><a href="'+ data.products[i]['link'] +'"><div class="lps-result-img"><img class="img-fluid" align = "center" src=' + data.products[i].cover.bySize.small_default.url + '></div>' + '<div class="lps-result-content"><div class="lps-result-title">' + data.products[i].name +'</div>' + '<div class="lps-result-price">' + data.products[i].price +'</div></a></li>';
|
||||
}
|
||||
str += '</ul>';
|
||||
str += '</div>';
|
||||
str += '</div>';
|
||||
str += '<div class="all-search-product">';
|
||||
str += '<a href="' + data['link'] + '">'+$("#leosearchtopbox").data('view-all')+' ('+data['total_items']+' '+$("#leosearchtopbox").data('label-products')+')</a>'
|
||||
str += '</div>';
|
||||
}else{
|
||||
str += "<div class='no-products'>Nie mam produktów</div>";
|
||||
str += '</div>';
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
$(".leoproductsearch-result .ac_results").html(str);
|
||||
$(".leoproductsearch-result .ac_results").show();
|
||||
|
||||
$(".suggest-item").click(function(){
|
||||
$("#leo_search_query_top").val($(this).attr('href'));
|
||||
onChange(0, true);
|
||||
return false;
|
||||
});
|
||||
|
||||
// var parsed = options.parse && options.parse(data) || parse(data);
|
||||
// //cache.add(term, $('select#cate').val(), parsed);
|
||||
// success(term, parsed);
|
||||
// //DONGND:: hide loading
|
||||
$loading.hide();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// if we have a failure, we need to empty the list -- this prevents the the [TAB] key from selecting the last successful match
|
||||
select.emptyList();
|
||||
failure(term);
|
||||
}
|
||||
};
|
||||
|
||||
function parse(data) {
|
||||
var parsed = [];
|
||||
var rows = data.split("\n");
|
||||
for (var i=0; i < rows.length; i++) {
|
||||
var row = $.trim(rows[i]);
|
||||
if (row) {
|
||||
row = row.split("|");
|
||||
parsed[parsed.length] = {
|
||||
data: row,
|
||||
value: row[0],
|
||||
result: options.formatResult && options.formatResult(row, row[0]) || row[0]
|
||||
};
|
||||
}
|
||||
}
|
||||
return parsed;
|
||||
};
|
||||
|
||||
function stopLoading() {
|
||||
$input.removeClass(options.loadingClass);
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
$.Autocompleter.defaults = {
|
||||
inputClass: "ac_input",
|
||||
resultsClass: "ac_results lps_results",
|
||||
loadingClass: "ac_loading",
|
||||
minChars: 1,
|
||||
delay: 400,
|
||||
matchCase: false,
|
||||
matchSubset: true,
|
||||
matchContains: false,
|
||||
cacheLength: 10,
|
||||
max: 100,
|
||||
mustMatch: false,
|
||||
extraParams: {},
|
||||
selectFirst: true,
|
||||
formatItem: function(row) { return row[0]; },
|
||||
formatMatch: null,
|
||||
autoFill: false,
|
||||
width: 0,
|
||||
multiple: false,
|
||||
multipleSeparator: ", ",
|
||||
highlight: function(value, term) {
|
||||
return value.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + term.replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi, "\\$1") + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "<strong>$1</strong>");
|
||||
},
|
||||
scroll: true,
|
||||
scrollHeight: 180
|
||||
};
|
||||
|
||||
$.Autocompleter.Cache = function(options) {
|
||||
|
||||
var data = {};
|
||||
var length = 0;
|
||||
|
||||
function matchSubset(s, sub) {
|
||||
if (!options.matchCase)
|
||||
s = s.toLowerCase();
|
||||
var i = s.indexOf(sub);
|
||||
if (i == -1) return false;
|
||||
return i == 0 || options.matchContains;
|
||||
};
|
||||
|
||||
function add(q, cate, value) {
|
||||
if (length > options.cacheLength){
|
||||
flush();
|
||||
}
|
||||
if (!data[q]){
|
||||
length++;
|
||||
}
|
||||
data[q] = value;
|
||||
}
|
||||
|
||||
function populate(){
|
||||
if( !options.data ) return false;
|
||||
// track the matches
|
||||
var stMatchSets = {},
|
||||
nullData = 0;
|
||||
|
||||
// no url was specified, we need to adjust the cache length to make sure it fits the local data store
|
||||
if( !options.url ) options.cacheLength = 1;
|
||||
|
||||
// track all options for minChars = 0
|
||||
stMatchSets[""] = [];
|
||||
|
||||
// loop through the array and create a lookup structure
|
||||
for ( var i = 0, ol = options.data.length; i < ol; i++ ) {
|
||||
var rawValue = options.data[i];
|
||||
// if rawValue is a string, make an array otherwise just reference the array
|
||||
rawValue = (typeof rawValue == "string") ? [rawValue] : rawValue;
|
||||
|
||||
var value = options.formatMatch(rawValue, i+1, options.data.length);
|
||||
if ( value === false )
|
||||
continue;
|
||||
|
||||
var firstChar = value.charAt(0).toLowerCase();
|
||||
// if no lookup array for this character exists, look it up now
|
||||
if( !stMatchSets[firstChar] )
|
||||
stMatchSets[firstChar] = [];
|
||||
|
||||
// if the match is a string
|
||||
var row = {
|
||||
value: value,
|
||||
data: rawValue,
|
||||
result: options.formatResult && options.formatResult(rawValue) || value
|
||||
};
|
||||
|
||||
// push the current match into the set list
|
||||
stMatchSets[firstChar].push(row);
|
||||
|
||||
// keep track of minChars zero items
|
||||
if ( nullData++ < options.max ) {
|
||||
stMatchSets[""].push(row);
|
||||
}
|
||||
};
|
||||
|
||||
// add the data items to the cache
|
||||
$.each(stMatchSets, function(i, value) {
|
||||
// increase the cache size
|
||||
options.cacheLength++;
|
||||
// add to the cache
|
||||
add(i, value);
|
||||
});
|
||||
}
|
||||
|
||||
// populate any existing data
|
||||
setTimeout(populate, 25);
|
||||
|
||||
function flush(){
|
||||
data = {};
|
||||
length = 0;
|
||||
}
|
||||
|
||||
return {
|
||||
flush: flush,
|
||||
add: add,
|
||||
populate: populate,
|
||||
load: function(q) {
|
||||
if (!options.cacheLength || !length)
|
||||
return null;
|
||||
/*
|
||||
* if dealing w/local data and matchContains than we must make sure
|
||||
* to loop through all the data collections looking for matches
|
||||
*/
|
||||
if( !options.url && options.matchContains ){
|
||||
// track all matches
|
||||
var csub = [];
|
||||
// loop through all the data grids for matches
|
||||
for( var k in data ){
|
||||
// don't search through the stMatchSets[""] (minChars: 0) cache
|
||||
// this prevents duplicates
|
||||
if( k.length > 0 ){
|
||||
var c = data[k];
|
||||
$.each(c, function(i, x) {
|
||||
// if we've got a match, add it to the array
|
||||
if (matchSubset(x.value, q)) {
|
||||
csub.push(x);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
return csub;
|
||||
} else
|
||||
// if the exact item exists, use it
|
||||
if (data[q]){
|
||||
return data[q];
|
||||
} else
|
||||
if (options.matchSubset) {
|
||||
for (var i = q.length - 1; i >= options.minChars; i--) {
|
||||
var c = data[q.substr(0, i)];
|
||||
if (c) {
|
||||
var csub = [];
|
||||
$.each(c, function(i, x) {
|
||||
if (matchSubset(x.value, q)) {
|
||||
csub[csub.length] = x;
|
||||
}
|
||||
});
|
||||
return csub;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
$.Autocompleter.Select = function (options, input, select, config) {
|
||||
var CLASSES = {
|
||||
ACTIVE: "ac_over"
|
||||
};
|
||||
|
||||
var listItems,
|
||||
active = -1,
|
||||
data,
|
||||
term = "",
|
||||
needsInit = true,
|
||||
element,
|
||||
list;
|
||||
|
||||
// Create results
|
||||
function init() {
|
||||
if (!needsInit)
|
||||
return;
|
||||
element = $("<div/>")
|
||||
.hide()
|
||||
.addClass(options.resultsClass)
|
||||
.css("position", "absolute")
|
||||
.appendTo('.leoproductsearch-result');
|
||||
// .appendTo(document.body);
|
||||
|
||||
list = $("<div/>").appendTo(element).mouseover( function(event) {
|
||||
if(target(event).nodeName && target(event).nodeName.toUpperCase() == 'LI') {
|
||||
active = $("li", list).removeClass(CLASSES.ACTIVE).index(target(event));
|
||||
$(target(event)).addClass(CLASSES.ACTIVE);
|
||||
}
|
||||
}).click(function(event) {
|
||||
$(target(event)).addClass(CLASSES.ACTIVE);
|
||||
select();
|
||||
// TODO provide option to avoid setting focus again after selection? useful for cleanup-on-focus
|
||||
input.focus();
|
||||
return false;
|
||||
}).mousedown(function() {
|
||||
config.mouseDownOnSelect = true;
|
||||
}).mouseup(function() {
|
||||
config.mouseDownOnSelect = false;
|
||||
});
|
||||
|
||||
if( options.width > 0 )
|
||||
element.css("width", options.width);
|
||||
|
||||
needsInit = false;
|
||||
}
|
||||
|
||||
function target(event) {
|
||||
var element = event.target;
|
||||
while(element && element.tagName != "LI")
|
||||
element = element.parentNode;
|
||||
// more fun with IE, sometimes event.target is empty, just ignore it then
|
||||
if(!element)
|
||||
return [];
|
||||
return element;
|
||||
}
|
||||
|
||||
function moveSelect(step) {
|
||||
listItems.slice(active, active + 1).removeClass(CLASSES.ACTIVE);
|
||||
movePosition(step);
|
||||
var activeItem = listItems.slice(active, active + 1).addClass(CLASSES.ACTIVE);
|
||||
if(options.scroll) {
|
||||
var offset = 0;
|
||||
listItems.slice(0, active).each(function() {
|
||||
offset += this.offsetHeight;
|
||||
});
|
||||
if((offset + activeItem[0].offsetHeight - list.scrollTop()) > list[0].clientHeight) {
|
||||
list.scrollTop(offset + activeItem[0].offsetHeight - list.innerHeight());
|
||||
} else if(offset < list.scrollTop()) {
|
||||
list.scrollTop(offset);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function movePosition(step) {
|
||||
active += step;
|
||||
if (active < 0) {
|
||||
active = listItems.size() - 1;
|
||||
} else if (active >= listItems.size()) {
|
||||
active = 0;
|
||||
}
|
||||
}
|
||||
|
||||
function limitNumberOfItems(available) {
|
||||
return options.max && options.max < available
|
||||
? options.max
|
||||
: available;
|
||||
}
|
||||
|
||||
function fillList() {
|
||||
list.empty();
|
||||
var max = limitNumberOfItems(data.length);
|
||||
for (var i=0; i < max; i++) {
|
||||
if (!data[i])
|
||||
continue;
|
||||
var formatted = options.formatItem(data[i].data, i+1, max, data[i].value, term);
|
||||
if ( formatted === false )
|
||||
continue;
|
||||
var li = $("<li/>").html( options.highlight(formatted, term) ).addClass(i%2 == 0 ? "ac_even" : "ac_odd").appendTo(list)[0];
|
||||
$.data(li, "ac_data", data[i]);
|
||||
}
|
||||
listItems = list.find("li");
|
||||
if ( options.selectFirst ) {
|
||||
listItems.slice(0, 1).addClass(CLASSES.ACTIVE);
|
||||
active = 0;
|
||||
}
|
||||
// apply bgiframe if available
|
||||
if ( $.fn.bgiframe )
|
||||
list.bgiframe();
|
||||
}
|
||||
|
||||
return {
|
||||
display: function(d, q) {
|
||||
init();
|
||||
data = d;
|
||||
term = q;
|
||||
fillList();
|
||||
},
|
||||
next: function() {
|
||||
moveSelect(1);
|
||||
},
|
||||
prev: function() {
|
||||
moveSelect(-1);
|
||||
},
|
||||
pageUp: function() {
|
||||
if (active != 0 && active - 8 < 0) {
|
||||
moveSelect( -active );
|
||||
} else {
|
||||
moveSelect(-8);
|
||||
}
|
||||
},
|
||||
pageDown: function() {
|
||||
if (active != listItems.size() - 1 && active + 8 > listItems.size()) {
|
||||
moveSelect( listItems.size() - 1 - active );
|
||||
} else {
|
||||
moveSelect(8);
|
||||
}
|
||||
},
|
||||
hide: function() {
|
||||
element && element.hide();
|
||||
listItems && listItems.removeClass(CLASSES.ACTIVE);
|
||||
active = -1;
|
||||
},
|
||||
visible : function() {
|
||||
return element && element.is(":visible");
|
||||
},
|
||||
current: function() {
|
||||
return this.visible() && (listItems.filter("." + CLASSES.ACTIVE)[0] || options.selectFirst && listItems[0]);
|
||||
},
|
||||
show: function() {
|
||||
var offset = $(input).offset();
|
||||
// element.css({
|
||||
// width: typeof options.width == "string" || options.width > 0 ? options.width : ($(input).width() + parseInt($(input).css('padding-left')) + parseInt($(input).css('padding-right')) + parseInt($(input).css('margin-left')) + parseInt($(input).css('margin-right'))),
|
||||
// top: offset.top + input.offsetHeight,
|
||||
// left: offset.left
|
||||
// }).show();
|
||||
element.css({
|
||||
width: typeof options.width == "string" || options.width > 0 ? options.width : ($(input).width() + parseInt($(input).css('padding-left')) + parseInt($(input).css('padding-right')) + parseInt($(input).css('margin-left')) + parseInt($(input).css('margin-right'))),
|
||||
top: "100%",
|
||||
left: 0
|
||||
}).show();
|
||||
if(options.scroll) {
|
||||
list.css({
|
||||
maxHeight: options.scrollHeight,
|
||||
overflow: 'auto'
|
||||
});
|
||||
|
||||
if($.browser.msie && typeof document.body.style.maxHeight === "undefined") {
|
||||
var listHeight = 0;
|
||||
listItems.each(function() {
|
||||
listHeight += this.offsetHeight;
|
||||
});
|
||||
var scrollbarsVisible = listHeight > options.scrollHeight;
|
||||
list.css('height', scrollbarsVisible ? options.scrollHeight : listHeight );
|
||||
if (!scrollbarsVisible) {
|
||||
// IE doesn't recalculate width when scrollbar disappears
|
||||
listItems.width( list.width() - parseInt(listItems.css("padding-left")) - parseInt(listItems.css("padding-right")) );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
selected: function() {
|
||||
var selected = listItems && listItems.filter("." + CLASSES.ACTIVE).removeClass(CLASSES.ACTIVE);
|
||||
return selected && selected.length && $.data(selected[0], "ac_data");
|
||||
},
|
||||
emptyList: function (){
|
||||
list && list.empty();
|
||||
},
|
||||
unbind: function() {
|
||||
element && element.remove();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
$.Autocompleter.Selection = function(field, start, end) {
|
||||
if( field.createTextRange ){
|
||||
var selRange = field.createTextRange();
|
||||
selRange.collapse(true);
|
||||
selRange.moveStart("character", start);
|
||||
selRange.moveEnd("character", end);
|
||||
selRange.select();
|
||||
} else if( field.setSelectionRange ){
|
||||
field.setSelectionRange(start, end);
|
||||
} else {
|
||||
if( field.selectionStart ){
|
||||
field.selectionStart = start;
|
||||
field.selectionEnd = end;
|
||||
}
|
||||
}
|
||||
field.focus();
|
||||
};
|
||||
|
||||
})(jQuery);
|
||||
189
modules/leoproductsearch/views/js/leosearch.js
Normal file
189
modules/leoproductsearch/views/js/leosearch.js
Normal file
@@ -0,0 +1,189 @@
|
||||
/**
|
||||
* @copyright Commercial License By LeoTheme.Com
|
||||
* @email leotheme.com
|
||||
* @visit http://www.leotheme.com
|
||||
*/
|
||||
|
||||
var instantSearchQueries = [];
|
||||
|
||||
$(document).click(function(event) {
|
||||
var $target = $(event.target);
|
||||
if(!$target.closest('.leoproductsearch-content').length) {
|
||||
$(".leoproductsearch-result .ac_results").hide();
|
||||
}
|
||||
});
|
||||
|
||||
$(document).ready(function()
|
||||
{
|
||||
$('#leo_search_query_top').click(function(){
|
||||
if ($(this).val().length > 2) {
|
||||
$(".leoproductsearch-result .ac_results").show();
|
||||
}
|
||||
});
|
||||
/* TODO Ids aa blocksearch_type need to be removed*/
|
||||
|
||||
if (typeof ajaxsearch != 'undefined' && ajaxsearch && typeof blocksearch_type !== 'undefined' && blocksearch_type){
|
||||
|
||||
var width_ac_results = $("#leo_search_query_" + blocksearch_type).outerWidth();
|
||||
$("#leo_search_query_" + blocksearch_type).autocomplete(
|
||||
leo_search_url,
|
||||
{
|
||||
minChars: 3,
|
||||
max: numpro_display,
|
||||
width: (width_ac_results > 0 ? width_ac_results : 500),
|
||||
selectFirst: false,
|
||||
scroll: false,
|
||||
dataType: "json",
|
||||
formatItem: function(data, i, max, value, term) {
|
||||
return value;
|
||||
},
|
||||
// parse: function(data) {
|
||||
|
||||
// var result = data.products;
|
||||
// var mytab = new Array();
|
||||
// if (result.length > 0)
|
||||
// {
|
||||
// for (var i = 0; i < result.length; i++)
|
||||
// {
|
||||
// //DONGND:: update config show product img and product price
|
||||
// var lps_html_result = '';
|
||||
// if (typeof lps_show_product_img != 'undefined' && lps_show_product_img && result[i].cover != null)
|
||||
// {
|
||||
// lps_html_result += '<div class="lps-result-img"><img class="img-fluid" align = "center" src=' + result[i].cover.bySize.small_default.url + '></div>';
|
||||
// }
|
||||
// lps_html_result += '<div class="lps-result-content"><div class="lps-result-title">' + result[i].name +'</div>';
|
||||
// if (typeof lps_show_product_price != 'undefined' && lps_show_product_price)
|
||||
// {
|
||||
// lps_html_result += '<div class="lps-result-price">' + result[i].price +'</div>';
|
||||
// }
|
||||
// lps_html_result += '<div>';
|
||||
|
||||
// mytab[mytab.length] = { data: result[i], value: lps_html_result };
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// mytab[0] = {data: { url: window.location.href}, value: '<span class="no-result">'+$('[name="txt_not_found"]').val()+'</span>'};
|
||||
// }
|
||||
|
||||
// return mytab;
|
||||
// },
|
||||
extraParams: {
|
||||
ajaxSearch: 1,
|
||||
id_lang: prestashop.language.id,
|
||||
leoproductsearch_static_token: leoproductsearch_static_token,
|
||||
leoproductsearch_token: leoproductsearch_token
|
||||
}
|
||||
}
|
||||
)
|
||||
.result(function(event, data, formatted) {
|
||||
$('#leo_search_query_' + blocksearch_type).val(data.name);
|
||||
document.location.href = data.url;
|
||||
});
|
||||
|
||||
//DONGND:: update when width of input has been change
|
||||
$("#leo_search_query_" + blocksearch_type).click(function(){
|
||||
width_ac_results = $(this).outerWidth();
|
||||
//DONGND:: update option js libary option when resize
|
||||
$(this).setOptions(
|
||||
{
|
||||
width: width_ac_results
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
$('.cate-item').click(function(){
|
||||
if (!$(this).hasClass('active'))
|
||||
{
|
||||
$('.cate-item.active').removeClass('active');
|
||||
var cate_id = $(this).data('cate-id');
|
||||
var cate_name = $(this).data('cate-name');
|
||||
$('#leosearch-cate-id').val(cate_id);
|
||||
$('#leosearchtop-cate-id').val(cate_id);
|
||||
$('#dropdownListCate span').text(cate_name);
|
||||
$('#dropdownListCateTop span').text(cate_name);
|
||||
$(this).addClass('active');
|
||||
}
|
||||
$('#dropdownListCate').trigger('click');
|
||||
$('#dropdownListCateTop').trigger('click');
|
||||
var e = jQuery.Event("keydown");
|
||||
e.keyCode = 40;
|
||||
$(this).parents('form').find('.search_query').focus().trigger(e);
|
||||
return false;
|
||||
});
|
||||
|
||||
//DONGND:: show result when click to input search
|
||||
$('.search_query').click(function(){
|
||||
if ($(this).val() != '')
|
||||
{
|
||||
// var e = jQuery.Event("keydown");
|
||||
// e.keyCode = 40;
|
||||
// $(this).trigger(e);
|
||||
}
|
||||
});
|
||||
$('.search_query').change(function(){
|
||||
if ($(this).val() != '')
|
||||
{
|
||||
var e = jQuery.Event("keydown");
|
||||
e.keyCode = 40;
|
||||
$(this).trigger(e);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
//DONGND:: update position of result when resize
|
||||
$(window).resize(function(){
|
||||
updatePositionOfResult();
|
||||
});
|
||||
|
||||
//DONGND:: update position of result when scroll
|
||||
//$(window).scroll(function(){
|
||||
// updatePositionOfResult();
|
||||
// if ($('.ac_results').length)
|
||||
// {
|
||||
// $('.ac_results').hide();
|
||||
// }
|
||||
//})
|
||||
|
||||
function updatePositionOfResult()
|
||||
{
|
||||
if ($('.ac_results').length)
|
||||
{
|
||||
width_ac_results = $("#leo_search_query_" + blocksearch_type).outerWidth();
|
||||
//DONGND:: update option js libary option when resize
|
||||
$("#leo_search_query_" + blocksearch_type).setOptions(
|
||||
{
|
||||
width: width_ac_results
|
||||
}
|
||||
);
|
||||
//DONGND:: update position and with of block result when resize
|
||||
//var o_top = $("#leo_search_query_" + blocksearch_type).offset().top;
|
||||
//var o_left = $("#leo_search_query_" + blocksearch_type).offset().left;
|
||||
//var f_height = $("#leo_search_query_" + blocksearch_type).outerHeight();
|
||||
|
||||
$('.ac_results').width(width_ac_results);
|
||||
// $('.ac_results').css({
|
||||
// 'top': o_top+f_height,
|
||||
// 'left' : o_left,
|
||||
// })
|
||||
}
|
||||
}
|
||||
|
||||
function tryToCloseInstantSearch()
|
||||
{
|
||||
if ($('#old_center_column').length > 0)
|
||||
{
|
||||
$('#center_column').remove();
|
||||
$('#old_center_column').attr('id', 'center_column');
|
||||
$('#center_column').show();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function stopInstantSearchQueries()
|
||||
{
|
||||
for(i=0;i<instantSearchQueries.length;i++)
|
||||
instantSearchQueries[i].abort();
|
||||
instantSearchQueries = new Array();
|
||||
}
|
||||
36
modules/leoproductsearch/views/templates/admin/index.php
Normal file
36
modules/leoproductsearch/views/templates/admin/index.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2014 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/osl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2014 PrestaShop SA
|
||||
* @version Release: $Revision$
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
||||
29
modules/leoproductsearch/views/templates/admin/panel.tpl
Normal file
29
modules/leoproductsearch/views/templates/admin/panel.tpl
Normal file
@@ -0,0 +1,29 @@
|
||||
{*
|
||||
* @Module Name: Leo Product Search
|
||||
* @Website: leotheme.com.com - prestashop template provider
|
||||
* @author Leotheme <leotheme@gmail.com>
|
||||
* @copyright Leotheme
|
||||
*}
|
||||
|
||||
<div class="panel form-horizontal">
|
||||
<div class="form-group">
|
||||
<div class="col-lg-1">
|
||||
<a class="megamenu-correct-module btn btn-success" href="{$url_admin}&success=correct&correctmodule=1">
|
||||
<i class="icon-AdminParentPreferences"></i>{l s='Correct module' mod='leoproductsearch'}
|
||||
</a>
|
||||
</div>
|
||||
<div class="control-label col-lg-11" style="text-align: left">* {l s='Make module work well with current Prestashop Version (fix database and old bug of module).' mod='leoproductsearch'}</div>
|
||||
<div class="control-label col-lg-11" style="text-align: left">* {l s='Please backup the database before run correct module to safe' mod='leoproductsearch'}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="leoproductsearch-group">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading"><i class="icon-cogs"></i> {l s='Leo Product Search Global Config' mod='leoproductsearch'}</div>
|
||||
<div class="panel-content" id="leoquicklogin-setting">
|
||||
<div class="tab-content">
|
||||
{$globalform}{* HTML form , no escape necessary *}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
36
modules/leoproductsearch/views/templates/front/index.php
Normal file
36
modules/leoproductsearch/views/templates/front/index.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2014 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/osl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2014 PrestaShop SA
|
||||
* @version Release: $Revision$
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
||||
53
modules/leoproductsearch/views/templates/front/leosearch.tpl
Normal file
53
modules/leoproductsearch/views/templates/front/leosearch.tpl
Normal file
@@ -0,0 +1,53 @@
|
||||
{*
|
||||
* @Module Name: Leo Product Search
|
||||
* @Website: leotheme.com.com - prestashop template provider
|
||||
* @author Leotheme <leotheme@gmail.com>
|
||||
* @copyright Leotheme
|
||||
*}
|
||||
|
||||
{function name="lps_categories" nodes=[] depth=0}
|
||||
{strip}
|
||||
{if $nodes|count}
|
||||
{foreach from=$nodes item=node}
|
||||
<a href="#" data-cate-id="{$node.id_category|escape:'htmlall':'UTF-8'|stripslashes}" data-cate-name="{$node.name}" class="cate-item cate-level-{$node.level_depth}{if isset($selectedCate) && $node.id_category eq $selectedCate} active{/if}" >{if $node.level_depth > 1}{str_repeat('-', $node.level_depth)}{/if}{$node.name}</a>
|
||||
{lps_categories nodes=$node.children depth=$depth+1}
|
||||
{/foreach}
|
||||
{/if}
|
||||
{/strip}
|
||||
{/function}
|
||||
|
||||
<!-- Block search module -->
|
||||
<div id="leo_search_block_left" class="block exclusive{if $en_search_by_cat} search-by-category{/if}">
|
||||
<h4 class="title_block">{l s='Search' mod='leoproductsearch'}</h4>
|
||||
<form method="get" action="{$link->getPageLink('productsearch', true)|escape:'html':'UTF-8'}" id="leosearchbox">
|
||||
<input type="hidden" name="fc" value="module" />
|
||||
<input type="hidden" name="module" value="leoproductsearch" />
|
||||
<input type="hidden" name="controller" value="productsearch" />
|
||||
<input type="hidden" name="txt_not_found" value="{l s='No products found' mod='leoproductsearch'}">
|
||||
<input type="hidden" name="orderby" value="position" />
|
||||
<input type="hidden" name="orderway" value="desc" />
|
||||
|
||||
<label for="search_query_block">{l s='Search products:' mod='leoproductsearch'}</label>
|
||||
<div class="block_content clearfix">
|
||||
{if $en_search_by_cat}
|
||||
<div class="list-cate-wrapper">
|
||||
<input id="leosearch-cate-id" name="cate" value="{if isset($selectedCate)}{$selectedCate}{/if}" type="hidden">
|
||||
<a id="dropdownListCate" class="select-title" rel="nofollow" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
<span>{if $selectedCateName != ''}{$selectedCateName}{else}{l s='All Categories' mod='leoproductsearch'}{/if}</span>
|
||||
<i class="material-icons pull-xs-right">keyboard_arrow_down</i>
|
||||
</a>
|
||||
<div class="list-cate dropdown-menu" aria-labelledby="dropdownListCate">
|
||||
<a href="#" data-cate-id="" data-cate-name="{l s='All Categories' mod='leoproductsearch'}" class="cate-item{if $selectedCate == ''} active{/if}" >{l s='All Categories' mod='leoproductsearch'}</a>
|
||||
<a href="#" data-cate-id="{$cates.id_category|escape:'htmlall':'UTF-8'|stripslashes}" data-cate-name="{$cates.name}" class="cate-item cate-level-{$cates.level_depth}{if isset($selectedCate) && $cates.id_category eq $selectedCate} active{/if}" >{if $cates.level_depth > 1}{str_repeat('-', $cates.level_depth)}{/if}{$cates.name}</a>
|
||||
{lps_categories nodes=$cates.children}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
<div class="leoproductsearch-loading cssload-speeding-wheel">
|
||||
</div>
|
||||
<input class="search_query form-control grey" type="text" id="leo_search_query_block" name="search_query" value="{$search_query|escape:'htmlall':'UTF-8'|stripslashes}" />
|
||||
<button type="submit" id="leo_search_button" class="btn btn-default button button-small"><span><i class="material-icons search">search</i></span></button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<!-- /Block search module -->
|
||||
@@ -0,0 +1,60 @@
|
||||
{*
|
||||
* @Module Name: Leo Product Search
|
||||
* @Website: leotheme.com.com - prestashop template provider
|
||||
* @author Leotheme <leotheme@gmail.com>
|
||||
* @copyright Leotheme
|
||||
*}
|
||||
|
||||
{function name="lps_categories" nodes=[] depth=0}
|
||||
{strip}
|
||||
{if $nodes|count}
|
||||
{foreach from=$nodes item=node}
|
||||
<a href="#" data-cate-id="{$node.id_category|escape:'htmlall':'UTF-8'|stripslashes}" data-cate-name="{$node.name}" class="cate-item cate-level-{$node.level_depth}{if isset($selectedCate) && $node.id_category eq $selectedCate} active{/if}" >{if $node.level_depth > 1}{str_repeat('-', $node.level_depth)}{/if}{$node.name}</a>
|
||||
{lps_categories nodes=$node.children depth=$depth+1}
|
||||
{/foreach}
|
||||
{/if}
|
||||
{/strip}
|
||||
{/function}
|
||||
|
||||
<!-- Block search module -->
|
||||
<div id="leo_search_block_top" class="block exclusive{if $en_search_by_cat} search-by-category{/if}">
|
||||
<h4 class="title_block">{l s='Search' mod='leoproductsearch'}</h4>
|
||||
<form method="get" action="{$link->getPageLink('productsearch', true)|escape:'html':'UTF-8'}" id="leosearchtopbox" data-label-suggestion="{l s='Suggestion' mod='leoproductsearch'}" data-search-for="{l s='Search for' mod='leoproductsearch'}" data-in-category="{l s='in category' mod='leoproductsearch'}" data-products-for="{l s='Products For' mod='leoproductsearch'}" data-label-products="{l s='Products' mod='leoproductsearch'}" data-view-all="{l s='View all' mod='leoproductsearch'}">
|
||||
<input type="hidden" name="fc" value="module" />
|
||||
<input type="hidden" name="module" value="leoproductsearch" />
|
||||
<input type="hidden" name="controller" value="productsearch" />
|
||||
<input type="hidden" name="txt_not_found" value="{l s='No products found' mod='leoproductsearch'}">
|
||||
<input type="hidden" name="leoproductsearch_static_token" value="{$leoproductsearch_static_token|escape:'htmlall':'UTF-8'|stripslashes}"/>
|
||||
{*
|
||||
<input type="hidden" name="orderby" value="position" />
|
||||
<input type="hidden" name="orderway" value="desc" />
|
||||
*}
|
||||
<label>{l s='Search products:' mod='leoproductsearch'}</label>
|
||||
<div id="leo_search_block_input" class="block_content clearfix leoproductsearch-content">
|
||||
{if $en_search_by_cat}
|
||||
<div class="list-cate-wrapper">
|
||||
<input id="leosearchtop-cate-id" name="cate" value="{if isset($selectedCate)}{$selectedCate}{/if}" type="hidden">
|
||||
<a href="javascript:void(0)" id="dropdownListCateTop" class="select-title" rel="nofollow" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
<span>{if $selectedCateName != ''}{$selectedCateName}{else}{l s='All Categories' mod='leoproductsearch'}{/if}</span>
|
||||
<i class="material-icons pull-xs-right">keyboard_arrow_down</i>
|
||||
</a>
|
||||
<div class="list-cate dropdown-menu" aria-labelledby="dropdownListCateTop">
|
||||
<a href="#" data-cate-id="" data-cate-name="{l s='All Categories' mod='leoproductsearch'}" class="cate-item{if $selectedCate == ''} active{/if}" >{l s='All Categories' mod='leoproductsearch'}</a>
|
||||
<a href="#" data-cate-id="{$cates.id_category|escape:'htmlall':'UTF-8'|stripslashes}" data-cate-name="{$cates.name}" class="cate-item cate-level-{$cates.level_depth}{if isset($selectedCate) && $cates.id_category eq $selectedCate} active{/if}" >{if $cates.level_depth > 1}{str_repeat('-', $cates.level_depth)}{/if}{$cates.name}</a>
|
||||
{lps_categories nodes=$cates.children}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
<div class="leoproductsearch-result">
|
||||
<div class="leoproductsearch-loading cssload-speeding-wheel"></div>
|
||||
<input class="search_query form-control grey" type="text" id="leo_search_query_top" name="search_query" value="{$search_query|escape:'htmlall':'UTF-8'|stripslashes}" placeholder="Szukaj sportu, produktu lub marki..."/>
|
||||
<div class="ac_results lps_results"></div>
|
||||
</div>
|
||||
<button type="submit" id="leo_search_top_button" class="btn btn-default button button-small"><span><i class="material-icons search">search</i></span></button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
var blocksearch_type = 'top';
|
||||
</script>
|
||||
<!-- /Block search module -->
|
||||
98
modules/leoproductsearch/views/templates/front/search.tpl
Normal file
98
modules/leoproductsearch/views/templates/front/search.tpl
Normal file
@@ -0,0 +1,98 @@
|
||||
{*
|
||||
* @Module Name: Leo Product Search
|
||||
* @Website: leotheme.com.com - prestashop template provider
|
||||
* @author Leotheme <leotheme@gmail.com>
|
||||
* @copyright Leotheme
|
||||
*}
|
||||
|
||||
{extends file=$layout}
|
||||
|
||||
{block name='content'}
|
||||
|
||||
{capture name=path}{l s='Search' mod='leoproductsearch'}{/capture}
|
||||
|
||||
<h1
|
||||
{if isset($instant_search) && $instant_search}id="instant_search_results"{/if}
|
||||
class="page-heading {if !isset($instant_search) || (isset($instant_search) && !$instant_search)} product-listing{/if}">
|
||||
{l s='Search' mod='leoproductsearch'}
|
||||
{if $nbProducts > 0}
|
||||
<span class="lighter">
|
||||
"{if isset($search_query) && $search_query}{$search_query|escape:'html':'UTF-8'}{elseif $search_tag}{$search_tag|escape:'html':'UTF-8'}{elseif $ref}{$ref|escape:'html':'UTF-8'}{/if}"
|
||||
</span>
|
||||
{/if}
|
||||
{if isset($instant_search) && $instant_search}
|
||||
<a href="#" class="close">
|
||||
{l s='Return to the previous page' mod='leoproductsearch'}
|
||||
</a>
|
||||
{else}
|
||||
<span class="heading-counter">
|
||||
{if $nbProducts == 1}{l s='%d result has been found.' sprintf=[$nbProducts|intval] mod='leoproductsearch'}{else}{l s='%d results have been found.' sprintf=[$nbProducts|intval] mod='leoproductsearch'}{/if}
|
||||
</span>
|
||||
{/if}
|
||||
</h1>
|
||||
|
||||
{if $search_products.suggest || $search_products.category}
|
||||
<div class="head-leosearch-product">
|
||||
{if $search_products.suggest}
|
||||
<div class="search-in-suggest">
|
||||
<div class="search-value-title">{l s='Suggestion' mod='leoproductsearch'}</div>
|
||||
<ul>
|
||||
{foreach from=$search_products.suggest item=suggest}
|
||||
<li><a class="suggest-item" href="{$suggest.link}">{$suggest.word}</a></li>
|
||||
{/foreach}
|
||||
</ul>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{if $search_products.category}
|
||||
<div class="search-in-cat">
|
||||
<div class="search-value-title">{l s='Search in category' mod='leoproductsearch'}</div>
|
||||
<ul>
|
||||
{foreach from=$search_products.category item=category}
|
||||
<li><a href="{$category.link}">{l s='in category' mod='leoproductsearch'}: <strong>{$category.name}</strong> ({$category.count})</a></li>
|
||||
{/foreach}
|
||||
</ul>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{if !$nbProducts}
|
||||
<p class="alert alert-warning">
|
||||
{if isset($search_query) && $search_query}
|
||||
{l s='No results were found for your search' mod='leoproductsearch'} "{if isset($search_query)}{$search_query|escape:'html':'UTF-8'}{/if}"
|
||||
{elseif isset($search_tag) && $search_tag}
|
||||
{l s='No results were found for your search' mod='leoproductsearch'} "{$search_tag|escape:'html':'UTF-8'}"
|
||||
{else}
|
||||
{l s='Please enter a search keyword' mod='leoproductsearch'}
|
||||
{/if}
|
||||
</p>
|
||||
{else}
|
||||
{if isset($instant_search) && $instant_search}
|
||||
<p class="alert alert-info">
|
||||
{if $nbProducts == 1}{l s='%d result has been found.' sprintf=[$nbProducts|intval] mod='leoproductsearch'}{else}{l s='%d results have been found.' sprintf=[$nbProducts|intval] mod='leoproductsearch'}{/if}
|
||||
</p>
|
||||
{/if}
|
||||
|
||||
<section id="products">
|
||||
<div id="">
|
||||
{block name='product_list_top'}
|
||||
{include file='catalog/_partials/products-top.tpl' listing=$search_products}
|
||||
{/block}
|
||||
</div>
|
||||
|
||||
{block name='product_list_active_filters'}
|
||||
<div id="" class="hidden-sm-down">
|
||||
{$search_products.rendered_active_filters nofilter}{* HTML form , no escape necessary *}
|
||||
</div>
|
||||
{/block}
|
||||
<div id="">
|
||||
{block name='product_list'}
|
||||
{include file='catalog/_partials/products.tpl' listing=$search_products}
|
||||
{/block}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/if}
|
||||
{/block}
|
||||
36
modules/leoproductsearch/views/templates/index.php
Normal file
36
modules/leoproductsearch/views/templates/index.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2014 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/osl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2014 PrestaShop SA
|
||||
* @version Release: $Revision$
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
||||
Reference in New Issue
Block a user