getContainer()->getPermissionsService()->currentUserCanWrite(Entities::SERVICES)) { throw new AccessDeniedException('You are not allowed to update bookable services positions.'); } $result = new CommandResult(); $services = []; foreach ((array)$command->getFields()['services'] as $service) { $service = ServiceFactory::create($service); if (!$service instanceof Service) { $result->setResult(CommandResult::RESULT_ERROR); $result->setMessage('Could not update bookable services positions.'); return $result; } $services[] = $service; } /** @var ServiceRepository $serviceRepository */ $serviceRepository = $this->container->get('domain.bookable.service.repository'); foreach ($services as $service) { $serviceRepository->update($service->getId()->getValue(), $service); } /** @var SettingsService $settingsService */ $settingsService = $this->getContainer()->get('domain.settings.service'); $settings = $settingsService->getAllSettingsCategorized(); $settings['general']['sortingServices'] = $command->getFields()['sorting']; $settingsService->setAllSettings($settings); $result->setResult(CommandResult::RESULT_SUCCESS); $result->setMessage('Successfully updated bookable services positions.'); return $result; } }