Files
wyczarujprezent.pl/modules/anblog/controllers/admin/AdminAnblogAjax.php
2025-07-03 20:56:08 +02:00

63 lines
1.5 KiB
PHP

<?php
/**
* 2024 Anvanto
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
*
* @author Anvanto <anvantoco@gmail.com>
* @copyright 2024 Anvanto
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
*/
use PrestaShop\PrestaShop\Core\Domain\Product\Query\SearchProducts;
if (!defined('_PS_VERSION_')) {
exit;
}
class AdminAnblogAjaxController extends ModuleAdminController
{
public function initContent()
{
$result = [];
if (Tools::isSubmit('action')) {
$actionName = Tools::getValue('action', '') . 'Action';
if (method_exists($this, $actionName)) {
$result = $this->$actionName();
}
}
die(json_encode($result));
}
public function searchProductsAction()
{
// $defaultCurrencyId = (int) $this->get('prestashop.adapter.legacy.configuration')->get('PS_CURRENCY_DEFAULT');
//$searchPhrase = $request->query->get('search_phrase');
$searchPhrase = Tools::getValue('q');
if (!$searchPhrase){
return [];
}
$foundProducts = Product::searchByName((int) $this->context->language->id, pSQL($searchPhrase));
if (!$foundProducts){
return [];
}
$products = [];
foreach ($foundProducts as $fProduct){
$products[] = [
'id' => $fProduct['id_product'],
'name' => $fProduct['name']
];
}
return $products;
}
}