Esempio n. 1
0
* @author PrestaShop SA <*****@*****.**>
* @copyright 2007-2013 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
require_once dirname(__FILE__) . '/../../../config/config.inc.php';
require_once dirname(__FILE__) . '/../../../init.php';
require_once dirname(__FILE__) . '/../prediggo.php';
// Launch a Prediggo Notification
if (Tools::getValue('nId')) {
    $oPrediggo = new Prediggo();
    $params = array('cookie' => Context::getContext()->cookie, 'notificationId' => Tools::getValue('nId'));
    die(Tools::jsonEncode($oPrediggo->setProductNotification($params)));
}
// Launch a Prediggo Autocomplete action
if (Tools::getValue('q')) {
    require_once dirname(__FILE__) . '/../controllers/front/search.php';
    ob_start();
    $_GET['module'] = 'prediggo';
    $oPrediggoSearchModuleFrontController = new PrediggoSearchModuleFrontController();
    $oPrediggoSearchModuleFrontController->setQuery(pSQL(Tools::getValue('q')));
    $aResult = $oPrediggoSearchModuleFrontController->getAutocomplete();
    ob_end_clean();
    die(Tools::jsonEncode($aResult));
}
// Launch a Prediggo Recommendations for the blocklayered module
if (Tools::getValue('id_category_layered')) {
    $oPrediggo = new Prediggo();
    $params = array('cookie' => Context::getContext()->cookie, 'id_category_layered' => (int) Tools::getValue('id_category_layered'));
    die(Tools::jsonEncode($oPrediggo->getBlockLayeredRecommendations($params)));
}
 /**
  * Set the refine option
  *
  * @return array $aItems Autocompletion items (suggestions, products)
  */
 public function getAutocomplete()
 {
     global $link;
     parent::process();
     if (!$this->oPrediggoSearchConfig->autocompletion_active) {
         return '';
     }
     $aItems = array();
     /* If $sQuery is empty return the prediggo suggestion and products */
     if (strlen($this->sQuery) >= $this->oPrediggoSearchConfig->search_nb_min_chars && ($oPrediggoResult = $this->launchAutoComplete())) {
         require_once _PS_MODULE_DIR_ . 'prediggo/prediggo.php';
         $oModule = new Prediggo();
         foreach ($oPrediggoResult->getSuggestedWords() as $oSuggestedWords) {
             self::$smarty->assign(array('oSuggestedWords' => $oSuggestedWords));
             $aItems[] = array('value' => $oModule->displayAutocompleteDidYouMean($oSuggestedWords), 'link' => $link->getPageLink('modules/prediggo/prediggo_search.php') . '?q=' . $oSuggestedWords->getWord(), 'notificationId' => '', 'isRecommendation' => false);
         }
         foreach ($this->oPrediggoCall->getSuggestedProducts($oPrediggoResult, (int) self::$cookie->id_lang, (int) $this->oPrediggoSearchConfig->autocompletion_nb_items) as $aRecommendation) {
             self::$smarty->assign(array('aRecommendation' => $aRecommendation));
             $aItems[] = array('value' => $oModule->displayAutocompleteProduct(), 'link' => $aRecommendation['link'], 'notificationId' => $aRecommendation['notificationId'], 'isRecommendation' => true);
         }
     } elseif (strlen($this->sQuery) == 0) {
         global $link;
         if ($aSuggestWords = explode(',', $this->oPrediggoSearchConfig->suggest_words[(int) self::$cookie->id_lang])) {
             require_once _PS_MODULE_DIR_ . 'prediggo/prediggo.php';
             $oModule = new Prediggo();
             foreach ($aSuggestWords as $sSuggestWord) {
                 self::$smarty->assign(array('sSuggestWord' => trim($sSuggestWord)));
                 $aItems[] = array('value' => $oModule->displayAutocompleteSuggest(), 'link' => $link->getPageLink('modules/prediggo/prediggo_search.php') . '?q=' . $sSuggestWord, 'notificationId' => '', 'isRecommendation' => false);
             }
         }
     }
     return $aItems;
 }