added category lister

This commit is contained in:
O K
2025-09-26 12:39:14 +03:00
parent f056d8df8b
commit 2d21de9cbd
2 changed files with 87 additions and 1 deletions

View File

@@ -0,0 +1,86 @@
<?php
/**
* Product Link Checker Product Data Generate Controller
*
* This controller generates a JSON feed of all products and their attribute combinations
* with detailed information for external services.
*/
use Symfony\Component\HttpFoundation\JsonResponse;
class ProductLinkCheckerCategoryModuleFrontController extends ModuleFrontController
{
public function init()
{
parent::init();
// Security check: Validate the token, same as the other controller
$token = Tools::getValue('token');
$storedToken = Configuration::get('PLC_SECURITY_TOKEN');
if (!$token || $token !== $storedToken) {
header('HTTP/1.1 403 Forbidden');
exit('Invalid security token.');
}
}
public function initContent()
{
parent::initContent();
header('Content-Type: application/json');
$categoriesData = [];
$collection = new PrestaShopCollection('Category');
$id_shop_filter = (int)Tools::getValue('plc_id_shop');
$id_lang_filter = (int)Tools::getValue('plc_id_lang');
// Determine which shops to scan
if ($id_shop_filter) {
$shop_ids = [$id_shop_filter];
} else {
$shop_ids = Shop::getShops(true, null, true);
}
// Determine which languages to scan
if ($id_lang_filter) {
$lang_ids = [$id_lang_filter];
} else {
$lang_ids = Language::getLanguages(true, false, true);
}
foreach ($shop_ids as $id_shop) {
foreach ($lang_ids as $id_lang) {
foreach ($collection as $cat) {
$category = new Category((int)$cat->id, $id_lang, $id_shop);
if (Tools::getValue('plc_only_active') && !$category->active) {
continue;
}
$data = [
'id_category' => $category->id,
'id_parent' => $category->id_parent,
'active' => $category->active,
];
Tools::getValue('plc_name') ? $data['name'] = $category->name : null;
Tools::getValue('plc_link_rewrite') ? $data['link_rewrite'] = $category->link_rewrite : null;
Tools::getValue('plc_description') ? $data['description'] = $category->description : null;
Tools::getValue('plc_additional_description') ? $data['additional_description'] = $category->additional_description : null;
Tools::getValue('plc_meta_title') ? $data['meta_title'] = $category->meta_title : null;
Tools::getValue('plc_meta_description') ? $data['meta_description'] = $category->meta_description : null;
$categoriesData[] = $data;
}
}
}
$response = new JsonResponse($categoriesData);
$response->send();
exit;
}
}

View File

@@ -7,7 +7,7 @@
* with detailed information for external services. * with detailed information for external services.
*/ */
class ProductLinkCheckerProductDataGenerateModuleFrontController extends ModuleFrontController class ProductLinkCheckerProductModuleFrontController extends ModuleFrontController
{ {
public function init() public function init()
{ {