Jump to content

1. Как добавить картинку товара в AJAX поиск


Recommended Posts


<?php
define("AJAX_QUICKSEARCH_RESULT", 'text'); // dropdown or text
define("AJAX_QUICKSEARCH_DROPDOWN_SIZE", 5);
define("AJAX_QUICKSEARCH_LIMIT", 15);
$q = addslashes(preg_replace("%[^0-9a-zA-Zа-яА-Я\s]%iu", "", $_REQUEST['keywords']) );
$out = "";
if(isset($q) && vam_not_null($q)) {
$searchwords = explode(" ",$q);
$nosearchwords = sizeof($searchwords);
foreach($searchwords as $key => $value) {
if ($value == '')
unset($searchwords[$key]);
}
$searchwords = array_values($searchwords);
$nosearchwords = sizeof($searchwords);
foreach($searchwords as $key => $value) {
$booltje = '+' . $searchwords[$key] . '*';
$searchwords[$key] = $booltje;
}
$q = implode(" ",$searchwords);
$products_query = vam_db_query("select pd.products_id, pd.products_name, pd.products_keywords, p.products_model, p.products_image
from " . TABLE_PRODUCTS_DESCRIPTION . " pd
inner join " . TABLE_PRODUCTS . " p
on (p.products_id = pd.products_id)
where (match (pd.products_name) against ('" . $q . "' in boolean mode)
or match (p.products_model) against ('" . $q . "' in boolean mode) or match (p.products_ean) against ('" . $q . "' in boolean mode) or match (pd.products_keywords) against ('" . $q . "' in boolean mode)" .
($_REQUEST['search_in_description'] == '1' ? "or match (pd.products_description) against ('" . $q . "' in boolean mode)" : "") . ")
and p.products_status = '1'
and pd.language_id = '" . (int)$_SESSION['languages_id'] . "'
order by pd.products_name asc
limit " . AJAX_QUICKSEARCH_LIMIT);
if(vam_db_num_rows($products_query)) {
$out .= sprintf(TEXT_AJAX_QUICKSEARCH_TOP, AJAX_QUICKSEARCH_LIMIT) . '<br />';
$dropdown = array();
$out .= '<ul class="ajaxQuickFind">';
while($products = vam_db_fetch_array($products_query)) {
if ($products['products_image']==''){
$image = DIR_WS_INFO_IMAGES.'../noimage.gif';
}else{
$image = DIR_WS_INFO_IMAGES.$products['products_image'];
}
$out .= '<li class="ajaxQuickFind"><a rel=nofollow" href="' . vam_href_link(FILENAME_PRODUCT_INFO, vam_product_link($products['products_id'], $products['products_name']), 'NONSSL', false) . '"><img style="width:60px;" class="ajaximg" src="' . $image . '"/><span>' . $products['products_name'] . '</span></a></li>' . "\n";
$dropdown[] = array('id' => $products['products_id'],
'text' => $products['products_name']);
}
$out .= '</ul>' . "\n";
if(AJAX_QUICKSEARCH_RESULT == 'dropdown') {
$out .= vam_draw_pull_down_menu('AJAX_QUICKSEARCH_pid', $dropdown, '', 'onChange="this.form.submit();" size="' . AJAX_QUICKSEARCH_DROPDOWN_SIZE . '" class="ajaxQuickFind"') . vam_hide_session_id();
}
}
}
echo $out;
?>
[/CODE] вот готовый код, в нем правда еще добавлен поиск по штрихкоду а вот разборка в строчку
[CODE]
$products_query = vam_db_query("select pd.products_id, pd.products_name, pd.products_keywords, p.products_model
добавлен запрос на картинку товара т.е вот

$products_query = vam_db_query("select pd.products_id, pd.products_name, pd.products_keywords, p.products_model, p.products_image
[/code] далее проверяем, есть у товара картинка после
[code]
while($products = vam_db_fetch_array($products_query)) {
вставляем

if ($products['products_image']==''){
$image = DIR_WS_INFO_IMAGES.'../noimage.gif';
}else{
$image = DIR_WS_INFO_IMAGES.$products['products_image'];
}
[/code] в строчку
[code]
$out .= '<li class="ajaxQuickFind"><a rel=nofollow" href="' . vam_href_link(FILENAME_PRODUCT_INFO, vam_product_link($products['products_id'], $products['products_name']), 'NONSSL', false) . '"><span>' . $products['products_name'] . '</span></a></li>' . "\n";
добавлен вывод картинки, т.е вот

$out .= '<li class="ajaxQuickFind"><a rel=nofollow" href="' . vam_href_link(FILENAME_PRODUCT_INFO, vam_product_link($products['products_id'], $products['products_name']), 'NONSSL', false) . '"><img style="width:60px;" class="ajaximg" src="' . $image . '"/><span>' . $products['products_name'] . '</span></a></li>' . "\n";

[/code]

все. осталось стилями оформить по красивее.

Link to post
Share on other sites
  • 2 weeks later...
  • 2 years later...

А как-то можно это доработать, чтобы окно с результатами не раздвигала существующий блок, а как-бы накладывалась сверху, как в примере у Bomond (выше).

Link to post
Share on other sites
support

Можно конечно, в css стилях для этого блока укажите position: absolute;

По идее, должно помочь.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...