Initial import: Carteasy Shop (Dev-Stand)
This commit is contained in:
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
// get for intelectra geraetezuordnung
|
||||
|
||||
/*if ($obj->attribute_17 != '') {
|
||||
$sql = "SELECT * FROM import_geraetezuordnung WHERE anr='".$obj->attribute_17."'";
|
||||
$result = $this->db->query($sql);
|
||||
}
|
||||
else {
|
||||
$sql = "SELECT * FROM import_geraetezuordnung WHERE anr='".$obj->number."'";
|
||||
$result = $this->db->query($sql);
|
||||
}*/
|
||||
|
||||
$result = null;
|
||||
|
||||
if (strlen($obj->number) == 8) {
|
||||
$sql = "SELECT g.*
|
||||
FROM krempl_geraete_22 g
|
||||
INNER JOIN krempl_artikelgeraet_22 ag ON g.id = ag.geraet
|
||||
INNER JOIN krempl_passendwie pw ON ag.ersatzteil = pw.id
|
||||
INNER JOIN items i ON pw.navisionid = i.krempl_id
|
||||
WHERE i.number = ".$this->db->real_escape_string($obj->number).";";
|
||||
$result = $this->db->query($sql);
|
||||
}
|
||||
|
||||
if ($obj->krempl_id && (!isset($result) || $result->num_rows < 1)) {
|
||||
$sql = "SELECT * FROM krempl_artikelgeraet_22 ka
|
||||
left join krempl_geraete_22 kg on kg.id=ka.geraet
|
||||
WHERE ka.ersatzteil=".$this->db->real_escape_string($obj->krempl_id)." AND not isnull(nr)";
|
||||
$result = $this->db->query($sql);
|
||||
}
|
||||
|
||||
$obj->geraetezuordnung = array();
|
||||
if ($result) {
|
||||
while ($obj1 = $result->fetch_object()) {
|
||||
$obj->geraetezuordnung[] = $obj1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// get parent warengruppe
|
||||
$sql = "select i.name, s.name, s2.name as wg from items i
|
||||
left join item_structure_assign isa on isa.item_id=i.id
|
||||
left join structure s on s.id=isa.structure_id
|
||||
left join structure s2 on s2.id=s.parent_id
|
||||
where i.id=".$obj->id.' AND s.active=1 LIMIT 1';
|
||||
$result = $this->db->query($sql);
|
||||
$parent_warengruppe = '';
|
||||
if ($result) {
|
||||
while ($obj1 = $result->fetch_object()) {
|
||||
$parent_warengruppe = $obj1->wg;
|
||||
}
|
||||
}
|
||||
|
||||
$table_data = array();
|
||||
foreach ($obj->geraetezuordnung as $geraet) {
|
||||
$nr1 = str_replace('#', '', $geraet->nr);
|
||||
$nr1 = str_replace('_', ' ', $nr1);
|
||||
$nr2 = str_replace('#', '', $geraet->produktionsstart);
|
||||
$nr2 = str_replace('_', ' ', $nr2);
|
||||
$nr3 = str_replace('#', '', $geraet->produktionsende);
|
||||
$nr3 = str_replace('_', ' ', $nr3);
|
||||
$nr3 = empty($nr3) ? "" : " - ".$nr3;
|
||||
$nr2 = $nr2.$nr3;
|
||||
$bezeichnungoriginal = str_replace('#', '', $geraet->bezeichnungoriginal);
|
||||
$bezeichnungoriginal = str_replace('_', ' ', $bezeichnungoriginal);
|
||||
$bezeichnungoriginal = preg_replace('/\r\n|\n|\r/', '', $bezeichnungoriginal);
|
||||
|
||||
// Überprüfe, ob $bezeichnungoriginal leer ist, und verwende $geraet->modellBezeichnung falls ja
|
||||
if (empty($bezeichnungoriginal) && !empty($geraet->modellBezeichnung)) {
|
||||
$bezeichnungoriginal = str_replace('#', '', $geraet->modellBezeichnung);
|
||||
$bezeichnungoriginal = str_replace('_', ' ', $bezeichnungoriginal);// Ersetze durch modellBezeichnung
|
||||
} elseif (empty($bezeichnungoriginal)) {
|
||||
$bezeichnungoriginal = "-"; // Oder einen Platzhalter, wenn auch modellBezeichnung leer ist
|
||||
}
|
||||
|
||||
|
||||
$einkaufsmoeglichkeitencached = $nr1." ".$nr2;
|
||||
$table_data[$einkaufsmoeglichkeitencached][$bezeichnungoriginal][] = array($nr1, $nr2);
|
||||
}
|
||||
|
||||
|
||||
$html = '<table border="0" cellpadding="2" cellspacing="0">';
|
||||
foreach ($table_data as $key => $marken) {
|
||||
$y = 0;
|
||||
$html .= '<tr class="intelectra_item_table_header"><td colspan="3"><h4><b>'.$obj->name.' passend zu '.$key.' '.$parent_warengruppe.'</b></h4></tr>';
|
||||
$html .= '<tr class="intelectra_item_table_header"><td>Geräte-/Modellbezeichnung</td><td>E-, Service-, Produktions- oder Hauptnummer</td><td>Zusatz-, F- oder Seriennummer oder Fertigungsdatum</td></tr>';
|
||||
foreach ($marken as $geraet => $nummern) {
|
||||
$color = 'intelectra_table_row1';
|
||||
if ($y % 2 == 1) {
|
||||
$color = 'intelectra_table_row2';
|
||||
}
|
||||
$z = 0;
|
||||
foreach ($nummern as $nummer) {
|
||||
if ($z == 0) {
|
||||
$html .= '<tr class="'.$color.'"><td>'.$geraet.'</td><td>'.$nummer[0].'</td><td>'.$nummer[1].'</td></tr>';
|
||||
} else {
|
||||
$html .= '<tr class="'.$color.'"><td> </td><td>'.$nummer[0].'</td><td>'.$nummer[1].'</td></tr>';
|
||||
}
|
||||
$z++;
|
||||
}
|
||||
$y++;
|
||||
}
|
||||
}
|
||||
$html .= '</table>';
|
||||
$obj->geraetezuordnung = $html;
|
||||
|
||||
|
||||
|
||||
// $int = $this->createIntWithTableData($html);
|
||||
|
||||
|
||||
// base price calc
|
||||
if ($obj->attribute_11 && $obj->attribute_15) {
|
||||
$obj->sample_unit = $obj->attribute_15;
|
||||
if (strstr($obj->sample_unit, '100')) {
|
||||
$obj->sample_price = $obj->shop_price_1 / ($obj->attribute_11 * 10);
|
||||
} else {
|
||||
$obj->sample_price = $obj->shop_price_1 / $obj->attribute_11;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,372 @@
|
||||
<?php
|
||||
|
||||
class ItemSearch {
|
||||
|
||||
private $config;
|
||||
protected $base_object;
|
||||
protected $db;
|
||||
|
||||
private $searchData = array();
|
||||
private $pageOffset = 0;
|
||||
|
||||
|
||||
public function __construct($base_object) {
|
||||
$this->config = $base_object->config;
|
||||
$this->db = $base_object->db;
|
||||
$this->base_object = $base_object;
|
||||
}
|
||||
|
||||
public function searchItems($searchString) {
|
||||
$timer_start = microtime(true);
|
||||
//echo "searchItems called<br>";
|
||||
|
||||
//$searchString_trimmed = trim($searchString);
|
||||
//$searchString_filtered = preg_replace("@[^\p{L}\p{N}]@sui", '', $searchString_trimmed);
|
||||
|
||||
$this->pageOffset = isset($_GET["page"]) ? ($_GET["page"] - 1) : 0;
|
||||
$results = Array();
|
||||
$results = array_merge($results, $this->_getItemByNumber($searchString));
|
||||
$results = array_merge($results, $this->_getItemByText($searchString));
|
||||
$results = array_merge($results, $this->_searchItemWithinItemsAndAssociations('', $searchString));
|
||||
$results = array_merge($results, $this->_getItembyKremplNumber($searchString));
|
||||
|
||||
$running_time = microtime(true) - $timer_start;
|
||||
|
||||
// Paginate result (make solution cleaner in the future)
|
||||
//$results = array_splice($results, 0, 20);
|
||||
|
||||
//echo "results number: ".count($results)."<br>";
|
||||
$result = array(
|
||||
'searchstring' => $searchString,
|
||||
'results' => count($results),
|
||||
'queryTime' => $running_time,
|
||||
'data' => $results
|
||||
);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function _searchItemWithinItemsAndAssociations($searchManufacturer, $searchString, $idsOnly = false, $searchManufacturer_filtered = false, $searchString_filtered = false, $searchRefinement_filtered = false) {
|
||||
$queries = $this->_queryLike($searchManufacturer_filtered, $searchString);
|
||||
|
||||
$results = array();
|
||||
|
||||
$idArray = array();
|
||||
foreach ($queries as $query) {
|
||||
$rs = $this->db->query($query);
|
||||
if (!$rs) break;
|
||||
|
||||
while ($I = $rs->fetch_object()) {
|
||||
if ($I->anumber) {
|
||||
$results[$I->anumber] = $I->anumber;
|
||||
$idArray[] = $I->anumber;
|
||||
}
|
||||
}
|
||||
}
|
||||
//$idArray = $this->_getIdsByNumbers($results, true, $searchRefinement_filtered);
|
||||
|
||||
return $idArray;
|
||||
}
|
||||
|
||||
private function _getIdsByNumbers($numbers, $withAlternatives = true, $refinement = false) {
|
||||
if (is_array($numbers) && count($numbers) > 0) {
|
||||
$numberList = implode("','", $numbers);
|
||||
|
||||
$queryAddAlternatives = '';
|
||||
if ($withAlternatives) {
|
||||
$queryAddAlternatives = " OR attribute_17 IN ('".$numberList."')";
|
||||
}
|
||||
|
||||
$queryAddRefinement = '';
|
||||
if ($refinement) {
|
||||
$refinement = $this->db->real_escape_string($refinement);
|
||||
$queryAddRefinement = "
|
||||
AND (
|
||||
name LIKE '%".$refinement."%'
|
||||
OR
|
||||
detail_description LIKE '%".$refinement."%'
|
||||
OR
|
||||
detail_description LIKE '%".htmlentities($refinement, null, 'UTF-8')."%'
|
||||
OR
|
||||
attribute_1 LIKE '%".$refinement."%'
|
||||
OR
|
||||
attribute_9 LIKE '%".$refinement."%'
|
||||
OR
|
||||
attribute_20 LIKE '%".$refinement."%'
|
||||
OR
|
||||
attribute_6 LIKE '%".$refinement."%'
|
||||
)
|
||||
";
|
||||
$queryAddRefinement = "
|
||||
AND (
|
||||
name LIKE '%".$refinement."%'
|
||||
OR
|
||||
attribute_1 LIKE '%".$refinement."%'
|
||||
OR
|
||||
attribute_9 LIKE '%".$refinement."%'
|
||||
OR
|
||||
attribute_20 LIKE '%".$refinement."%'
|
||||
OR
|
||||
attribute_6 LIKE '%".$refinement."%'
|
||||
)
|
||||
";
|
||||
}
|
||||
|
||||
/*$query = "
|
||||
SELECT
|
||||
id
|
||||
FROM
|
||||
items
|
||||
WHERE (
|
||||
number IN ('".$numberList."') OR
|
||||
number IN ('".$numberList."')
|
||||
".$queryAddAlternatives."
|
||||
)
|
||||
".$queryAddRefinement."
|
||||
";*/
|
||||
$query = "
|
||||
SELECT
|
||||
id
|
||||
FROM
|
||||
items
|
||||
WHERE
|
||||
number IN ('".$numberList."')
|
||||
LIMIT 150";
|
||||
$idArray = array();
|
||||
$rs = $this->db->query($query);
|
||||
if (!$rs) return $idArray;
|
||||
//echo '<pre>';echo $query;exit();
|
||||
while ($I = $rs->fetch_object()) {
|
||||
$idArray[$I->id] = $I->id;
|
||||
}
|
||||
|
||||
return $idArray;
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
private function _queryLike($searchManufacturer_filtered, $searchString_filtered) {
|
||||
//$searchManufacturer_filtered = $this->db->real_escape_string($searchManufacturer_filtered);
|
||||
$searchString_filtered = $this->db->real_escape_string($searchString_filtered);
|
||||
|
||||
$queries = array();
|
||||
|
||||
if (ctype_alpha($searchString_filtered)) {
|
||||
$queries[] = "
|
||||
SELECT
|
||||
id AS anumber
|
||||
FROM
|
||||
items
|
||||
WHERE
|
||||
active = 1
|
||||
AND
|
||||
parent_id = 0
|
||||
AND (
|
||||
REPLACE(REPLACE(REPLACE(vendor_item_number, ' ', ''), '/', ''), '-', '') LIKE '%".$searchString_filtered."%'
|
||||
OR
|
||||
-- mögliche Aufschrift
|
||||
attribute_4 LIKE '%".$searchString_filtered."%'
|
||||
OR
|
||||
-- Aufdrucke
|
||||
attribute_9 LIKE '%".$searchString_filtered."%'
|
||||
OR
|
||||
-- Synonyme
|
||||
attribute_6 LIKE '%".$searchString_filtered."%'
|
||||
)
|
||||
GROUP BY number LIMIT 150";
|
||||
} else {
|
||||
$forwardSlashPos = strpos($searchString_filtered, "/");
|
||||
if ($forwardSlashPos != false) {
|
||||
$searchString_filtered = substr($searchString_filtered, 0, $forwardSlashPos);
|
||||
}
|
||||
|
||||
if (!ctype_digit($searchString_filtered) || (ctype_digit($searchString_filtered) && strlen($searchString_filtered) >= 6)) {
|
||||
$queries[] = "
|
||||
SELECT DISTINCT i.id AS anumber FROM krempl_geraete_22 kg
|
||||
LEFT JOIN krempl_artikelgeraet_22 ka on ka.geraet=kg.id
|
||||
LEFT JOIN items i on i.krempl_id=ka.ersatzteil
|
||||
WHERE
|
||||
REPLACE(REPLACE(REPLACE(kg.nr, ' ', ''), '/', ''), '-', '') LIKE '%".$searchString_filtered."%'
|
||||
OR
|
||||
REPLACE(REPLACE(REPLACE(kg.bezeichnungoriginal, ' ', ''), '/', ''), '-', '') LIKE '%".$searchString_filtered."%'
|
||||
LIMIT 150";
|
||||
}
|
||||
|
||||
$queries[] = "
|
||||
SELECT
|
||||
DISTINCT items.id AS anumber
|
||||
FROM
|
||||
krempl_passendwie pw
|
||||
LEFT JOIN
|
||||
items on items.number=pw.navisionid OR items.attribute_7=pw.navisionid
|
||||
WHERE
|
||||
REPLACE(REPLACE(REPLACE(bestellcode, ' ', ''), '/', ''), '-', '') LIKE '%".$searchString_filtered."%'
|
||||
LIMIT 150";
|
||||
|
||||
$queries[] = "SELECT id AS anumber FROM items WHERE active = 1 AND
|
||||
REPLACE(REPLACE(REPLACE(attribute_20, ' ', ''), '/', ''), '-', '') LIKE '%".$searchString_filtered."%'
|
||||
GROUP BY number LIMIT 150";
|
||||
}
|
||||
return $queries;
|
||||
}
|
||||
|
||||
private function _getItemByNumber($searchString_ready) {
|
||||
if (!is_numeric($searchString_ready)) return Array();
|
||||
|
||||
$query = "
|
||||
SELECT id FROM items WHERE
|
||||
number = '".$this->db->real_escape_string($searchString_ready)."' OR
|
||||
attribute_7 = '".$this->db->real_escape_string($searchString_ready)."' OR
|
||||
ean_code = '".$this->db->real_escape_string($searchString_ready)."'
|
||||
LIMIT 150";
|
||||
|
||||
$rs = $this->db->query($query);
|
||||
|
||||
$idArray = array();
|
||||
if ($rs->num_rows > 0) {
|
||||
while ($I = $rs->fetch_object()) {
|
||||
$idArray[$I->id] = $I->id;
|
||||
}
|
||||
return $idArray;
|
||||
} else {
|
||||
return Array();
|
||||
}
|
||||
}
|
||||
|
||||
private function _getItemByText($searchString_ready) {
|
||||
$query = "
|
||||
SELECT id FROM items WHERE
|
||||
name LIKE '%".$this->db->real_escape_string($searchString_ready)."%' OR
|
||||
attribute_20 like '%".$this->db->real_escape_string($searchString_ready)."%' OR
|
||||
short_description like '%".$this->db->real_escape_string($searchString_ready)."%' OR
|
||||
detail_description like '%".$this->db->real_escape_string($searchString_ready)."%'
|
||||
LIMIT 150";
|
||||
$rs = $this->db->query($query);
|
||||
|
||||
$idArray = array();
|
||||
if ($rs->num_rows > 0) {
|
||||
while ($I = $rs->fetch_object()) {
|
||||
$idArray[$I->id] = $I->id;
|
||||
}
|
||||
return $idArray;
|
||||
} else {
|
||||
return Array();
|
||||
}
|
||||
}
|
||||
|
||||
private function _getItembyKremplNumberOld($searchString) {
|
||||
|
||||
$query = 'SELECT kg.id FROM `krempl_geraete_22` kg where nr LIKE "%'.$searchString.'%" or modellBezeichnung LIKE "%'.$searchString.'%";';
|
||||
$rs = $this->db->query($query);
|
||||
|
||||
$idArray = array();
|
||||
if ($rs->num_rows > 0) {
|
||||
$ids = $rs->fetch_all(MYSQLI_NUM)[0];
|
||||
foreach ($ids as $id) {
|
||||
$sql = "
|
||||
SELECT i.id FROM `krempl_item` ki
|
||||
left join krempl_artikelgeraet_22 ka on ki.id = ka.ersatzteil
|
||||
left join krempl_geraete_22 kg ON kg.id = ka.geraet
|
||||
left join items i ON ki.navisionid = i.attribute_7
|
||||
WHERE ka.geraet = ".$id." ORDER BY `ki`.`navisionid` ASC;
|
||||
";
|
||||
/* //TEST ZUM OPTIMIEREN
|
||||
$sql = "
|
||||
SELECT i.* FROM items i
|
||||
INNER JOIN krempl_item ki ON i.attribute_7 = ki.navisionid
|
||||
INNER JOIN krempl_artikelgeraet_22 ka ON ki.id = ka.ersatzteil
|
||||
WHERE ka.geraet IN (
|
||||
SELECT kg.id FROM `krempl_geraete_22` kg where nr LIKE "%AR 1268 TXNL%" or modellBezeichnung LIKE "%AR 1268 TXNL%"
|
||||
);
|
||||
";
|
||||
*/
|
||||
$rs = $this->db->query($sql);
|
||||
|
||||
if ($rs->num_rows > 0) {
|
||||
while ($I = $rs->fetch_object()) {
|
||||
if (isset($I->id))
|
||||
$idArray[$I->id] = $I->id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $idArray;
|
||||
}
|
||||
|
||||
private function _getItembyKremplNumber($searchString) {
|
||||
if (!is_numeric($searchString_ready)) return Array();
|
||||
|
||||
/*$query = '
|
||||
CREATE TEMPORARY TABLE temp_kg_ids (id INT);
|
||||
|
||||
INSERT INTO temp_kg_ids (id)
|
||||
SELECT kg.id
|
||||
FROM krempl_geraete_22 kg
|
||||
WHERE kg.nr LIKE "%'.$searchString.'%" OR kg.modellBezeichnung LIKE "%'.$searchString.'%";
|
||||
|
||||
CREATE TEMPORARY TABLE temp_ersatzteile (ersatzteil INT);
|
||||
|
||||
INSERT INTO temp_ersatzteile (ersatzteil)
|
||||
SELECT ka.ersatzteil
|
||||
FROM krempl_artikelgeraet_22 ka
|
||||
JOIN temp_kg_ids tempkg ON ka.geraet = tempkg.id;
|
||||
|
||||
SELECT i.id
|
||||
FROM items i
|
||||
JOIN krempl_item ki ON i.attribute_7 = ki.navisionid
|
||||
JOIN temp_ersatzteile tempersatz ON ki.id = tempersatz.ersatzteil
|
||||
ORDER BY ki.navisionid ASC;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS temp_kg_ids;
|
||||
DROP TEMPORARY TABLE IF EXISTS temp_ersatzteile;
|
||||
';
|
||||
$rs = $this->db->query($query);
|
||||
return $rs->fetch_all(MYSQLI_NUM)[0];*/
|
||||
|
||||
$query = 'SELECT kg.id FROM `krempl_geraete_22` kg where nr LIKE "%'.$searchString.'%" or modellBezeichnung LIKE "%'.$searchString.'%";';
|
||||
$rs = $this->db->query($query);
|
||||
if ($rs->num_rows <= 0) return Array();
|
||||
$res = $this->collapseResultRows($rs->fetch_all(MYSQLI_NUM));
|
||||
|
||||
$query = 'SELECT ka.ersatzteil from krempl_artikelgeraet_22 ka WHERE '.$this->queryOrConcat("ka.geraet", $res);
|
||||
$rs = $this->db->query($query);
|
||||
if ($rs->num_rows <= 0) return Array();
|
||||
$res = $this->collapseResultRows($rs->fetch_all(MYSQLI_NUM));
|
||||
|
||||
$query = 'SELECT ki.navisionid FROM krempl_item ki WHERE '.$this->queryOrConcat("ki.id", $res);
|
||||
$rs = $this->db->query($query);
|
||||
if ($rs->num_rows <= 0) return Array();
|
||||
$res = $this->collapseResultRows($rs->fetch_all(MYSQLI_NUM));
|
||||
|
||||
$query = 'SELECT i.id FROM items i WHERE '.$this->queryOrConcat("i.attribute_7", $res);
|
||||
$rs = $this->db->query($query);
|
||||
if ($rs->num_rows <= 0) return Array();
|
||||
|
||||
$idArray = Array();
|
||||
foreach ($this->collapseResultRows($rs->fetch_all(MYSQLI_NUM)) as $i) {
|
||||
$idArray[(int) $i] = (int) $i;
|
||||
}
|
||||
return $idArray;
|
||||
}
|
||||
|
||||
private function queryOrConcat($varName, $arr) {
|
||||
$ret = "$varName = ";
|
||||
if (count($arr) <= 1) return $ret.$arr[0];
|
||||
|
||||
for ($i = 0; $i < count($arr) - 1; $i++) {
|
||||
$ret .= $arr[$i]." OR $varName = ";
|
||||
}
|
||||
$ret .= $arr[count($arr) - 1];
|
||||
return $ret;
|
||||
}
|
||||
|
||||
private function collapseResultRows($arr) { // takes a multilevel array returned by mysqli->fetch_all(MYSQLI_NUM) and collapses it to a monodimensional array
|
||||
$ret = Array();
|
||||
foreach ($arr as $a) {
|
||||
$ret[] = $a[0];
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,369 @@
|
||||
<?php
|
||||
|
||||
class ItemSearch {
|
||||
|
||||
private $config;
|
||||
protected $base_object;
|
||||
protected $db;
|
||||
|
||||
private $searchData = array();
|
||||
|
||||
|
||||
public function __construct($base_object) {
|
||||
$this->config = $base_object->config;
|
||||
$this->db = $base_object->db;
|
||||
$this->base_object = $base_object;
|
||||
}
|
||||
|
||||
public function searchItems($searchString) {
|
||||
$timer_start = microtime(true);
|
||||
|
||||
//$searchString_trimmed = trim($searchString);
|
||||
//$searchString_filtered = preg_replace("@[^\p{L}\p{N}]@sui", '', $searchString_trimmed);
|
||||
|
||||
$results = Array();
|
||||
$results = array_merge($results, $this->_getItemByNumber($searchString));
|
||||
$results = array_merge($results, $this->_getItemByText($searchString));
|
||||
$results = array_merge($results, $this->_searchItemWithinItemsAndAssociations('', $searchString));
|
||||
$results = array_merge($results, $this->_getItembyKremplNumber($searchString));
|
||||
|
||||
$running_time = microtime(true) - $timer_start;
|
||||
|
||||
$result = array(
|
||||
'searchstring' => $searchString,
|
||||
'results' => count($results),
|
||||
'queryTime' => $running_time,
|
||||
'data' => $results
|
||||
);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function _searchItemWithinItemsAndAssociations($searchManufacturer, $searchString, $idsOnly = false, $searchManufacturer_filtered = false, $searchString_filtered = false, $searchRefinement_filtered = false) {
|
||||
$queries = $this->_queryLike($searchManufacturer_filtered, $searchString);
|
||||
|
||||
$results = array();
|
||||
|
||||
$idArray = array();
|
||||
foreach ($queries as $query) {
|
||||
|
||||
$rs = $this->db->query($query);
|
||||
if (!$rs) break;
|
||||
|
||||
while ($I = $rs->fetch_object()) {
|
||||
if ($I->anumber) {
|
||||
$results[$I->anumber] = $I->anumber;
|
||||
$idArray[] = $I->anumber;
|
||||
}
|
||||
}
|
||||
}
|
||||
//$idArray = $this->_getIdsByNumbers($results, true, $searchRefinement_filtered);
|
||||
|
||||
return $idArray;
|
||||
}
|
||||
|
||||
private function _getIdsByNumbers($numbers, $withAlternatives = true, $refinement = false) {
|
||||
if (is_array($numbers) && count($numbers) > 0) {
|
||||
$numberList = implode("','", $numbers);
|
||||
|
||||
$queryAddAlternatives = '';
|
||||
if ($withAlternatives) {
|
||||
$queryAddAlternatives = " OR attribute_17 IN ('".$numberList."')";
|
||||
}
|
||||
|
||||
$queryAddRefinement = '';
|
||||
if ($refinement) {
|
||||
$refinement = $this->db->real_escape_string($refinement);
|
||||
$queryAddRefinement = "
|
||||
AND (
|
||||
name LIKE '%".$refinement."%'
|
||||
OR
|
||||
detail_description LIKE '%".$refinement."%'
|
||||
OR
|
||||
detail_description LIKE '%".htmlentities($refinement, null, 'UTF-8')."%'
|
||||
OR
|
||||
attribute_1 LIKE '%".$refinement."%'
|
||||
OR
|
||||
attribute_9 LIKE '%".$refinement."%'
|
||||
OR
|
||||
attribute_20 LIKE '%".$refinement."%'
|
||||
OR
|
||||
attribute_6 LIKE '%".$refinement."%'
|
||||
)
|
||||
";
|
||||
$queryAddRefinement = "
|
||||
AND (
|
||||
name LIKE '%".$refinement."%'
|
||||
OR
|
||||
attribute_1 LIKE '%".$refinement."%'
|
||||
OR
|
||||
attribute_9 LIKE '%".$refinement."%'
|
||||
OR
|
||||
attribute_20 LIKE '%".$refinement."%'
|
||||
OR
|
||||
attribute_6 LIKE '%".$refinement."%'
|
||||
)
|
||||
";
|
||||
}
|
||||
|
||||
/*$query = "
|
||||
SELECT
|
||||
id
|
||||
FROM
|
||||
items
|
||||
WHERE (
|
||||
number IN ('".$numberList."') OR
|
||||
number IN ('".$numberList."')
|
||||
".$queryAddAlternatives."
|
||||
)
|
||||
".$queryAddRefinement."
|
||||
";*/
|
||||
$query = "
|
||||
SELECT
|
||||
id
|
||||
FROM
|
||||
items
|
||||
WHERE
|
||||
number IN ('".$numberList."')
|
||||
";
|
||||
$idArray = array();
|
||||
$rs = $this->db->query($query);
|
||||
if (!$rs) return $idArray;
|
||||
//echo '<pre>';echo $query;exit();
|
||||
while ($I = $rs->fetch_object()) {
|
||||
$idArray[$I->id] = $I->id;
|
||||
}
|
||||
|
||||
return $idArray;
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
private function _queryLike($searchManufacturer_filtered, $searchString_filtered) {
|
||||
$searchManufacturer_filtered = $this->db->real_escape_string($searchManufacturer_filtered);
|
||||
$searchString_filtered = $this->db->real_escape_string($searchString_filtered);
|
||||
|
||||
$queries = array();
|
||||
|
||||
if (ctype_alpha($searchString_filtered)) {
|
||||
$queries[] = "
|
||||
SELECT
|
||||
id AS anumber
|
||||
FROM
|
||||
items
|
||||
WHERE
|
||||
active = 1
|
||||
AND
|
||||
parent_id = 0
|
||||
AND (
|
||||
REPLACE(REPLACE(REPLACE(vendor_item_number, ' ', ''), '/', ''), '-', '') = '".$searchString_filtered."'
|
||||
OR
|
||||
REPLACE(REPLACE(REPLACE(name, ' ', ''), '/', ''), '-', '') LIKE '%".$searchString_filtered."%'
|
||||
OR
|
||||
-- mögliche Aufschrift
|
||||
REPLACE(REPLACE(REPLACE(attribute_4, ' ', ''), '/', ''), '-', '') LIKE '%".$searchString_filtered."%'
|
||||
OR
|
||||
-- Aufdrucke
|
||||
REPLACE(REPLACE(REPLACE(attribute_9, ' ', ''), '/', ''), '-', '') LIKE '%".$searchString_filtered."%'
|
||||
OR
|
||||
-- Merkmale
|
||||
REPLACE(REPLACE(REPLACE(attribute_8, ' ', ''), '/', ''), '-', '') LIKE '%".$searchString_filtered."%'
|
||||
OR
|
||||
-- Internes DB-Feld
|
||||
REPLACE(REPLACE(REPLACE(attribute_20, ' ', ''), '/', ''), '-', '') LIKE '%".$searchString_filtered."%'
|
||||
OR
|
||||
-- Synonyme
|
||||
REPLACE(REPLACE(REPLACE(attribute_6, ' ', ''), '/', ''), '-', '') LIKE '%".$searchString_filtered."%'
|
||||
)
|
||||
GROUP BY number LIMIT 150";
|
||||
} else {
|
||||
|
||||
if (!ctype_digit($searchString_filtered) || (ctype_digit($searchString_filtered) && strlen($searchString_filtered) >= 7)) {
|
||||
$queries[] = "
|
||||
SELECT DISTINCT i.id AS anumber FROM krempl_geraete kg
|
||||
LEFT JOIN krempl_artikelgeraet ka on ka.geraet=kg.id
|
||||
LEFT JOIN items i on i.krempl_id=ka.ersatzteil
|
||||
WHERE
|
||||
REPLACE(REPLACE(REPLACE(kg.nr, ' ', ''), '/', ''), '-', '') LIKE '%".$searchString_filtered."%'
|
||||
OR
|
||||
REPLACE(REPLACE(REPLACE(kg.bezeichnung1, ' ', ''), '/', ''), '-', '') LIKE '%".$searchString_filtered."%'
|
||||
LIMIT 150
|
||||
";
|
||||
}
|
||||
|
||||
$queries[] = "
|
||||
SELECT
|
||||
DISTINCT items.id AS anumber
|
||||
FROM
|
||||
krempl_passendwie pw
|
||||
LEFT JOIN
|
||||
items on items.number=pw.navisionid OR items.attribute_7=pw.navisionid
|
||||
WHERE
|
||||
REPLACE(REPLACE(REPLACE(bestellcode, ' ', ''), '/', ''), '-', '') LIKE '%".$searchString_filtered."%'
|
||||
LIMIT 150
|
||||
";
|
||||
|
||||
$queries[] = "SELECT id AS anumber FROM items WHERE active = 1 AND
|
||||
REPLACE(REPLACE(REPLACE(attribute_20, ' ', ''), '/', ''), '-', '') LIKE '%".$searchString_filtered."%'
|
||||
GROUP BY number LIMIT 50";
|
||||
}
|
||||
return $queries;
|
||||
}
|
||||
|
||||
private function _getItemByNumber($searchString_ready) {
|
||||
$query = "
|
||||
SELECT id FROM items WHERE
|
||||
number = '".$this->db->real_escape_string($searchString_ready)."' OR
|
||||
attribute_7 = '".$this->db->real_escape_string($searchString_ready)."' OR
|
||||
ean_code = '".$this->db->real_escape_string($searchString_ready)."'
|
||||
LIMIT 150
|
||||
";
|
||||
$rs = $this->db->query($query);
|
||||
|
||||
$idArray = array();
|
||||
if ($rs->num_rows > 0) {
|
||||
while ($I = $rs->fetch_object()) {
|
||||
$idArray[$I->id] = $I->id;
|
||||
}
|
||||
return $idArray;
|
||||
} else {
|
||||
return Array();
|
||||
}
|
||||
}
|
||||
|
||||
private function _getItemByText($searchString_ready) {
|
||||
$query = "
|
||||
SELECT id FROM items WHERE
|
||||
name LIKE '%".$this->db->real_escape_string($searchString_ready)."%' OR
|
||||
attribute_20 like '%".$this->db->real_escape_string($searchString_ready)."%' OR
|
||||
short_description like '%".$this->db->real_escape_string($searchString_ready)."%' OR
|
||||
detail_description like '%".$this->db->real_escape_string($searchString_ready)."%'
|
||||
LIMIT 150
|
||||
";
|
||||
$rs = $this->db->query($query);
|
||||
|
||||
$idArray = array();
|
||||
if ($rs->num_rows > 0) {
|
||||
while ($I = $rs->fetch_object()) {
|
||||
$idArray[$I->id] = $I->id;
|
||||
}
|
||||
return $idArray;
|
||||
} else {
|
||||
return Array();
|
||||
}
|
||||
}
|
||||
|
||||
private function _getItembyKremplNumberOld($searchString) {
|
||||
|
||||
$query = 'SELECT kg.id FROM `krempl_geraete_22` kg where nr LIKE "%'.$searchString.'%" or modellBezeichnung LIKE "%'.$searchString.'%";';
|
||||
$rs = $this->db->query($query);
|
||||
|
||||
$idArray = array();
|
||||
if ($rs->num_rows > 0) {
|
||||
$ids = $rs->fetch_all(MYSQLI_NUM)[0];
|
||||
foreach ($ids as $id) {
|
||||
$sql = "
|
||||
SELECT i.id FROM `krempl_item` ki
|
||||
left join krempl_artikelgeraet_22 ka on ki.id = ka.ersatzteil
|
||||
left join krempl_geraete_22 kg ON kg.id = ka.geraet
|
||||
left join items i ON ki.navisionid = i.attribute_7
|
||||
WHERE ka.geraet = ".$id." ORDER BY `ki`.`navisionid` ASC;
|
||||
";
|
||||
/* //TEST ZUM OPTIMIEREN
|
||||
$sql = "
|
||||
SELECT i.* FROM items i
|
||||
INNER JOIN krempl_item ki ON i.attribute_7 = ki.navisionid
|
||||
INNER JOIN krempl_artikelgeraet_22 ka ON ki.id = ka.ersatzteil
|
||||
WHERE ka.geraet IN (
|
||||
SELECT kg.id FROM `krempl_geraete_22` kg where nr LIKE "%AR 1268 TXNL%" or modellBezeichnung LIKE "%AR 1268 TXNL%"
|
||||
);
|
||||
";
|
||||
*/
|
||||
$rs = $this->db->query($sql);
|
||||
|
||||
if ($rs->num_rows > 0) {
|
||||
while ($I = $rs->fetch_object()) {
|
||||
if (isset($I->id))
|
||||
$idArray[$I->id] = $I->id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $idArray;
|
||||
}
|
||||
|
||||
private function _getItembyKremplNumber($searchString) {
|
||||
/*$query = '
|
||||
CREATE TEMPORARY TABLE temp_kg_ids (id INT);
|
||||
|
||||
INSERT INTO temp_kg_ids (id)
|
||||
SELECT kg.id
|
||||
FROM krempl_geraete_22 kg
|
||||
WHERE kg.nr LIKE "%'.$searchString.'%" OR kg.modellBezeichnung LIKE "%'.$searchString.'%";
|
||||
|
||||
CREATE TEMPORARY TABLE temp_ersatzteile (ersatzteil INT);
|
||||
|
||||
INSERT INTO temp_ersatzteile (ersatzteil)
|
||||
SELECT ka.ersatzteil
|
||||
FROM krempl_artikelgeraet_22 ka
|
||||
JOIN temp_kg_ids tempkg ON ka.geraet = tempkg.id;
|
||||
|
||||
SELECT i.id
|
||||
FROM items i
|
||||
JOIN krempl_item ki ON i.attribute_7 = ki.navisionid
|
||||
JOIN temp_ersatzteile tempersatz ON ki.id = tempersatz.ersatzteil
|
||||
ORDER BY ki.navisionid ASC;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS temp_kg_ids;
|
||||
DROP TEMPORARY TABLE IF EXISTS temp_ersatzteile;
|
||||
';
|
||||
$rs = $this->db->query($query);
|
||||
return $rs->fetch_all(MYSQLI_NUM)[0];*/
|
||||
|
||||
$query = 'SELECT kg.id FROM `krempl_geraete_22` kg where nr LIKE "%'.$searchString.'%" or modellBezeichnung LIKE "%'.$searchString.'%";';
|
||||
$rs = $this->db->query($query);
|
||||
if ($rs->num_rows <= 0) return Array();
|
||||
$res = $this->collapseResultRows($rs->fetch_all(MYSQLI_NUM));
|
||||
|
||||
$query = 'SELECT ka.ersatzteil from krempl_artikelgeraet_22 ka WHERE '.$this->queryOrConcat("ka.geraet", $res);
|
||||
$rs = $this->db->query($query);
|
||||
if ($rs->num_rows <= 0) return Array();
|
||||
$res = $this->collapseResultRows($rs->fetch_all(MYSQLI_NUM));
|
||||
|
||||
$query = 'SELECT ki.navisionid FROM krempl_item ki WHERE '.$this->queryOrConcat("ki.id", $res);
|
||||
$rs = $this->db->query($query);
|
||||
if ($rs->num_rows <= 0) return Array();
|
||||
$res = $this->collapseResultRows($rs->fetch_all(MYSQLI_NUM));
|
||||
|
||||
$query = 'SELECT i.id FROM items i WHERE '.$this->queryOrConcat("i.attribute_7", $res);
|
||||
$rs = $this->db->query($query);
|
||||
if ($rs->num_rows <= 0) return Array();
|
||||
|
||||
$idArray = Array();
|
||||
foreach ($this->collapseResultRows($rs->fetch_all(MYSQLI_NUM)) as $i) {
|
||||
$idArray[(int) $i] = (int) $i;
|
||||
}
|
||||
return $idArray;
|
||||
}
|
||||
|
||||
private function queryOrConcat($varName, $arr) {
|
||||
$ret = "$varName = ";
|
||||
if (count($arr) <= 1) return $ret.$arr[0];
|
||||
|
||||
for ($i = 0; $i < count($arr) - 1; $i++) {
|
||||
$ret .= $arr[$i]." OR $varName = ";
|
||||
}
|
||||
$ret .= $arr[count($arr) - 1];
|
||||
return $ret;
|
||||
}
|
||||
|
||||
private function collapseResultRows($arr) { // takes a multilevel array returned by mysqli->fetch_all(MYSQLI_NUM) and collapses it to a monodimensional array
|
||||
$ret = Array();
|
||||
foreach ($arr as $a) {
|
||||
$ret[] = $a[0];
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
$matchingItemNumberFirst = true;
|
||||
|
||||
include_once 'itemsearch.class.php';
|
||||
|
||||
$searchString = $search['search_item'];
|
||||
$ItemsClass = new ItemSearch($this->base_object);
|
||||
|
||||
$strings = explode(' ', $searchString);
|
||||
if (count($strings) == 1) {
|
||||
$searchString = trim($searchString);
|
||||
} else {
|
||||
$searchString = '';
|
||||
$string_type = 0;
|
||||
$strings = array_reverse($strings);
|
||||
foreach ($strings as $str) {
|
||||
$str = trim($str);
|
||||
// ganzzahl
|
||||
if (ctype_digit($str)) {
|
||||
$searchString = $str;
|
||||
$string_type = 2;
|
||||
} else if (!ctype_alpha($str) && $string_type != 2) {
|
||||
$searchString = $str;
|
||||
$string_type = 1;
|
||||
} else if ($string_type == 0) {
|
||||
$searchString = $str;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$result = $ItemsClass->searchItems($searchString);
|
||||
|
||||
if (!isset($this->db)) {
|
||||
$this->db = $this->base_object->db;
|
||||
}
|
||||
|
||||
if ($result['data'] && count($result['data']) > 0) {
|
||||
if (isset($search['item_category']) && $search['item_category'] > 0) {
|
||||
$sql = "
|
||||
SELECT
|
||||
i.*,
|
||||
i.default_image_file_name AS file_name,
|
||||
ip.price_1, ip.bargain_price_1
|
||||
FROM
|
||||
item_prices ip
|
||||
RIGHT JOIN
|
||||
items i
|
||||
ON
|
||||
i.id = ip.item_id
|
||||
AND
|
||||
ip.customergroup_id = ".$this->db->real_escape_string($this->base_object->customer_group->price_group_id)."
|
||||
RIGHT JOIN
|
||||
item_structure_assign isa
|
||||
ON
|
||||
i.id = isa.item_id
|
||||
WHERE
|
||||
i.active = 1
|
||||
AND
|
||||
i.id IN (".implode(',', $result['data']).")
|
||||
AND
|
||||
i.parent_id = 0
|
||||
AND
|
||||
isa.structure_id = ".$this->db->real_escape_string($search['item_category'])."
|
||||
GROUP BY
|
||||
i.id
|
||||
ORDER BY
|
||||
i.name DESC
|
||||
";
|
||||
} else {
|
||||
$sql = "
|
||||
SELECT
|
||||
i.*,
|
||||
i.default_image_file_name AS file_name,
|
||||
ip.price_1, ip.bargain_price_1
|
||||
FROM
|
||||
item_prices ip
|
||||
RIGHT JOIN
|
||||
items i
|
||||
ON
|
||||
i.id = ip.item_id
|
||||
AND
|
||||
ip.customergroup_id = ".$this->db->real_escape_string($this->base_object->customer_group->price_group_id)."
|
||||
WHERE
|
||||
i.active = 1
|
||||
AND
|
||||
i.id IN (".implode(',', $result['data']).")
|
||||
AND
|
||||
parent_id = 0
|
||||
GROUP BY
|
||||
i.id
|
||||
ORDER BY
|
||||
i.name DESC
|
||||
";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
if (!is_array($item_ids) || count($item_ids) <= 0) {
|
||||
include_once 'itemsearch.class.php';
|
||||
|
||||
$ItemsClass = new ItemSearch($this->base_object);
|
||||
//$result = $ItemsClass->searchItems($search['search_item'], true);
|
||||
|
||||
$item_ids = $result['data'];
|
||||
}
|
||||
|
||||
if (is_array($item_ids) && count($item_ids) > 0) {
|
||||
$sql = "
|
||||
SELECT
|
||||
wg.id,
|
||||
count(wg.id) AS found_items
|
||||
FROM
|
||||
structure wg
|
||||
LEFT JOIN
|
||||
item_structure_assign isa
|
||||
ON
|
||||
wg.id = isa.structure_id
|
||||
WHERE
|
||||
isa.item_id IN (".implode(',', $item_ids).")
|
||||
AND
|
||||
wg.active=1
|
||||
GROUP BY
|
||||
wg.id
|
||||
";
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
include_once 'itemsearch.class.php';
|
||||
|
||||
$ItemsClass = new ItemSearch($this->base_object);
|
||||
$result = $ItemsClass->searchItems($search);
|
||||
|
||||
$this->layout_object->assign('item_search', $result);
|
||||
|
||||
$return = $this->layout_object->_fetch('live_search.tpl');
|
||||
Reference in New Issue
Block a user