_setResourceModel(ConfigResource::class, ConfigCollection::class); } public function beforeSave() { $items = []; $value = $this->getValue(); if (is_array($value)) { unset($value['__empty']); foreach ($value as $row) { if (!is_array($row)) { continue; } $label = trim((string)($row['label'] ?? '')); $threshold = max(0.0, (float)($row['threshold'] ?? 0)); $multiplier = (float)($row['multiplier'] ?? 0); if ($label === '' || $multiplier <= 0) { continue; } $items[] = ['label' => $label, 'threshold' => $threshold, 'multiplier' => $multiplier]; } } usort($items, static fn(array $left, array $right): int => $left['threshold'] <=> $right['threshold']); $this->setValue($items); return parent::beforeSave(); } }