Exemplo n.º 1
0
 public function preProcess()
 {
     parent::preProcess();
     $query = urldecode(Tools::getValue('q'));
     if ($this->ajaxSearch) {
         self::$link = new Link();
         $searchResults = Search::find((int) Tools::getValue('id_lang'), $query, 1, 10, 'position', 'desc', true);
         if (is_array($searchResults)) {
             foreach ($searchResults as &$product) {
                 $product['product_link'] = self::$link->getProductLink($product['id_product'], $product['prewrite'], $product['crewrite']);
             }
         }
         die(Tools::jsonEncode($searchResults));
     } elseif ($this->instantSearch && !is_array($query)) {
         $this->productSort();
         $this->n = abs((int) Tools::getValue('n', Configuration::get('PS_PRODUCTS_PER_PAGE')));
         $this->p = abs((int) Tools::getValue('p', 1));
         $search = Search::find((int) self::$cookie->id_lang, $query, $this->p, $this->n, $this->orderBy, $this->orderWay);
         Module::hookExec('search', array('expr' => $query, 'total' => $search['total']));
         $nbProducts = $search['total'];
         $this->pagination($nbProducts);
         self::$smarty->assign(array('products' => $search['result'], 'search_products' => $search['result'], 'nbProducts' => $search['total'], 'search_query' => $query, 'instantSearch' => $this->instantSearch, 'homeSize' => Image::getSize('home')));
     } elseif ($query = Tools::getValue('search_query', Tools::getValue('ref')) and !is_array($query)) {
         $this->productSort();
         $this->n = abs((int) Tools::getValue('n', Configuration::get('PS_PRODUCTS_PER_PAGE')));
         $this->p = abs((int) Tools::getValue('p', 1));
         $search = Search::find((int) self::$cookie->id_lang, $query, $this->p, $this->n, $this->orderBy, $this->orderWay);
         Module::hookExec('search', array('expr' => $query, 'total' => $search['total']));
         $nbProducts = $search['total'];
         $this->pagination($nbProducts);
         self::$smarty->assign(array('products' => $search['result'], 'search_products' => $search['result'], 'nbProducts' => $search['total'], 'search_query' => $query, 'homeSize' => Image::getSize('home')));
     } elseif ($tag = urldecode(Tools::getValue('tag')) and !is_array($tag)) {
         $this->productSort();
         $nbProducts = (int) Search::searchTag((int) self::$cookie->id_lang, $tag, true);
         $this->pagination($nbProducts);
         $result = Search::searchTag((int) self::$cookie->id_lang, $tag, false, $this->p, $this->n, $this->orderBy, $this->orderWay);
         Module::hookExec('search', array('expr' => $tag, 'total' => sizeof($result)));
         self::$smarty->assign(array('search_tag' => $tag, 'products' => $result, 'search_products' => $result, 'nbProducts' => $nbProducts, 'homeSize' => Image::getSize('home')));
     } else {
         self::$smarty->assign(array('products' => array(), 'search_products' => array(), 'pages_nb' => 1, 'nbProducts' => 0));
     }
     self::$smarty->assign('add_prod_display', Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'));
 }
Exemplo n.º 2
0
 public function preProcess()
 {
     if (!Module::isInstalled('agilesearchbyzipcode')) {
         return parent::preProcess();
     }
     if (Tools::getValue('is_zipcode_search') != 1) {
         return parent::preProcess();
     }
     $this->productSort();
     $this->n = abs((int) Tools::getValue('n', Configuration::get('PS_PRODUCTS_PER_PAGE')));
     $this->p = abs((int) Tools::getValue('p', 1));
     $centerLat = Tools::getValue('asbz_centerLat');
     $centerLng = Tools::getValue('asbz_centerLng');
     $search_scope = Configuration::get('ASBZ_SEARCH_SCOPE');
     include_once dirname(__FILE__) . "/../../modules/agilesearchbyzipcode/ProdLocation.php";
     $products = ProdLocation::searchProducts(self::$cookie->id_lang, $centerLat, $centerLng, $search_scope, Tools::getValue('orderby'), Tools::getValue('orderway'));
     $nbProducts = count($products);
     $this->pagination($nbProducts);
     self::$smarty->assign(array('search_products' => $products, 'nbProducts' => $nbProducts, 'search_tag' => '', 'search_query' => Tools::getValue('asbz_zipcode'), 'ref' => '', 'search_zipcode' => Tools::getValue('asbz_zipcode'), 'homeSize' => Image::getSize('home')));
     self::$smarty->assign('add_prod_display', Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'));
 }
 public function setMedia()
 {
     parent::setMedia();
     if (!$this->instant_search && !$this->ajax_search) {
         $this->addCSS(_THEME_CSS_DIR_ . 'product_list.css');
     }
 }
Exemplo n.º 4
0
 public function initContent()
 {
     include _PS_MODULE_DIR_ . 'blocksearch_mod' . DIRECTORY_SEPARATOR . 'IqitSearch.php';
     $query = Tools::replaceAccentedChars(urldecode(Tools::getValue('q')));
     $original_query = Tools::getValue('q');
     $search_query_cat = (int) Tools::getValue('search_query_cat');
     if ($this->ajax_search) {
         self::$link = new Link();
         $image = new Image();
         $searchResults = IqitSearch::find((int) Tools::getValue('id_lang'), $query, $search_query_cat, 1, 10, 'position', 'desc', true);
         $taxes = Product::getTaxCalculationMethod();
         $currency = (int) Context::getContext()->currency->id;
         $iso_code = $this->context->language->iso_code;
         if (is_array($searchResults)) {
             foreach ($searchResults as &$product) {
                 $imageID = $image->getCover($product['id_product']);
                 if (isset($imageID['id_image'])) {
                     $imgLink = $this->context->link->getImageLink($product['prewrite'], (int) $product['id_product'] . '-' . $imageID['id_image'], 'small_default');
                 } else {
                     $imgLink = _THEME_PROD_DIR_ . $iso_code . "-default-small_default.jpg";
                 }
                 $product['product_link'] = $this->context->link->getProductLink($product['id_product'], $product['prewrite'], $product['crewrite']);
                 $product['obr_thumb'] = $imgLink;
                 $product['product_price'] = Product::getPriceStatic((int) $product['id_product'], false, NULL, 2);
                 if ($taxes == 0 or $taxes == 2) {
                     $product['product_price'] = Tools::displayPrice(Product::getPriceStatic((int) $product['id_product'], true), $currency);
                 } elseif ($taxes == 1) {
                     $product['product_price'] = Tools::displayPrice(Product::getPriceStatic((int) $product['id_product'], false), $currency);
                 }
             }
         }
         $this->ajaxDie(Tools::jsonEncode($searchResults));
     }
     // Only controller content initialization when the user use the normal search
     parent::initContent();
     if ($this->instant_search && !is_array($query)) {
         $this->productSort();
         $this->n = abs((int) Tools::getValue('n', $product_per_page));
         $this->p = abs((int) Tools::getValue('p', 1));
         $search = IqitSearch::find($this->context->language->id, $query, $search_query_cat, 1, 10, 'position', 'desc');
         Hook::exec('actionSearch', array('expr' => $query, 'total' => $search['total']));
         $nbProducts = $search['total'];
         $this->pagination($nbProducts);
         $this->addColorsToProductList($search['result']);
         if (method_exists('Product', 'getProductsImgs')) {
             $image_array = array();
             for ($i = 0; $i < $nbProducts; $i++) {
                 if (isset($search['result'][$i]['id_product'])) {
                     $image_array[$search['result'][$i]['id_product']] = Product::getProductsImgs($search['result'][$i]['id_product']);
                 }
             }
             $this->context->smarty->assign('productimg', (isset($image_array) and $image_array) ? $image_array : NULL);
         }
         $this->context->smarty->assign(array('products' => $search['result'], 'search_products' => $search['result'], 'nbProducts' => $search['total'], 'search_query' => $original_query, 'instant_search' => $this->instant_search, 'homeSize' => Image::getSize(ImageType::getFormatedName('home'))));
     } elseif (($query = Tools::getValue('search_query', Tools::getValue('ref'))) && !is_array($query)) {
         $this->productSort();
         $this->n = abs((int) Tools::getValue('n', Configuration::get('PS_PRODUCTS_PER_PAGE')));
         $this->p = abs((int) Tools::getValue('p', 1));
         $original_query = $query;
         $query = Tools::replaceAccentedChars(urldecode($query));
         $search = IqitSearch::find($this->context->language->id, $query, $search_query_cat, $this->p, $this->n, $this->orderBy, $this->orderWay);
         if (is_array($search['result'])) {
             foreach ($search['result'] as &$product) {
                 $product['link'] .= (strpos($product['link'], '?') === false ? '?' : '&') . 'search_query=' . urlencode($query) . '&results=' . (int) $search['total'];
             }
         }
         Hook::exec('actionSearch', array('expr' => $query, 'total' => $search['total']));
         $nbProducts = $search['total'];
         $this->pagination($nbProducts);
         $this->addColorsToProductList($search['result']);
         /************************* /Images Array ******************************/
         if (method_exists('Product', 'getProductsImgs')) {
             $image_array = array();
             for ($i = 0; $i < $nbProducts; $i++) {
                 if (isset($search['result'][$i]['id_product'])) {
                     $image_array[$search['result'][$i]['id_product']] = Product::getProductsImgs($search['result'][$i]['id_product']);
                 }
             }
             $this->context->smarty->assign('productimg', (isset($image_array) and $image_array) ? $image_array : NULL);
         }
         /************************* /Images Array ******************************/
         $this->context->smarty->assign(array('products' => $search['result'], 'search_products' => $search['result'], 'nbProducts' => $search['total'], 'search_query' => $original_query, 'homeSize' => Image::getSize(ImageType::getFormatedName('home'))));
     } elseif (($tag = urldecode(Tools::getValue('tag'))) && !is_array($tag)) {
         $nbProducts = (int) Search::searchTag($this->context->language->id, $tag, true);
         $this->pagination($nbProducts);
         $result = Search::searchTag($this->context->language->id, $tag, false, $this->p, $this->n, $this->orderBy, $this->orderWay);
         Hook::exec('actionSearch', array('expr' => $tag, 'total' => count($result)));
         $this->addColorsToProductList($result);
         /************************* /Images Array ******************************/
         if (method_exists('Product', 'getProductsImgs')) {
             $image_array = array();
             for ($i = 0; $i < $nbProducts; $i++) {
                 if (isset($result[$i]['id_product'])) {
                     $image_array[$result[$i]['id_product']] = Product::getProductsImgs($result[$i]['id_product']);
                 }
             }
             $this->context->smarty->assign('productimg', (isset($image_array) and $image_array) ? $image_array : NULL);
         }
         /************************* /Images Array ******************************/
         $this->context->smarty->assign(array('search_tag' => $tag, 'products' => $result, 'search_products' => $result, 'nbProducts' => $nbProducts, 'homeSize' => Image::getSize(ImageType::getFormatedName('home'))));
     } else {
         $this->context->smarty->assign(array('products' => array(), 'search_products' => array(), 'pages_nb' => 1, 'nbProducts' => 0));
     }
     $this->context->smarty->assign(array('add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'comparator_max_item' => Configuration::get('PS_COMPARATOR_MAX_ITEM')));
     $this->setTemplate(_PS_THEME_DIR_ . 'search.tpl');
 }
Exemplo n.º 5
0
 public function preProcess()
 {
     parent::preProcess();
     $query = urldecode(Tools::getValue('q'));
     if ($this->ajaxSearch) {
         self::$link = new Link();
         $searchResults = Search::find((int) Tools::getValue('id_lang'), $query, 1, 10, 'position', 'desc', true);
         foreach ($searchResults as &$product) {
             $product['product_link'] = self::$link->getProductLink($product['id_product'], $product['prewrite'], $product['crewrite']);
         }
         die(Tools::jsonEncode($searchResults));
     }
     if ($this->instantSearch && !is_array($query)) {
         $this->productSort();
         $this->n = abs((int) Tools::getValue('n', Configuration::get('PS_PRODUCTS_PER_PAGE')));
         $this->p = abs((int) Tools::getValue('p', 1));
         $search = Search::find((int) self::$cookie->id_lang, $query, $this->p, $this->n, 'position', 'desc');
         Module::hookExec('search', array('expr' => $query, 'total' => $search['total']));
         $nbProducts = $search['total'];
         $this->pagination($nbProducts);
         self::$smarty->assign(array('products' => $search['result'], 'search_products' => $search['result'], 'nbProducts' => $search['total'], 'search_query' => $query, 'instantSearch' => $this->instantSearch, 'homeSize' => Image::getSize('home')));
     } elseif ($query = Tools::getValue('search_query', Tools::getValue('ref')) and !is_array($query)) {
         $this->productSort();
         $this->n = abs((int) Tools::getValue('n', Configuration::get('PS_PRODUCTS_PER_PAGE')));
         $this->p = abs((int) Tools::getValue('p', 1));
         //$search = Search::find((int)(self::$cookie->id_lang), $query, $this->p, $this->n, 'position', 'desc');
         $other_results = false;
         try {
             //get the right address for this cart
             global $cart, $cookie;
             $id_country = (int) Country::getDefaultCountryId();
             if ($cart->id_address_delivery) {
                 $address = new Address($cart->id_address_delivery);
                 if ($address->id_country) {
                     $id_country = $address->id_country;
                 } elseif (isset($cookie->id_country)) {
                     $id_country = (int) $cookie->id_country;
                 }
             }
             self::$smarty->assign('price_tax_country', $id_country);
             $resultSet = Search::searchProducts($query, $this->p, $this->n, $other_results);
             $products = $resultSet->getData();
             $products = $products['response']['docs'];
             $total_results = $resultSet->getNumFound();
         } catch (Exception $e) {
             self::$smarty->assign('fetch_error', 1);
         }
         Module::hookExec('search', array('expr' => $query, 'total' => $total_results));
         $this->pagination($total_results);
         self::$smarty->assign(array('products' => $products, 'search_products' => $products, 'nbProducts' => $total_results, 'search_query' => $query, 'homeSize' => Image::getSize('home'), 'ssResults' => $other_results));
         $generic_description = "Buy the widest range of sarees, salwar kameez, kurtis, tunics and ghaghra cholis by shopping online at IndusDiva.com, India's leading online store for buying #phrase#. All products are double-checked for quality before they get shipped and we take extra care to ensure the safety of your order. We deliver products all over the world through leading courier service providers to ensure timely and hassle-free deliveries.\n\t\t\t\t\t\t\t\t\t<br><br>\n\t\t\t\t\t\t\t\t\tTo buy #phrase#, all you need to do is review your shopping cart and provide the address details and phone number at checkout. IndusDiva.com offers the best available price across all online shopping sites and provides the best collection of Indian wear online. Shopping for Indian saris, blouse and salwar kurta online just turned more fun as getting your hands on #phrase# has never been so easy.";
         $res = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS("select description from ps_seo_keywords where keyword = '" . $query . "'");
         if (count($res) > 0) {
             self::$smarty->assign('search_description', str_replace('#phrase#', $query, $res[0]['description']));
         } else {
             self::$smarty->assign('search_description', str_replace('#phrase#', $query, $generic_description));
         }
     } elseif ($tag = urldecode(Tools::getValue('tag')) and !is_array($tag)) {
         $nbProducts = (int) Search::searchTag((int) self::$cookie->id_lang, $tag, true);
         $this->pagination($nbProducts);
         $result = Search::searchTag((int) self::$cookie->id_lang, $tag, false, $this->p, $this->n, $this->orderBy, $this->orderWay);
         Module::hookExec('search', array('expr' => $tag, 'total' => sizeof($result)));
         self::$smarty->assign(array('search_tag' => $tag, 'products' => $result, 'search_products' => $result, 'nbProducts' => $nbProducts, 'homeSize' => Image::getSize('home')));
     } else {
         self::$smarty->assign(array('products' => array(), 'search_products' => array(), 'pages_nb' => 1, 'nbProducts' => 0));
     }
     self::$smarty->assign('add_prod_display', Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'));
     self::$smarty->assign('lazy', 1);
 }