ver. 0.276: ShopOrder migration, Integrations cleanup, global admin search

This commit is contained in:
2026-02-15 16:37:57 +01:00
parent 0a2d13090f
commit d012a694c2
34 changed files with 2196 additions and 1063 deletions

View File

@@ -68,6 +68,159 @@ class SettingsController
exit;
}
/**
* Globalna wyszukiwarka admin (produkty + zamowienia) - AJAX.
*/
public function globalSearchAjax(): void
{
global $mdb;
$phrase = trim((string)\S::get('q'));
if ($phrase === '' || mb_strlen($phrase) < 2) {
echo json_encode([
'status' => 'ok',
'items' => [],
]);
exit;
}
$phrase = mb_substr($phrase, 0, 120);
$phraseNormalized = preg_replace('/\s+/', ' ', $phrase);
$phraseNormalized = trim((string)$phraseNormalized);
$like = '%' . $phrase . '%';
$likeNormalized = '%' . $phraseNormalized . '%';
$items = [];
$defaultLang = (string)\front\factory\Languages::default_language();
try {
$productStmt = $mdb->query(
'SELECT '
. 'p.id, p.ean, p.sku, p.parent_id, psl.name '
. 'FROM pp_shop_products AS p '
. 'LEFT JOIN pp_shop_products_langs AS psl ON psl.product_id = p.id AND psl.lang_id = :lang_id '
. 'WHERE '
. '(p.ean LIKE :q1 OR p.sku LIKE :q2 OR psl.name LIKE :q3) '
. 'AND p.archive != 1 '
. 'ORDER BY p.id DESC '
. 'LIMIT 15',
[
':lang_id' => $defaultLang,
':q1' => $like,
':q2' => $like,
':q3' => $like,
]
);
} catch (\Throwable $e) {
$productStmt = false;
}
$productRows = $productStmt ? $productStmt->fetchAll() : [];
if (is_array($productRows)) {
foreach ($productRows as $row) {
$productId = (int)($row['id'] ?? 0);
if ($productId <= 0) {
continue;
}
$name = trim((string)($row['name'] ?? ''));
if ($name === '') {
$name = 'Produkt #' . $productId;
}
$meta = [];
$sku = trim((string)($row['sku'] ?? ''));
$ean = trim((string)($row['ean'] ?? ''));
if ($sku !== '') {
$meta[] = 'SKU: ' . $sku;
}
if ($ean !== '') {
$meta[] = 'EAN: ' . $ean;
}
$items[] = [
'type' => 'product',
'title' => $name,
'subtitle' => implode(' | ', $meta),
'url' => '/admin/shop_product/product_edit/id=' . $productId,
];
}
}
try {
$orderStmt = $mdb->query(
'SELECT '
. 'id, number, client_name, client_surname, client_email, client_phone '
. 'FROM pp_shop_orders '
. 'WHERE '
. '('
. 'number LIKE :q1 '
. 'OR client_email LIKE :q2 '
. 'OR client_name LIKE :q3 '
. 'OR client_surname LIKE :q4 '
. 'OR client_phone LIKE :q5 '
. "OR CONCAT_WS(' ', TRIM(client_name), TRIM(client_surname)) LIKE :q6 "
. "OR CONCAT_WS(' ', TRIM(client_surname), TRIM(client_name)) LIKE :q7 "
. ') '
. 'ORDER BY id DESC '
. 'LIMIT 15',
[
':q1' => $like,
':q2' => $like,
':q3' => $like,
':q4' => $like,
':q5' => $like,
':q6' => $likeNormalized,
':q7' => $likeNormalized,
]
);
} catch (\Throwable $e) {
$orderStmt = false;
}
$orderRows = $orderStmt ? $orderStmt->fetchAll() : [];
if (is_array($orderRows)) {
foreach ($orderRows as $row) {
$orderId = (int)($row['id'] ?? 0);
if ($orderId <= 0) {
continue;
}
$orderNumber = trim((string)($row['number'] ?? ''));
$clientName = trim((string)($row['client_name'] ?? ''));
$clientSurname = trim((string)($row['client_surname'] ?? ''));
$clientEmail = trim((string)($row['client_email'] ?? ''));
$clientPhone = trim((string)($row['client_phone'] ?? ''));
$title = $orderNumber !== '' ? 'Zamówienie ' . $orderNumber : 'Zamówienie #' . $orderId;
$subtitleParts = [];
$fullName = trim($clientName . ' ' . $clientSurname);
if ($fullName !== '') {
$subtitleParts[] = $fullName;
}
if ($clientEmail !== '') {
$subtitleParts[] = $clientEmail;
}
if ($clientPhone !== '') {
$subtitleParts[] = $clientPhone;
}
$items[] = [
'type' => 'order',
'title' => $title,
'subtitle' => implode(' | ', $subtitleParts),
'url' => '/admin/shop_order/order_details/order_id=' . $orderId,
];
}
}
echo json_encode([
'status' => 'ok',
'items' => array_slice($items, 0, 20),
]);
exit;
}
/**
* Zapis ustawien (AJAX).
*/