Aw: suche nach eigenen Felder und Anzeige
<?php
/**
* @version 4.11.0 18.12.2014
* @author MAXXmarketing GmbH
* @package Jshopping
* @copyright Copyright (C) 2010 webdesigner-profi.de. All rights reserved.
* @license GNU/GPL
*/
defined('_JEXEC') or die('Restricted access');
Echo "search"
class jshopSearch{
private $search = '';
private $filters = array();
private $date_to;
private $date_from;
private $search_type;
private $order;
private $orderby;
private $adv_query;
private $adv_from;
private $adv_result;
private $order_query;
private $buildAdvQuery;
private $Jahr;
public function setSearch($val){
$this->search = $val;
}
public function setFilters($val){
$this->filters = $val;
}
public function setDateTo($val){
$this->date_to = $val;
}
public function setJahr($val){
$this->Jahr = $val;
}
public function setDateFrom($val){
$this->date_from = $val;
}
public function setSearchType($val){
$this->search_type = $val;
}
public function setOrder($val){
$this->order = $val;
}
public function setOrderby($val){
$this->orderby = $val;
}
public function getTotal(){
$db = JFactory::getDBO();
$this->buildAdvQuery();
$query = "SELECT count(distinct prod.product_id) FROM `#__jshopping_products` AS prod
LEFT JOIN `#__jshopping_products_to_categories` AS pr_cat ON pr_cat.product_id = prod.product_id
LEFT JOIN `#__jshopping_categories` AS cat ON pr_cat.category_id = cat.category_id
".$this->adv_from."
WHERE prod.product_publish = '1' AND cat.category_publish='1'
".$this->adv_query;
$db->setQuery($query);
return $db->loadResult();
}
public function getProducts($limitstart = null, $limit = null){
$db = JFactory::getDBO();
$this->buildAdvQuery();
$query = "SELECT ".$this->adv_result." FROM `#__jshopping_products` AS prod
LEFT JOIN `#__jshopping_products_to_categories` AS pr_cat ON pr_cat.product_id = prod.product_id
LEFT JOIN `#__jshopping_categories` AS cat ON pr_cat.category_id = cat.category_id
".$this->adv_from."
WHERE prod.product_publish = '1' AND cat.category_publish='1'
".$this->adv_query."
GROUP BY prod.product_id ".$this->order_query;
$db->setQuery($query, $limitstart, $limit);
$rows = $db->loadObjectList();
$rows = listProductUpdateData($rows);
addLinkToProducts($rows, 0, 1);
return $rows;
}
private function buildAdvQuery(){
if ($this->buildAdvQuery==1) return 0;
$jshopConfig = JSFactory::getConfig();
$dispatcher = JDispatcher::getInstance();
$db = JFactory::getDBO();
$product = JSFactory::getTable('product', 'jshop');
$orderbyq = getQuerySortDirection($this->order, $this->orderby);
$adv_query = "";
$adv_from = "";
$adv_result = $product->getBuildQueryListProductDefaultResult();
$product->getBuildQueryListProduct("search", "list", $this->filters, $adv_query, $adv_from, $adv_result;);
if ($this->date_to && checkMyDate($this->date_to)) {
$adv_query .= " AND prod.product_date_added <= '".$db->escape($this->date_to)."'";
}
if ($this->date_from && checkMyDate($this->date_from)) {
$adv_query .= " AND prod.product_date_added >= '".$db->escape($this->date_from)."'";
if ($this->$Jahr )) {
$adv_query .= " AND prod.product_Jahr =$Jahr '".$db->escape($this->Jahr)."'";
}
$where_search = "";
if ($this->search_type=="exact"){
$word = addcslashes($db->escape($this->search), "_%");
$tmp = array();
foreach($jshopConfig->product_search_fields as $field){
$tmp[] = "LOWER(".getDBFieldNameFromConfig($field).") LIKE '%".$word."%'";
}
$where_search = implode(' OR ', $tmp);
}else{
$words = explode(" ", $this->search);
$search_word = array();
foreach($words as $word){
$word = addcslashes($db->escape($word), "_%");
$tmp = array();
foreach($jshopConfig->product_search_fields as $field){
$tmp[] = "LOWER(".getDBFieldNameFromConfig($field).") LIKE '%".$word."%'";
}
$where_search_block = implode(' OR ', $tmp);
$search_word[] = "(".$where_search_block.")";
}
if ($this->search_type=="any"){
$where_search = implode(" OR ", $search_word);
}else{
$where_search = implode(" AND ", $search_word);
}
}
if ($where_search){
$adv_query .= " AND ($where_search)";
}
$orderbyf = $jshopConfig->sorting_products_field_s_select[$this->order];
$order_query = $product->getBuildQueryOrderListProduct($orderbyf, $orderbyq, $adv_from);
$dispatcher->trigger('onBeforeQueryGetProductList', array("search", &$adv_result, &$adv_from, &$adv_query, &$order_query, &$this->filters) );
$this->adv_result = $adv_result;
$this->adv_from = $adv_from;
$this->adv_query = $adv_query;
$this->order_query = $order_query;
$this->buildAdvQuery==1;
return 1;
}
}
Ist das so korrekt, ich bekomme nach der Suche immer alle Produkte angezeigt !
Hier noch die Form.PHP
<script type="text/javascript">var liveurl = '<?php print JURI::root()?>';</script>
<div class="jshop">
<h1><?php print _JSHOP_SEARCH ?></h1>
<h3>Suchen Sie mit dem Suchformular
oder treffen Sie eine Vorauswahl ueber die Kategorie.</h3>
<form action = "<?php print JURI::base()?>index.php" name = "form_ad_search" method = "get" onsubmit = "return validateFormAdvancedSearch('form_ad_search')">
<input type = "hidden" name = "option" value = "com_jshopping" />
<input type = "hidden" name = "controller" value = "search" />
<input type = "hidden" name = "task" value = "result" />
<input type = "hidden" name = "Itemid" value = "<?php print $this->Itemid ?>" />
<table class = "jshop" cellpadding = "6" cellspacing="0">
<TABLE BGCOLOR="#BBCCD1" WIDTH="525" BORDER="0" CELLPADDING="6" CELLSPACING="0" BGCOLOR="#ECE8D1">
<tr>
<td width="120">
<?php print _JSHOP_SEARCH_TEXT?>
</td>
<td>
<input type = "text" name = "search" class = "inputbox" style = "width:300px" />
</td>
<tr>
<td>
<?php print "Verfasser" ?>
</td>
<td>
<input type = "text" class = "inputbox" name = "Verfasser" id = "Verfasser" />
</td>
</tr>
<tr>
<td>
<?php print Titel?>
</td>
<td>
<input type = "text" name = "Titel" id = "Titel" class = "inputbox" style = "width:300px" />
</td>
<tr>
<td>
<?php print _JSHOP_SEARCH_VERLAG ?>
</td>
<td>
<input type = "text" class = "inputbox" name = "Verlag" id = "Verlag" />
</td>
</tr>
<tr>
<td>
<?php print "Erscheinungsjahr" ?>
<td>
<input type = "text" class = "inputbox" name = "Jahr" id = "Jahr" />
</td>
<tr>
</tr>
<tr>
<td>
<?php print _JSHOP_SEARCH_CATEGORIES ?>
</td>
<td>
<?php print $this->list_categories ?><br />
<input type = "checkbox" name = "include_subcat" id = "include_subcat" value = "1" />
<label for = "include_subcat"><?php print _JSHOP_SEARCH_INCLUDE_SUBCAT ?></label>
</td>
</tr>
<tr>
<td>
<?php /*print _JSHOP_SEARCH_MANUFACTURERS */?>
</td>
<td>
<?php /* print $this->list_manufacturers */ ?>
</td>
<td colspan="2" id="list_characteristics"><?php print $this->characteristics?></td>
</tr>
</table>
<div style="padding:6px;">
<input type = "submit" class="button" value = "<?php print _JSHOP_SEARCH ?> " />
</div>
</form>
</div>