yf_shop_search user module| File | plugins/shop/modules/shop/yf_shop_search.class.php |
|---|---|
| Use | module('shop_search'), URL ?object=shop_search |
| Property | Default | Description |
|---|---|---|
| None declared in this class. | ||
public function prepare_str($string)
public function prepare_str($string)
{
$patrn = "/([\[\}\]\{\%\"\'\<\>\~\!\@\#\$\%\&\*\(\)\s\-\_\\:\;\+\=\|\?\№\.\\/\^\,])+/iu";
$patrn2 = ['<', '>'];
$string = str_replace($patrn2, '', $string);
$string = _strtolower(trim($string));
$string = preg_replace($patrn, ',', $string);
$string = trim($string, ',');
$str_search = explode(',', $string);
$rezult = $this->search_fast($str_search);
return $rezult;
}
public function search()
public function search()
{
if (($_GET['id'] ?? null) == 'fast') {
// TODO: fill with real code
}
$str_search = ($_POST['search'] ?? null);
$rezult = $this->prepare_str($str_search);
return $rezult;
}
public function search_fast($str_search)
public function search_fast($str_search)
{
$str_search2 = implode(' ', $str_search);
$str_search = implode('%', $str_search);
$sql = 'SELECT id FROM ' . db('shop_products') . ' WHERE name LIKE ';
$_sql = '';
$_sql = $sql . "'%" . $str_search . "%'";
$Q = db()->query($_sql);
$product_ids = '';
while ($product_id = db()->fetch_assoc($Q)) {
$product_ids .= $product_id['id'] . ',';
}
$product_ids = rtrim($product_ids, ',');
if ($product_ids == '') {
$replace = [
'str_search' => _prepare_html($str_search2),
'form_action' => process_url('./?object=shop&action=search&id=fast'),
];
return tpl()->parse('shop/no_search_results', $replace);
}
$replace = module('shop')->products_show($product_ids, $str_search2);
return $replace;
}