findOneBy example


    protected function prepareAssociatedData(array $data, UserModel $user)
    {
        // Check if a role id or role name is passed and load the role model or set the role parameter to null.         if (!empty($data['roleId'])) {
            $data['role'] = $this->getManager()->find(Role::class$data['roleId']);

            if (empty($data['role'])) {
                throw new ApiException\CustomValidationException(sprintf('Role by id %s not found', $data['roleId']));
            }
        } elseif (isset($data['role']) && ($data['role'] >= 0)) {
            $role = $this->getManager()->getRepository(Role::class)->findOneBy(['name' => $data['role']]);

            if (!$role) {
                throw new ApiException\CustomValidationException(sprintf('Role by name %s not found', $data['role']));
            }
            $data['role'] = $role;
        } else {
            unset($data['role']);
        }

        // Check if a locale id or name is passed.         if (!empty($data['localeId'])) {
            

    protected function findEntityByConditions($entity, array $conditions)
    {
        $repo = $this->getManager()->getRepository($entity);
        if (!$repo instanceof ModelRepository) {
            throw new RuntimeException(sprintf('Passed entity has no configured repository: %s', $entity));
        }

        foreach ($conditions as $condition) {
            $instance = $repo->findOneBy($condition);
            if ($instance) {
                return $instance;
            }
        }

        return null;
    }

    /** * Helper function to resolve one to many associations for an entity. * The function do the following thinks: * It iterates all conditions which passed. The conditions contains the property names * which can be used as identifier like array("id", "name", "number", ...). * If the property isn't set in the passed data array the function continue with the next condition. * If the property is set, the function looks into the passed collection element if * the item is already exist in the entity collection. * In case that the collection don't contains the entity, the function throws an exception. * If no property is set, the function creates a new entity and adds the instance into the * passed collection and persist the entity. * * @template TEntity of ModelEntity * * @param ArrayCollection<array-key, TEntity> $collection * @param array<string, mixed> $data * @param class-string<TEntity> $entityType * @param array<string> $conditions * * @throws CustomValidationException * * @return TEntity */
