getOneOrNullResult example



    private function getAvailableSalutationKeys(): array
    {
        $builder = Shopware()->Container()->get(ModelManager::class)->createQueryBuilder();
        $builder->select(['element', 'values'])
            ->from(Element::class, 'element')
            ->leftJoin('element.values', 'values')
            ->where('element.name = :name')
            ->setParameter('name', 'shopsalutations');

        $data = $builder->getQuery()->getOneOrNullResult(AbstractQuery::HYDRATE_ARRAY);

        $value = explode(',', $data['value']);
        if (!empty($data['values'])) {
            $value = [];
        }

        foreach ($data['values'] as $shopValue) {
            $value = array_merge($valueexplode(',', $shopValue['value']));
        }

        return array_unique(array_filter($value));
    }
$modelManager = $this->get(\Shopware\Components\Model\ModelManager::class);
        try {
            $modelManager->persist($group);
            $modelManager->flush();
        } catch (\Exception $e) {
            $this->View()->assign(['success' => false, 'message' => $e->getMessage()]);

            return;
        }
        $data = $this->getPropertyRepository()
                     ->getGroupDetailQuery($group->getId())
                     ->getOneOrNullResult(\Doctrine\ORM\AbstractQuery::HYDRATE_ARRAY);

        $this->View()->assign(['success' => true, 'data' => $data]);
    }

    /** * Updates one group identified by its identifier */
    public function updateSetAction()
    {
        if (!($id = $this->Request()->getParam('id'))) {
            $this->View()->assign(['success' => false, 'message' => 'Id not found']);

            
throw new ParameterMissingException('id');
        }

        $builder = $this->getRepository()->getVariantDetailQuery();
        $builder->addSelect('article')
                ->andWhere('variants.id = :variantId')
                ->addOrderBy('variants.id', 'ASC')
                ->addOrderBy('customerGroup.id', 'ASC')
                ->addOrderBy('prices.from', 'ASC')
                ->setParameter('variantId', $id);

        $variant = $builder->getQuery()->getOneOrNullResult($this->getResultMode());

        if (!$variant) {
            throw new NotFoundException(sprintf('Variant by id %d not found', $id));
        }

        if (\is_array($variant) && !empty($options['considerTaxInput'])) {
            $variant = $this->considerTaxInput($variant);
        }

        return $variant;
    }

    
return $this->repository;
    }

    /** * Returns an array with the converted mail data and a mail object for the passed mail id. * * @return false|array{data: array, mail: Mail} */
    private function getMail(int $id)
    {
        $query = $this->getRepository()->getMailQuery($id);
        $mail = $query->getOneOrNullResult(AbstractQuery::HYDRATE_OBJECT);

        if (!$mail instanceof Mail) {
            $this->View()->assign(['success' => false, 'message' => 'Mail not found']);

            return false;
        }

        if ($mail->isOrderStateMail()) {
            $type = 'orderState';
        } elseif ($mail->isPaymentStateMail()) {
            $type = 'paymentState';
        }
$fromDate = $this->getFromDate();
            $toDate = $this->getToDate();

            $repository = $this->get('models')->getRepository(Partner::class);
            $dataQuery = $repository->getStatisticListQuery($order$offset$limit$partnerId, false, $fromDate$toDate);

            $totalCount = $this->getStatisticListTotalCount($dataQuery);

            $data = $dataQuery->getArrayResult();

            $summaryQuery = $repository->getStatisticListQuery($order$offset$limit$partnerId, true, $fromDate$toDate);
            $summaryData = $summaryQuery->getOneOrNullResult(AbstractQuery::HYDRATE_ARRAY);

            $this->View()->assign(
                [
                    'success' => true,
                    'data' => $data,
                    'totalCount' => $totalCount,
                    'totalNetTurnOver' => $summaryData['netTurnOver'],
                    'totalProvision' => $summaryData['provision'],
                ]
            );
        } catch (Exception $e) {
            
// Get the information of the partner chart         $customerCurrencyFactor = Shopware()->Shop()->getCurrency()->getFactor();

        $dataQuery = $repository->getStatisticChartQuery($partnerId$fromDate$toDate$customerCurrencyFactor);
        $this->View()->assign('sPartnerOrderChartData', $dataQuery->getArrayResult());

        $dataQuery = $repository->getStatisticListQuery(null, null, null, $partnerId, false, $fromDate$toDate$customerCurrencyFactor);
        $this->View()->assign('sPartnerOrders', $dataQuery->getArrayResult());

        $dataQuery = $repository->getStatisticListQuery(null, null, null, $partnerId, true, $fromDate$toDate$customerCurrencyFactor);
        $this->View()->assign('sTotalPartnerAmount', $dataQuery->getOneOrNullResult(AbstractQuery::HYDRATE_ARRAY));
    }

    /** * Logout account and delete session * * @return void */
    public function logoutAction()
    {
        $this->admin->logout();
    }

    
