feat(main): Add FAQ accordion

This commit is contained in:
2026-08-11 13:25:06 +02:00
parent 635c13a0ed
commit 1493081602
22 changed files with 459 additions and 4 deletions
+15
View File
@@ -3,6 +3,8 @@
namespace Websmid\CustomHtml\Module;
use Websmid\CustomHtml\Config\Config;
use PrestaShop\PrestaShop\Core\Grid\Data\GridData;
use PrestaShop\PrestaShop\Core\Grid\Record\RecordCollection;
use Tools;
trait AdminHooks
@@ -27,4 +29,17 @@ trait AdminHooks
$this->context->controller->addCSS($this->getPathUri() . 'views/css/admin/grid.css');
}
public function hookActionCustomhtmlblockGridDataModifier(array $params): void
{
$gridData = $params['data'];
$records = array_map(static function (array $row) {
$row['type'] = Config::BLOCK_TYPES[$row['type']] ?? $row['type'];
return $row;
}, $gridData->getRecords()->all());
$params['data'] = new GridData(new RecordCollection($records), $gridData->getRecordsTotal(), $gridData->getQuery());
}
}
+15
View File
@@ -3,6 +3,7 @@
namespace Websmid\CustomHtml\Module;
use Websmid\CustomHtml\Model\CustomHtmlBlock;
use Websmid\CustomHtml\Model\CustomHtmlFaq;
use Websmid\CustomHtml\Model\CustomHtmlGroup;
use Context;
@@ -54,6 +55,7 @@ trait DisplayHooks
}
$blocksByGroup = CustomHtmlBlock::getActiveByGroupIds(array_column($groups, 'id_ws_customhtml_group'));
$blocksByGroup = $this->attachFaqsToBlocks($blocksByGroup);
$groups = array_map(static function (array $group) use ($blocksByGroup) {
$group['blocks'] = $blocksByGroup[(int) $group['id_ws_customhtml_group']] ?? [];
@@ -65,4 +67,17 @@ trait DisplayHooks
return !empty($group['blocks']);
}));
}
private function attachFaqsToBlocks(array $blocksByGroup): array
{
return array_map(static function (array $blocks) {
return array_map(static function (array $block) {
if ($block['type'] === 'faq') {
$block['faqs'] = CustomHtmlFaq::getByBlockId((int) $block['id_ws_customhtml']);
}
return $block;
}, $blocks);
}, $blocksByGroup);
}
}
+44
View File
@@ -3,7 +3,9 @@
namespace Websmid\CustomHtml\Module;
use Websmid\CustomHtml\Config\Config;
use Context;
use Db;
use Hook;
use Language;
use Tab;
@@ -31,6 +33,11 @@ trait Install
return false;
}
if (!$this->registerGroupHooks()) {
error_log('[ws_customhtml] registerGroupHooks() failed');
return false;
}
return true;
}
@@ -55,6 +62,7 @@ trait Install
`id_ws_customhtml` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`id_ws_customhtml_group` INT(11) NOT NULL,
`title` VARCHAR(256) NOT NULL DEFAULT \'\',
`type` VARCHAR(32) NOT NULL DEFAULT \'html\',
`content` LONGTEXT,
`active` TINYINT(1) NOT NULL DEFAULT 1,
`show_title` TINYINT(1) NOT NULL DEFAULT 0,
@@ -65,6 +73,19 @@ trait Install
);
';
$sqlToExec[] = '
CREATE TABLE IF NOT EXISTS ' . _DB_PREFIX_ . 'ws_customhtml_faq (
`id_ws_customhtml_faq` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`id_ws_customhtml` INT(11) NOT NULL,
`question` VARCHAR(512) NOT NULL DEFAULT \'\',
`answer` TEXT,
`ordering` INT(11) NOT NULL DEFAULT 0,
`date_add` DATETIME NOT NULL,
`date_upd` DATETIME NOT NULL,
KEY `id_ws_customhtml` (`id_ws_customhtml`)
);
';
foreach ($sqlToExec as $sqlBlock) {
Db::getInstance()->execute(trim($sqlBlock));
}
@@ -83,6 +104,29 @@ trait Install
return true;
}
private function registerGroupHooks(): bool
{
$hookNames = Db::getInstance()->executeS(
'SELECT DISTINCT `hook_name` FROM `' . _DB_PREFIX_ . 'ws_customhtml_group`'
);
$idShop = (int) Context::getContext()->shop->id;
foreach ($hookNames as $row) {
$hookName = $row['hook_name'];
if (Hook::isModuleRegisteredOnHook($this, $hookName, $idShop)) {
continue;
}
if (!$this->registerHook($hookName)) {
return false;
}
}
return true;
}
private function registerTabs(array $moduleTabs): bool
{
$languages = Language::getLanguages(false);