getResultMode example


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

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

        $query = $this->getRepository()->getDetailQuery($id);

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

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

        return $manufacturer;
    }

    /** * @param int $offset * @param int $limit * * @return array */
throw new ParameterMissingException('id');
        }

        $builder = $this->getRepository()->createQueryBuilder('customerGroup')
                ->select('customerGroup', 'd', 'attribute')
                ->leftJoin('customerGroup.discounts', 'd')
                ->leftJoin('customerGroup.attribute', 'attribute')
                ->where('customerGroup.id = :id')
                ->setParameter(':id', $id);

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

        /** @var Group|null $result */
        $result = $query->getOneOrNullResult($this->getResultMode());

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

        return $result;
    }

    

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

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

        $query = $this->getRepository()->getDetailQueryWithoutArticles($id);

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

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

        if ($this->getResultMode() === Resource::HYDRATE_ARRAY) {
            $category = $categoryResult[0] + $categoryResult;

            $query = $this->getManager()->createQuery('SELECT shop FROM Shopware\Models\Shop\Shop as shop');

            foreach ($query->getArrayResult() as $shop) {
                
if (empty($id)) {
            throw new ParameterMissingException('id');
        }

        $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 */

        $this->checkPrivilege('read');

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

        $filters = [['property' => 'payment.id', 'expression' => '=', 'value' => $id]];
        $query = $this->getRepository()->getListQuery($filters[], 0, 1);

        /** @var PaymentModel|null $payment */
        $payment = $query->getOneOrNullResult($this->getResultMode());

        if (!$payment) {
            throw new ApiException\NotFoundException(sprintf('Payment by id %d not found', $id));
        }

        return $payment;
    }

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

        $this->checkPrivilege('read');

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

        $filters = [['property' => 'media.id', 'expression' => '=', 'value' => $id]];
        $query = $this->getRepository()->getMediaListQuery($filters[], 1);

        /** @var MediaModel|array $media */
        $media = $query->getOneOrNullResult($this->getResultMode());

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

        $mediaService = Shopware()->Container()->get(MediaServiceInterface::class);
        if (\is_array($media)) {
            $media['path'] = $mediaService->getUrl($media['path']);
        } else {
            $media->setPath($mediaService->getUrl($media->getPath()));
        }

        


        $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 */
->leftJoin('mainDetailPrices.customerGroup', 'priceCustomGroup')
            ->leftJoin('article.tax', 'tax')
            ->leftJoin('article.propertyValues', 'propertyValues')
            ->leftJoin('article.supplier', 'supplier')
            ->leftJoin('mainDetail.attribute', 'mainDetailAttribute')
            ->leftJoin('mainDetail.configuratorOptions', 'configuratorOptions')
            ->leftJoin('article.propertyGroup', 'propertyGroup')
            ->leftJoin('article.customerGroups', 'customerGroups')
            ->where('article.id = ?1')
            ->setParameter(1, $id);

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

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

        if ($this->getResultMode() === self::HYDRATE_ARRAY) {
            $product['images'] = $this->getArticleImages($id);
            $product['configuratorSet'] = $this->getArticleConfiguratorSet($id);
            $product['links'] = $this->getArticleLinks($id);
            $product['downloads'] = $this->getArticleDownloads($id);
            $product['categories'] = $this->getArticleCategories($id);
            

        $this->checkPrivilege('read');

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

        $filters = [['property' => 'groups.id', 'expression' => '=', 'value' => $id]];
        $query = $this->getRepository()->getListGroupsQuery($filters);

        /** @var \Shopware\Models\Property\Group|null $property */
        $property = $query->getOneOrNullResult($this->getResultMode());

        if (!$property) {
            throw new ApiException\NotFoundException(sprintf('PropertyGroup by id %d not found', $id));
        }

        return $property;
    }

    /** * @param int $offset * @param int $limit * * @return array */
$results = [];
        foreach ($data as $key => $datum) {
            $id = $this->getIdByData($datum);

            try {
                $results[$key] = [
                    'success' => true,
                    'operation' => 'delete',
                    'data' => $this->delete($id),
                ];
                if ($this->getResultMode() === self::HYDRATE_ARRAY) {
                    $results[$key]['data'] = Shopware()->Models()->toArray(
                        $results[$key]['data']
                    );
                }
            } catch (Exception $e) {
                if (!$this->getManager()->isOpen()) {
                    $this->resetEntityManager();
                }
                $message = $e->getMessage();
                if ($e instanceof ValidationException && $e->getViolations() instanceof ConstraintViolationList) {
                    $message = implode("\n", $e->getViolations()->getIterator()->getArrayCopy());
                }
throw new ParameterMissingException('id');
        }

        $builder = $this->getRepository()->createQueryBuilder('user');
        $builder->select(['users', 'attribute'])
            ->from(UserModel::class, 'users')
            ->leftJoin('users.attribute', 'attribute')
            ->where('users.id = ?1')
            ->setParameter(1, $id);

        /** @var UserModel|array|null $user */
        $user = $builder->getQuery()->getOneOrNullResult($this->getResultMode());

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

        if (!$this->hasPrivilege('create', 'usermanager')
            && !$this->hasPrivilege('update', 'usermanager')) {
            if (\is_array($user)) {
                unset($user['apiKey']$user['sessionId']$user['password']$user['encoder']);
            } else {
                $user->setApiKey('');
                
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;
    }

    

    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 getOne($id)
    {
        $this->checkPrivilege('read');

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

        $query = $this->getRepository()->getOne($id);

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

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

        return $address;
    }

    /** * @param int $offset * @param int $limit * * @return array */
->leftJoin('customer.paymentData', 'paymentData', Join::WITH, 'paymentData.paymentMean = customer.paymentId')
            ->leftJoin('billing.attribute', 'billingAttribute')
            ->leftJoin('customer.defaultShippingAddress', 'shipping')
            ->leftJoin('shipping.attribute', 'shippingAttribute')
            ->leftJoin('billing.country', 'billingCountry')
            ->leftJoin('shipping.country', 'shippingCountry')
            ->leftJoin('billing.state', 'billingState')
            ->leftJoin('shipping.state', 'shippingState')
            ->where('customer.id = ?1')
            ->setParameter(1, $id);

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

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

        return $customer;
    }

    /** * @param int $offset * @param int $limit * @param array<string, string>|array<array{property: string, value: mixed, expression?: string}> $criteria * @param array<array{property: string, direction: string}> $orderBy * * @return array{data: array<array<string, mixed>|CustomerModel>, total: int} */
Home | Imprint | This part of the site doesn't use cookies.