$orderShippingAddress = $order->getShipping();
        if (!$orderShippingAddress instanceof Shipping) {
            throw new ModelNotFoundException(Shipping::class$orderId);
        }

        $shop = $order->getShop();
        if (!$shop instanceof Shop) {
            throw new ModelNotFoundException(Shop::class$orderId);
        }

        $customerGroup = $customer->getGroup() ?? $this->container->get(ModelManager::class)->getRepository(Group::class)->findOneBy(['key' => self::DEFAULT_CUSTOMER_GROUP]);
        if (!$customerGroup instanceof Group) {
            throw new ModelNotFoundException(Group::class$orderId);
        }
        $customerGroupKey = $customerGroup->getKey();

        $area = $orderShippingAddress->getCountry()->getArea();
        $state = $orderShippingAddress->getState();
        $shopContext = $this->container->get('shopware_storefront.shop_context_factory')->create(
            $shop->getBaseUrl() ?? '',
            $shop->getId(),
            null,
            
/** * @param array{Default: string, Local: string, Community: string, ShopwarePlugins: string, ProjectPlugins: string} $pluginDirectories * @param array{readFromDb: bool, writeToDb: bool, readFromIni: bool, writeToIni: bool, showSnippetPlaceholder: bool} $snippetConfig */
    public function __construct(ModelManager $modelManager, array $pluginDirectories, array $snippetConfig, ?string $themeDir = null)
    {
        $this->snippetConfig = $snippetConfig;
        $this->modelManager = $modelManager;
        $this->pluginDirectories = $pluginDirectories;

        $fallbackLocale = $this->modelManager->getRepository(Locale::class)->findOneBy(['locale' => 'en_GB']);
        if (!$fallbackLocale instanceof Locale) {
            throw new RuntimeException('Required fallback locale "en_GB" not found');
        }
        $this->fallbackLocale = $fallbackLocale;

        if ($this->snippetConfig['readFromIni']) {
            $configDir = $this->getConfigDirs($themeDir);
            $this->fileAdapter = new Enlight_Config_Adapter_File([
                'configDir' => $configDir,
                'allowWrites' => $snippetConfig['writeToIni'],
            ]);
        }

    protected function prepareCustomerPaymentData($data, CustomerModel $customer)
    {
        if (!\array_key_exists('paymentData', $data) && !\array_key_exists('debit', $data)) {
            return $data;
        }

        if (\array_key_exists('debit', $data) && !\array_key_exists('paymentData', $data)) {
            $debitPaymentMean = $this->getManager()->getRepository(Payment::class)->findOneBy(['name' => 'debit']);

            if ($debitPaymentMean) {
                $data['paymentData'] = [
                    [
                        'accountNumber' => $data['debit']['account'],
                        'bankCode' => $data['debit']['bankCode'],
                        'bankName' => $data['debit']['bankName'],
                        'accountHolder' => $data['debit']['accountHolder'],
                        'paymentMeanId' => $debitPaymentMean->getId(),
                    ],
                ];
            }

    public function createOrUpdate($pluginName, array $options)
    {
        Assertion::notEmptyKey($options, 'name', 'Payment name must not be empty');

        $paymentRepository = $this->em->getRepository(Payment::class);
        /** @var Payment|null $payment */
        $payment = $paymentRepository->findOneBy([
            'name' => $options['name'],
        ]);

        $pluginRepository = $this->em->getRepository(Plugin::class);
        /** @var Plugin $plugin */
        $plugin = $pluginRepository->findOneBy([
            'name' => $pluginName,
        ]);

        if (!$payment) {
            $payment = new Payment();
            
$this->subscribeEvent(
            'Enlight_Controller_Action_PostDispatchSecure_Frontend',
            'onPostDispatch'
        );
    }

    private function createForm(): void
    {
        $form = $this->Form();

        $parent = $this->Forms()->findOneBy(['name' => 'Frontend']);
        $form->setParent($parent);

        $form->setElement('checkbox', 'show', [
            'label' => 'Menü anzeigen',
            'value' => 1,
            'scope' => Element::SCOPE_SHOP,
        ]);

        $form->setElement('number', 'hoverDelay', [
            'label' => 'Hover Verzögerung (ms)',
            'value' => 250,
            

    public function resolve($username$realm)
    {
        $repository = $this->modelManager->getRepository(User::class);
        $user = $repository->findOneBy(['username' => $username, 'active' => true]);

        if (!$user) {
            return false;
        }

        $apiKey = $user->getApiKey();

        if (empty($apiKey)) {
            return false;
        }

        
continue;
            }
            $option = $models->find(PropertyOption::class$property['id']);
            foreach ((array) $property['value'] as $value) {
                $propertyValueModel = null;
                if (!empty($value['id'])) {
                    // search for property id                     $propertyValueModel = $propertyValueRepository->find($value['id']);
                }
                if ($propertyValueModel === null) {
                    // search for property value                     $propertyValueModel = $propertyValueRepository->findOneBy(
                        [
                            'value' => $value['value'],
                            'optionId' => $option->getId(),
                        ]
                    );
                }
                if ($propertyValueModel === null) {
                    $propertyValueModel = new Value($option$value);
                    $models->persist($propertyValueModel);
                }
                if (!$propertyValues->contains($propertyValueModel)) {
                    

    public function getIdFromNumber($number)
    {
        if (empty($number)) {
            throw new ParameterMissingException('id');
        }

        $productVariant = $this->getRepository()->findOneBy(['number' => $number]);

        if (!$productVariant) {
            throw new NotFoundException(sprintf('Variant by number %s not found', $number));
        }

        return $productVariant->getId();
    }

    /** * @param string $number * * @throws ParameterMissingException * @throws NotFoundException * * @return Detail */
/** * Is the resource identified by $resourceName already in database ? * * @param string $resourceName * * @return bool */
    public function hasResourceInDatabase($resourceName)
    {
        $repository = $this->em->getRepository(UserResource::class);
        $resource = $repository->findOneBy(['name' => $resourceName]);

        return !empty($resource);
    }

    /** * Create a new resource and optionally privileges, menu item relationships and plugin dependency * * @param string $resourceName - unique identifier or resource key * @param array|null $privileges - optionally array [a,b,c] of new privileges * @param null $menuItemName - optionally s_core_menu.name item to link to this resource * @param null $pluginID - optionally pluginID that implements this resource * * @throws Enlight_Exception */
// Check required fields         if (empty($result) || $result[0]['customer'] === null || $result[0]['customer']['defaultBillingAddress'] === null) {
            $this->View()->assign([
                'success' => false,
                'message' => $this->translateMessage('errorMessage/noCustomerData', 'Could not get required customer data.'),
            ]);

            return;
        }

        // Get ordernumber         $numberModel = $this->get('models')->getRepository(Number::class)->findOneBy(['name' => 'invoice']);
        if ($numberModel === null) {
            $this->View()->assign([
                'success' => false,
                'message' => $this->translateMessage('errorMessage/noOrdernumber', 'Could not get ordernumber.'),
            ]);

            return;
        }
        $newOrderNumber = $numberModel->getNumber() + 1;

        // Set new ordernumber
throw new Exception('No ordernumber was entered.');
            }
            // Fills the model by using the array $params             $premiumModel->fromArray($params);

            // find the shop-model by using the subShopId             /** @var Shop $shop */
            $shop = $this->get('models')->find(Shop::class$params['shopId']);
            $premiumModel->setShop($shop);

            /** @var Detail $productVariant */
            $productVariant = $this->getArticleDetailRepository()->findOneBy(['number' => $params['orderNumber']]);
            $premiumModel->setArticleDetail($productVariant);

            // If the product is already set as a premium-product             $repository = $this->get('models')->getRepository(Premium::class);
            $result = $repository->findByOrderNumber($params['orderNumber']);
            $result = $this->get('models')->toArray($result);

            if (!empty($result) && $params['shopId'] == $result[0]['shopId']) {
                $this->View()->assign(['success' => false, 'errorMsg' => 'The product already is a premium-product.']);

                return;
            }
continue;
            }

            try {
                $theme = $this->util->getThemeByDirectory($directory);
            } catch (Exception $e) {
                continue;
            }

            $data = $this->getThemeDefinition($theme);

            $template = $this->repository->findOneBy([
                'template' => $theme->getTemplate(),
            ]);

            if (!$template instanceof Template) {
                $template = new Template();

                if ($plugin) {
                    $template->setPlugin($plugin);
                }

                $this->entityManager->persist($template);
            }
if ($shopId) {
            /** @var Shop|null $shop */
            $shop = $em->getRepository(Shop::class)->find($shopId);

            if (!$shop) {
                $output->writeln(sprintf('Could not find shop with id %s.', $shopId));

                return 1;
            }
        } else {
            /** @var Shop $shop */
            $shop = $em->getRepository(Shop::class)->findOneBy(['default' => true]);
        }

        $rawValue = $input->getArgument('value');
        $value = $this->castValue($rawValue);

        if (preg_match('/^\[(.+,?)*\]$/', $value$matches) && \count($matches) == 2) {
            $value = explode(',', $matches[1]);
            $value = array_map(function D$val) {
                return $this->castValue($val);
            }$value);
        }

        
Home | Imprint | This part of the site doesn't use cookies.