/home/sharedstore/.trash/modules/czproductsearch
Edit: /home/sharedstore/.trash/modules/czproductsearch/czproductsearch.php (7184B)
* @copyright 2007-2018 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
if (!defined('_PS_VERSION_')) {
# module validation
exit;
}
class CzProductSearch extends Module
{
public function __construct()
{
$this->name = 'czproductsearch';
$this->tab = 'search_filter';
$this->version = '1.0.0';
$this->author = 'Codezeel';
$this->need_instance = 0;
$this->controllers = array('productsearch');
parent::__construct();
$this->displayName = $this->trans('CZ - Category Wise Product Search');
$this->description = $this->trans('Adds advanced category wise product search to your website.');
$this->ps_versions_compliancy = array('min' => '1.7.0.0', 'max' => _PS_VERSION_);
$this->templateFile = 'module:czproductsearch/views/templates/hook/czsearch_top.tpl';
}
public function install()
{
if (!parent::install() || !$this->registerHook('displayTop') || !$this->registerHook('displayHeader')) {
return false;
}
return true;
}
public function hookdisplayHeader($params)
{
$this->context->controller->registerStylesheet('modules-czsearch', 'modules/'.$this->name.'/views/css/czsearch.css', ['media' => 'all', 'priority' => 150]);
$this->context->controller->registerStylesheet('modules-product_list', _THEME_CSS_DIR_.'product_list.css', ['media' => 'all', 'priority' => 150]);
if (Configuration::get('PS_SEARCH_AJAX')) {
$this->context->controller->registerJavascript('modules-productsearchjs', 'modules/'.$this->name.'/views/js/jquery.autocomplete_productsearch.js', ['position' => 'bottom', 'priority' => 150]);
$this->context->controller->registerStylesheet('modules-autocomplete_productsearch', 'modules/'.$this->name.'/views/css/jquery.autocomplete_productsearch.css', ['media' => 'all', 'priority' => 150]);
Media::addJsDef(
array(
'cz_search_url' => $this->context->link->getModuleLink('czproductsearch', 'productsearch', array(), Tools::usingSecureMode()),
'ajaxsearch' => Configuration::get('PS_SEARCH_AJAX'),
)
);
$this->context->controller->registerJavascript('modules-czsearchjs', 'modules/'.$this->name.'/views/js/czsearch.js', ['position' => 'bottom', 'priority' => 150]);
}
}
/*public function hookLeftColumn($params)
{
if (Tools::getValue('search_query') || !$this->isCached('czsearch.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;
}
$this->smarty->assign(array(
'blocksearch_type' => 'block',
'search_query' => (string)Tools::getValue('search_query'),
'selectedCate' => (string)Tools::getValue('cate'),
'selectedCateName' => $selectedCateName,
'cates' => $this->getCategories($this->context->language->id),
));
}
Media::addJsDef(array('blocksearch_type' => 'block'));
// $search_query = (string)Tools::getValue('search_query');
return $this->display(__FILE__, 'czsearch.tpl', Tools::getValue('search_query') ? null : $this->getCacheId());
}*/
public function hookdisplayTop($params)
{
if (Tools::getValue('search_query') || !$this->isCached($this->templateFile, $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;
}
$this->smarty->assign(array(
'blocksearch_type' => 'top',
'search_query' => (string)Tools::getValue('search_query'),
'selectedCate' => (string)Tools::getValue('cate'),
'selectedCateName' => $selectedCateName,
'cates' => $this->getCategories($this->context->language->id),
));
}
return $this->display(__FILE__, 'czsearch_top.tpl', Tools::getValue('search_query') ? null : $this->getCacheId());
}
/*
public function hookdisplayNavFullWidth($params)
{
return $this->hookTop($params);
}*/
private function calculHookCommon($params)
{
$this->smarty->assign(array(
'ENT_QUOTES' => ENT_QUOTES,
'search_ssl' => Tools::usingSecureMode(),
'ajaxsearch' => Configuration::get('PS_SEARCH_AJAX'),
// 'ajaxsearch' => 1,
'instantsearch' => Configuration::get('PS_INSTANT_SEARCH'),
'self' => dirname(__FILE__),
));
unset($params);
return true;
}
/**
* copy from function hookFooter of class "modules/blockcategories/blockcategories"
*/
public function getCategories($id_lang = false, $active = true)
{
$maxdepth = Configuration::get('BLOCK_CATEG_MAX_DEPTH');
// Get all groups for this customer and concatenate them as a string: "1,2,3..."
$groups = implode(', ', Customer::getGroupsStatic((int)$this->context->customer->id));
$sql = '
SELECT DISTINCT c.id_parent, c.id_category, cl.name, cl.description, cl.link_rewrite
FROM `'._DB_PREFIX_.'category` c
'.Shop::addSqlAssociation('category', 'c').'
LEFT 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').')
LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = c.`id_category`)
WHERE (c.`active` = 1 OR c.`id_category` = 1)
'.((int)($maxdepth) != 0 ? ' AND `level_depth` <= '.(int)($maxdepth) : '').'
AND cg.`id_group` IN ('.pSQL($groups).')
ORDER BY `level_depth` ASC, '.(Configuration::get('BLOCK_CATEG_SORT') ? 'cl.`name`' : 'category_shop.`position`').' '.(Configuration::get('BLOCK_CATEG_SORT_WAY') ? 'DESC' : 'ASC');
unset($id_lang);
unset($active);
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
}
}