feat(main): Make groups reorderable

This commit is contained in:
2026-08-13 16:42:17 +02:00
parent 34fb95a699
commit e804c37175
10 changed files with 93 additions and 4 deletions
@@ -5,6 +5,7 @@ namespace Websmid\CustomHtml\Form\DataHandler;
use PrestaShop\PrestaShop\Core\Form\IdentifiableObject\DataHandler\FormDataHandlerInterface;
use Websmid\CustomHtml\Model\CustomHtmlGroup;
use Context;
use Db;
use Hook;
use Module;
use Validate;
@@ -17,7 +18,7 @@ final class CustomHtmlGroupDataHandler implements FormDataHandlerInterface
$group->title = (string) $formData['title'];
$group->hook_name = (string) $formData['hook_name'];
$group->active = (int) $formData['active'];
$group->ordering = 0;
$group->ordering = $this->getNextOrdering();
if (!$group->add()) {
return false;
@@ -28,6 +29,15 @@ final class CustomHtmlGroupDataHandler implements FormDataHandlerInterface
return $group->id;
}
private function getNextOrdering(): int
{
$maxOrdering = Db::getInstance()->getValue(
'SELECT MAX(`ordering`) FROM `' . _DB_PREFIX_ . 'ws_customhtml_group`'
);
return $maxOrdering !== false ? ((int) $maxOrdering + 1) : 0;
}
public function update($id, array $formData)
{
$group = new CustomHtmlGroup((int) $id);