tab = $tab; $this->addon = $addon; $this->name = $addon; $this->context = Context::getContext(); if (Tools::getValue('searchType', 'false') != 'false' && Tools::getValue('ajax') == 1) { if (Tools::getValue('searchType') == 'manufacturer') { echo self::jsonencode($this->searchForID('manufacturer', 'name', trim(Tools::getValue('q')), false)); die(); } elseif (Tools::getValue('searchType') == 'product') { echo self::jsonencode($this->searchForID('product_lang', 'name', trim(Tools::getValue('q')), true)); die(); } elseif (Tools::getValue('searchType') == 'category') { echo self::jsonencode($this->searchForID('category_lang', 'name', trim(Tools::getValue('q')), true)); die(); } elseif (Tools::getValue('searchType') == 'supplier') { echo self::jsonencode($this->searchForID('supplier', 'name', trim(Tools::getValue('q')), false)); die(); } elseif (Tools::getValue('searchType') == 'cms_category') { echo self::jsonencode($this->searchForID('cms_category_lang', 'name', trim(Tools::getValue('q')), true)); die(); } elseif (Tools::getValue('searchType') == 'cms') { echo self::jsonencode($this->searchForID('cms_lang', 'meta_title', trim(Tools::getValue('q')), true)); die(); } elseif (Tools::getValue('searchType') == 'customer') { echo self::jsonencode($this->searchForID('customer', array('email', 'firstname', 'lastname'), trim(Tools::getValue('q')), true)); die(); } elseif (Tools::getValue('searchType') == 'group') { echo self::jsonencode($this->searchForID('group_lang', 'name', trim(Tools::getValue('q')), false)); die(); } elseif (Tools::getValue('searchType') == 'feature_value') { $result = $this->searchForID('feature_value_lang', 'value', trim(Tools::getValue('q')), false); if (is_array($result)) { if (count($result) > 0) { foreach ($result AS $k => $v) { $fv = new FeatureValue($v['id_feature_value'], Context::getContext()->language->id); $f = new Feature($fv->id_feature, Context::getContext()->language->id); if ($f != false) { $result[$k]['feature_name'] = $f->name; $result[$k]['value'] = $result[$k]['value'] . $this->productsFound('feature', $v['id_feature_value']); } } } } echo self::jsonencode($result); die(); } elseif (Tools::getValue('searchType') == 'attribute_value') { $result = $this->searchForID('attribute_lang', 'name', trim(Tools::getValue('q')), false); if (is_array($result)) { if (count($result) > 0) { foreach ($result AS $k => $v) { $attr = new Attribute($v['id_attribute'], Context::getContext()->language->id); $attrg = new AttributeGroup($attr->id_attribute_group, Context::getContext()->language->id); if ($attrg != false) { $result[$k]['attribute_name'] = $attrg->public_name; $result[$k]['name'] = $result[$k]['name'] . (Tools::getValue('showCounter') == true ? $this->productsFound('attribute', $v['id_attribute']) : ''); } } } } echo self::jsonencode($result); die(); } } elseif (Tools::getValue('getCombinations') == 1 && Tools::getValue('searchByID', 'false') != 'false' && Tools::getValue('ajax') == 1) { echo $this->returnCombinations(Tools::getValue('searchByID'), Tools::getValue('combinationsClass')); } } public function initTool() { $this->context->smarty->assign('SearchToolLink', $this->context->link->getAdminLink('AdminModules', false) . '&token=' . Tools::getAdminTokenLite('AdminModules') . '&configure=' . $this->name . '&tab_module=' . $this->tab . '&ajax=1&module_name=' . $this->name); return $this->context->smarty->fetch(_PS_MODULE_DIR_ . $this->addon . '/lib/searchTool/views/scripts.tpl'); } public function productsFound($type, $id) { if ($type == 'attribute') { $result = Db::getInstance()->ExecuteS('SELECT * FROM `' . _DB_PREFIX_ . 'product_attribute_combination` pac INNER JOIN ' . _DB_PREFIX_ . 'product_attribute_shop pas ON (pas.id_product_attribute = pac.id_product_attribute) WHERE pac.id_attribute="' . $id . '" GROUP BY pas.id_product'); if (isset($result[0]['id_product'])) { return ' | ' . $this->l('Products found:') . ' ' . count($result); } else { return ''; } } if ($type == 'feature') { $result = Db::getInstance()->ExecuteS('SELECT * FROM `' . _DB_PREFIX_ . 'feature_product` fp WHERE fp.id_feature_value="'.$id.'" '); if (isset($result[0]['id_feature_value'])) { return ' | ' . $this->l('Products found:') . ' ' . count($result); } else { return ''; } } } public function searchTool($type, $resultInput, $replacementType = 'replace', $returnBox = false, $object = false, $combinations = false, $combination_input = '', $selected_combination = false, $showCounter = false) { $array = array(); if ($returnBox == true) { if ($object != false) { $objectClass = ucfirst($type); if ($objectClass == 'Cms_category') { $objectClass = 'CMSCategory'; } elseif ($objectClass == 'Cms') { $objectClass = 'CMS'; } elseif ($objectClass == 'Feature_value') { $objectClass = 'FeatureValue'; } if (class_exists($objectClass)) { $object_exploded = explode(',', $object); foreach ($object_exploded AS $object_item) { if ($type == 'product') { $object_to_display = new $objectClass($object_item, false, $this->context->language->id); } elseif ($type == 'feature_value') { $object_to_display = new FeatureValue($object_item, $this->context->language->id); $f = new Feature($object_to_display->id_feature, $this->context->language->id); $object_to_display->value = $f->name . ': ' . $object_to_display->value; } elseif ($type == 'attribute_value') { $object_to_display = new Attribute($object_item, $this->context->language->id); $ag = new Feature($object_to_display->id_attribute_group, $this->context->language->id); $object_to_display->value = $ag->public_name . ': ' . $object_to_display->name; } else { $object_to_display = new $objectClass($object_item, $this->context->language->id); } $array[] = '