Skip to content

Commit

Permalink
Merge pull request #12 from Extrabash/patch-6
Browse files Browse the repository at this point in the history
Поиск по нескольким словам
  • Loading branch information
osben authored Feb 25, 2019
2 parents 9409e49 + 5c030c3 commit c094428
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion ajax/search_products.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,17 @@ public function fetch()

if (!empty($result->query)) {
$kw = $this->db->escape($result->query);
$kw = preg_replace('/\s{2,}/', ' ', trim($kw));
$kw_array = explode(' ', $kw);
$kw_filter = '';
foreach ($kw_array as $kw1) {
$kw_filter .= $simpla->db->placehold("AND (p.name LIKE '%$kw1%' OR p.meta_keywords LIKE '%$kw1%' OR p.id in (SELECT product_id FROM __variants WHERE sku LIKE '%$kw1%')) ");
}

$this->db->query("SELECT p.id, p.name, i.filename as image FROM __products p
LEFT JOIN __images i ON i.product_id=p.id AND i.position=(SELECT MIN(position) FROM __images WHERE product_id=p.id LIMIT 1)
WHERE (p.name LIKE '%$kw%' OR p.meta_keywords LIKE '%$kw%' OR p.id in (SELECT product_id FROM __variants WHERE sku LIKE '%$kw%'))
WHERE 1
$kw_filter
AND p.visible=1
GROUP BY p.id
ORDER BY p.name
Expand Down

0 comments on commit c094428

Please sign in to comment.