feat(main): Make groups reorderable
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user