private:koding:hostcms:modules:shop:useful:autocomplete

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
private:koding:hostcms:modules:shop:useful:autocomplete [25.11.15 в 13:41]
san-ma_yandex.ru
private:koding:hostcms:modules:shop:useful:autocomplete [27.06.17 в 15:57] (current)
maximzasorin_gmail.com ↷ Страница перемещена из private:koding:hostcms:shop:autocomplete в private:koding:hostcms:modules:shop:useful:autocomplete
Line 1: Line 1:
 +====== Автодополнение в строке поиска ======
 +
 +
 В этой статье описано,​ как реализовать такое автодополнение вариантов поиска в редакции Халява В этой статье описано,​ как реализовать такое автодополнение вариантов поиска в редакции Халява
 {{:​private:​koding:​hostcms:​shop:​12e3.jpg|}} {{:​private:​koding:​hostcms:​shop:​12e3.jpg|}}
Line 6: Line 9:
 Свежую версию плагина можно скачать на Github'​е:​ https://​github.com/​devbridge/​jQuery-Autocomplete Свежую версию плагина можно скачать на Github'​е:​ https://​github.com/​devbridge/​jQuery-Autocomplete
  
-1. необходимо добавить загруженные файлы скрипта и стилей на сервер ''​styles.css''​ и ''​jquery.autocomplete.min.js''​ в папки ''​css''​ и ''​js''​ соответственно. +  - Необходимо добавить загруженные файлы скрипта и стилей на сервер ''​styles.css''​ и ''​jquery.autocomplete.min.js''​ в папки ''​css''​ и ''​js''​ соответственно. 
- +  - Подключить эти файлы в основном макете сайта 
-2. подключить эти файлы в основном макете сайта +  - В основной макет сайта в блок ''​head''​ добавить следующий код: <code html>
- +
-3. в основной макет сайта в блок ''​head''​ добавить следующий код: +
- +
-<code html>+
 <script type="​text/​javascript">​ <script type="​text/​javascript">​
   $(function() {   $(function() {
Line 31: Line 30:
   });   });
 </​script></​code>​ </​script></​code>​
 +  - Для ''<​input>'',​ у которого должен выводиться выпадающий список добавляете ''​id="​search_text"'' ​
 +  - В ТДС, в Настройки страницы интернет магазина добавить код: (данный пример кода ищет варианты автозаполнения по имени и артикулу) <code php>
  
-4. Для ''<​input>'',​ у которого должен выводиться выпадающий список добавляете 
-''​id="​search_text"'' ​ 
- 
-5. В ТДС, в Настройки страницы интернет магазина добавить код: ​ 
- 
-(данный пример кода ищет варианты автозаполнения по имени и артикулу) 
- 
-<code php> 
 /** /**
 *  Поиск товаров для автозаполнения *  Поиск товаров для автозаполнения
Line 50: Line 43:
 if (Core_Array::​getGet('​autocomplete'​)) if (Core_Array::​getGet('​autocomplete'​))
 { {
-  ​$result_json ​= array(); + $aResultJson ​= array(); 
-  $query=Core_Array::​getGet('​query'​);​ + $sQuery=Core_Array::​getGet('​query'​);​ 
- +  
-  // Оригинальный запрос + $aResultJson['​query'​] = $sQuery
-  ​$result_json['​query'​] = $query+ $aResultJson['​suggestions'​] = array(); 
-  $result_json['​suggestions'​] = array(); +  
- + //ищем совпадающие запросу имена 
-  //ищем совпадающие запросу имена + $aResultName ​= Core_QueryBuilder::​select(array('​shop_items.name',​ '​value'​)) 
-  $result1 ​= Core_QueryBuilder::​select(array('​shop_items.name',​ '​value'​)) + ->​from('​shop_items'​) 
-    ->​from('​shop_items'​) + ->​where('​shop_items.name',​ '​LIKE',​ '​%'​.$sQuery.'​%'​) 
-    ->​where('​shop_items.name',​ '​LIKE',​ '​%'​.$query.'​%'​) + ->​setAnd() 
-    ->​setAnd() + ->​where('​shop_items.shop_id',​ '​=',​ '​5'​)->​setAnd() 
-    ->​where('​shop_items.shop_id',​ '​=',​ '​5'​)->​setAnd() + ->​where('​shop_items.active',​ '​=',​ '​1'​)->​setAnd() 
-    ->​where('​shop_items.active',​ '​=',​ '​1'​)->​setAnd() + ->​where('​shop_items.deleted',​ '​=',​ '​0'​);​  
-    ->​where('​shop_items.deleted',​ '​=',​ '​0'​);​  +  
- + //​аналогично ищем артикули 
-  //​аналогично ищем артикули + $aResultMarking ​= Core_QueryBuilder::​select(array('​shop_items.marking',​ '​value'​)) 
-  $result2 ​= Core_QueryBuilder::​select(array('​shop_items.marking',​ '​value'​)) + ->​from('​shop_items'​) 
-    ->​from('​shop_items'​) + ->​where('​shop_items.marking',​ '​LIKE',​ '​%'​.$sQuery.'​%'​) 
-    ->​where('​shop_items.marking',​ '​LIKE',​ '​%'​.$query.'​%'​) + ->​setAnd() 
-    ->​setAnd() + ->​where('​shop_items.shop_id',​ '​=',​ '​5'​)->​setAnd() 
-    ->​where('​shop_items.shop_id',​ '​=',​ '​5'​)->​setAnd() + ->​where('​shop_items.active',​ '​=',​ '​1'​)->​setAnd() 
-    ->​where('​shop_items.active',​ '​=',​ '​1'​)->​setAnd() + ->​where('​shop_items.deleted',​ '​=',​ '​0'​);​  
-    ->​where('​shop_items.deleted',​ '​=',​ '​0'​);​  +  
- +  
- + $aResultJson['​suggestions'​] = array_merge($aResultName->​execute()->​asAssoc()->​result(),​ $aResultMarking->​execute()->​asAssoc()->​result()) ; 
-  $result_json['​suggestions'​] = array_merge($result1->​execute()->​asAssoc()->​result(),​ $result2->​execute()->​asAssoc()->​result()) ; +  
- + echo json_encode($aResultJson); 
-  echo json_encode($result_json); + exit();
-  exit();+
 } }
- 
  
 /** /**
Line 87: Line 78:
 * @author Malinovskii Aleksandr, KAD Systems (©) 2015 * @author Malinovskii Aleksandr, KAD Systems (©) 2015
 * @date 24-11-2015 * @date 24-11-2015
-*/<​code>​+*/ 
 +</code>
private/koding/hostcms/modules/shop/useful/autocomplete.1448448077.txt.gz · Last modified: 25.11.15 в 13:41 by san-ma_yandex.ru