/** * @param int $id * * @return DetachedShop|null */
    public function getActiveById($id)
    {
        $builder = $this->getActiveQueryBuilder();
        $builder->andWhere('shop.id=:shopId');
        $builder->setParameter('shopId', $id);
        $shop = $builder->getQuery()->getOneOrNullResult();

        if ($shop !== null) {
            $shop = $this->fixActive($shop);
        }

        return $shop;
    }

    /** * @param int $id * * @return DetachedShop|null */


        $filters = [
            [
                'property' => 'countries.id',
                'expression' => '=',
                'value' => $id,
            ],
        ];
        $builder = $this->getRepository()->getCountriesWithStatesQueryBuilder($filters);
        /** @var CountryModel|null $country */
        $country = $builder->getQuery()->getOneOrNullResult($this->getResultMode());
        if (!$country) {
            throw new NotFoundException(sprintf('Country by id %d not found', $id));
        }

        return $country;
    }

    /** * Returns an array containing the total count of existing countries as well as the data of countries * that match the given criteria. * * @param int $offset * @param int $limit * * @return array */

    public function getOne($id)
    {
        $this->checkPrivilege('read');

        if (empty($id)) {
            throw new ParameterMissingException('id');
        }

        $filters = [['property' => 'orders.id', 'expression' => '=', 'value' => $id]];
        $order = $this->getRepository()->getOrdersQueryBuilder($filters)->getQuery()
            ->getOneOrNullResult($this->getResultMode());

        if ($order === null) {
            throw new NotFoundException(sprintf('Order by id %d not found', $id));
        }

        if (\is_array($order)) {
            $order['paymentStatusId'] = $order['cleared'];
            $order['orderStatusId'] = $order['status'];
            unset($order['cleared']$order['status']);
        }

        

    public function getSystemConfiguration($hydration = AbstractQuery::HYDRATE_ARRAY)
    {
        $builder = $this->entityManager->createQueryBuilder();
        $builder->select(['settings'])
            ->from(Settings::class, 'settings')
            ->orderBy('settings.id', 'ASC')
            ->setFirstResult(0)
            ->setMaxResults(1);

        return $builder->getQuery()->getOneOrNullResult($hydration);
    }

    /** * Saves the passed configuration data into the database. * * @param array $data */
    public function saveSystemConfiguration($data)
    {
        $settings = $this->getSystemConfiguration(AbstractQuery::HYDRATE_OBJECT);

        


        $builder = $this->getRepository()->createQueryBuilder('shop')
                ->select('shop', 'currency')
                ->leftJoin('shop.currency', 'currency')
                ->where('shop.id = :id')
                ->setParameter(':id', $id);

        $query = $builder->getQuery();
        $query->setHydrationMode($this->getResultMode());

        $shop = $query->getOneOrNullResult($this->getResultMode());

        if (!$shop) {
            throw new NotFoundException(sprintf('Shop by id %s not found', $id));
        }

        return $shop;
    }

    /** * @param int $offset * @param int $limit * * @return array */

    protected function getTemplate($id)
    {
        $builder = $this->get('models')->createQueryBuilder();
        $builder->select(['template'])
            ->from(Template::class, 'template')
            ->where('template.id = :id')
            ->setParameter('id', $id);

        return $builder->getQuery()->getOneOrNullResult(
            AbstractQuery::HYDRATE_ARRAY
        );
    }

    /** * Internal helper function to get access to the entity manager. */
    private function getManager(): ModelManager
    {
        if ($this->manager === null) {
            $this->manager = $this->get('models');
        }

    public function getUserDetailsAction()
    {
        $params = $this->Request()->getParams();
        $id = $params['id'];
        if (empty($id)) {
            throw new Enlight_Exception('Empty id given');
        }
        $data = $this->getUserRepository()
            ->getUserDetailQuery($id)
            ->getOneOrNullResult(AbstractQuery::HYDRATE_ARRAY);

        if (!$this->_isAllowed('create') && !$this->_isAllowed('update')) {
            unset($data['apiKey']$data['sessionId']);
        }

        unset($data['password']); // Do not send password hash to client         $this->View()->assign(['success' => true, 'data' => $data, 'total' => 1]);
    }

    /** * Get a list of all backend users * Returns a JSON string from all registered backend users */


            $site->fromArray($params);
            $site->setChanged();

            $this->getManager()->persist($site);

            $this->getManager()->flush();

            $data = $this->getSiteRepository()
                ->getSiteQuery($site->getId())
                ->getOneOrNullResult(AbstractQuery::HYDRATE_ARRAY);

            $this->View()->assign(['success' => true, 'data' => $data]);
        } catch (Exception $e) {
            // Catch all errors             $this->View()->assign(['success' => false, 'message' => $e->getMessage()]);
        }
    }

    /** * Builds an array containing all groups to be displayed in the itemSelectorField */
    

            ->from(Voucher::class, 'voucher')
            ->leftJoin('voucher.codes', 'voucherCodes')
            ->where('voucher.modus = 1')
            ->andWhere('voucher.id = :voucherId')
            ->andWhere('voucher.validTo >= CURRENT_DATE() OR voucher.validTo is NULL')
            ->andWhere('voucherCodes.customerId is NULL')
            ->andWhere('voucherCodes.cashed = 0')
            ->setParameter('voucherId', $voucherId)
            ->setMaxResults(1)
            ->getQuery()
            ->getOneOrNullResult(AbstractQuery::HYDRATE_ARRAY);
    }

    /** * @return ProductVariant[] */
    private function getOutOfStockProducts(Order $order): array
    {
        $products = $this->getProductsOfOrder($order);

        $invalid = [];
        foreach ($products as $product) {
            
Home | Imprint | This part of the site doesn't use cookies.