_setResourceModel(ConfigResource::class, ConfigCollection::class); } public function beforeSave() { $items = []; $allowedCodes = [ 'registration', 'first_shipping_address', 'order_earned', 'review_text', 'review_media', 'social_share', ]; $value = $this->getValue(); if (is_array($value)) { unset($value['__empty']); foreach ($value as $row) { if (!is_array($row)) { continue; } $code = strtolower(trim((string)($row['code'] ?? ''))); $points = max(0.0, (float)($row['points'] ?? 0)); $name = trim((string)($row['name'] ?? '')); $reason = trim((string)($row['reason'] ?? '')); if (!in_array($code, $allowedCodes, true) || $name === '') { continue; } $items[$code] = ['code' => $code, 'points' => $points, 'name' => $name, 'reason' => $reason]; } } $this->setValue(array_values($items)); return parent::beforeSave(); } }