Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
added manufacturers to the search
  • Loading branch information
davesaddle committed Aug 1, 2019
1 parent 15343c7 commit d1461a7
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @copyright Portions Copyright 2003-2006 The Zen Cart Team
* @copyright Portions Copyright 2003 osCommerce
* @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
* @version $Id: jscript_instantSearch.js 5 2018-09-01 18:34:47Z davewest $
* @version $Id: jscript_instantSearch.js 6 2019-08-01 18:34:47Z davewest $
*/


Expand Down Expand Up @@ -111,7 +111,7 @@ $(document).ready(function () {
var resultHtml = '';
$.each(data, function (i, item) {
//if any search result are found, a link will be created and placed into the instant search container
resultHtml += '<li><a href="' + generateLink(item.pc,item.l,item.pt) + '"><span class="alignRight">' + formatNumber(item.c) + '</span>' + highlightWord(replaceWord,item.q) + '</a></li>';
resultHtml += '<li><a href="' + generateLink(item.pc,item.l,item.pt,item.q) + '"><span class="alignRight">' + formatNumber(item.c) + '</span>' + highlightWord(replaceWord,item.q) + '</a></li>';
});

//added for the more link at the bottom uncomment if like it
Expand Down Expand Up @@ -163,16 +163,17 @@ function autoPositionContainer(inputBoxCurr, resltsContainer){
}

//this function creates the link back to the matching products or categories
function generateLink(productORcategory, productCategoryID, productInfopage)
function generateLink(productORcategory, productCategoryID, productInfopage, productKeyword)
{
var l = "";

if (productORcategory == "p"){
l = "index.php?main_page=" + productInfopage + "&products_id=" + productCategoryID;
}else{
}else if (productORcategory == "c"){
l = "index.php?main_page=index&cPath=" + productCategoryID;
}else {
l = "index.php?main_page=advanced_search_result&keyword=" + productKeyword + "&manufacturers_id=" + productCategoryID;
}

return l;

}
Expand Down
64 changes: 62 additions & 2 deletions INSTALL/searches.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @copyright Portions Copyright 2003-2006 The Zen Cart Team
* @copyright Portions Copyright 2003 osCommerce
* @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
* @version $Id: searches.php 5 2018-09-01 18:34:47Z davewest $
* @version $Id: searches.php 6 2019-08-01 18:34:47Z davewest $
*/


Expand Down Expand Up @@ -56,7 +56,7 @@
WHERE p.products_id = pd.products_id
AND p.products_status <> 0
AND pd.language_id = :languagesID:
AND ((products_name LIKE :wordSearchPlus:) OR (LEFT(pd.products_name,LENGTH(:wordSearch:)) SOUNDS LIKE :wordSearch:))
AND ((products_name LIKE :wordSearchPlus:) OR (LEFT(pd.products_name,LENGTH(:wordSearch:)) SOUNDS LIKE :wordSearch:) )
ORDER BY field(LEFT(pd.products_name,LENGTH(:wordSearch:)), :wordSearch:) DESC, pd.products_viewed DESC LIMIT " . $sqlLimit;


Expand Down Expand Up @@ -145,7 +145,45 @@
$dbCategories->MoveNext();
}
}

//similar to categories search but now we search witin manufacturers
$sqlManuf = "SELECT p.products_status, p.manufacturers_id, m.manufacturers_name
FROM " . TABLE_PRODUCTS . " p, " . TABLE_MANUFACTURERS . " m
WHERE p.manufacturers_id = m.manufacturers_id
AND p.products_status <> 0
AND (manufacturers_name LIKE :wordSearchPlus:)
ORDER BY field(LEFT(m.manufacturers_name,LENGTH(:wordSearch:)), :wordSearch:) DESC LIMIT " . $sqlLimit;;


//this protects use from sql injection - i think????
$sqlManuf = $db->bindVars($sqlManuf, ':wordSearch:', $wordSearch, 'string');
$sqlManuf = $db->bindVars($sqlManuf, ':wordSearchPlus:', $wordSearchPlus, 'string');

$dbManuf = $db->Execute($sqlManuf);

//this takes each item that was found in the results and places it into 2 separate arrays
if ($dbManuf->RecordCount() > 0) {
//this searches for the number of products with same manufacturer ID
$Manuf_count = ($CatCount) ? zen_count_products_for_manufacturer($dbManuf->fields['manufacturers_id']) : "";
$ManufResult = strip_tags($dbManuf->fields['manufacturers_name']);

if (strtolower(substr($ManufResult,0,strlen($wordSearch))) == strtolower($wordSearch)){
$results[] = array(
'q'=>$ManufResult,
'c'=>$Manuf_count,
'l'=>$dbManuf->fields['manufacturers_id'],
'pc'=>"m"
);
}else{
$resultsAddAfter[] = array(
'q'=>$ManufResult,
'c'=>$Manuf_count,
'l'=>$dbManuf->fields['manufacturers_id'],
'pc'=>"m"
);
}

}
}


Expand Down Expand Up @@ -175,5 +213,27 @@
//the results are now passed onto instantSearch.js
echo json_encode($results);

// Return the number of products for manufacturer
// TABLES: products, manufacturers
function zen_count_products_for_manufacturer($manufacturers_id, $include_inactive = false) {
global $db;
$products_count = 0;
if ($include_inactive == true) {
$products_query = "select count(products_id) as total
from " . TABLE_PRODUCTS . "
where manufacturers_id = '" . (int)$manufacturers_id . "'";

} else {
$products_query = "select count(products_id) as total
from " . TABLE_PRODUCTS . "
where manufacturers_id = '" . (int)$manufacturers_id . "'
and products_status = '1'";

}
$products = $db->Execute($products_query);
$products_count += $products->fields['total'];


return $products_count;
}
?>

0 comments on commit d1461a7

Please sign in to comment.