NotFoundException example

->where('customer.number = ?1')
                ->setParameter(1, $number);

        try {
            $id = $builder->getQuery()->getOneOrNullResult();
        } catch (NonUniqueResultException $nonUniqueResultException) {
            $ids = $builder->getQuery()->getArrayResult();
            throw new NonUniqueIdentifierUsedException('number', (string) $number, CustomerModel::classarray_column($ids, 'id'));
        }

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

        return $id['id'];
    }

    /** * @param string $number * * @throws NotFoundException * @throws ParameterMissingException * * @return array<string, mixed>|CustomerModel */

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

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

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

        return $productVariant->getArticle()->getId();
    }

    /** * Convenience method to get a product by number * * @param string $number * * @return array|ProductModel */
$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 */
    
$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 */
    
public function update($id, array $data$index = false)
    {
        $this->checkPrivilege('save');

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

        $stream = $this->getManager()->find(CustomerStreamEntity::class$id);

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

        $data = $this->prepareData($data);

        $stream->fromArray($data);

        $violations = $this->getManager()->validate($stream);
        if ($violations->count() > 0) {
            throw new ValidationException($violations);
        }

        
$useNumberAsId = (bool) $request->getParam('useNumberAsId', 0);
        $id = $useNumberAsId ? $this->resource->getIdFromNumber($id) : (int) $id;

        if (!$useNumberAsId && $id <= 0) {
            throw new ApiException\CustomValidationException('Invalid product id');
        }

        /** @var Article|null $product */
        $product = $this->resource->getRepository()->find($id);

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

        $this->resource->generateImages($product(bool) $request->getParam('force', 0));

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

    /** * Controller Action for the batchAction * Blocks batch actions implemented by the extended class * * @throws RuntimeException */
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()));
        }

        return $media;
    }

    

        $filter = [['property' => 'id', 'value' => $id]];

        $criteria = new Criteria();
        $criteria->filter = $filter;
        $criteria->loadAssociations = $resolve;
        $criteria->loadTranslations = $loadTranslations;

        $result = current($this->repository->findAll($criteria)->items);

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

        $this->View()->assign('data', $result);
        $this->View()->assign('success', true);
    }

    public function postAction(): void
    {
        $params = $this->Request()->getPost();
        $result = [];
        $result['id'] = $this->repository->save($params);
        
$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) {
                $translation = $this->translationComponent->read($shop['id'], 'category', $id);
                if (!empty($translation)) {
                    $translation['shopId'] = $shop['id'];
                    

    public function savePreviewAction()
    {
        try {
            $data = $this->Request()->getParams();

            if (empty($data['id'])) {
                throw new NotFoundException('The emotion must exist before previewing it.');
            }

            $data['previewId'] = $data['id'];
            $data['previewSecret'] = Random::getAlphanumericString(32);
            $data['active'] = false;

            $previewEmotion = $this->findPreviewEmotion((int) $data['id']);
            if ($previewEmotion) {
                $previewEmotion->getElements()->clear();
                $this->getManager()->flush($previewEmotion);

                
$tags[] = CacheManager::ITEM_TAG_SEARCH;
                $this->cacheManager->clearSearchCache();
                break;
            case 'rewrite':
            case 'router':
                $this->cacheManager->clearRewriteCache();
                break;
            case 'opcache':
                $this->cacheManager->clearOpCache();
                break;
            default:
                throw new NotFoundException(sprintf('Cache "%s" is not a valid cache id.', $cache));
        }

        if (!empty($capabilities['tags'])) {
            if (!empty($tags)) {
                $this->cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, $tags);
            } else {
                $this->cache->clean();
            }
        }
    }

    
->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 */
    
->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;
    }

    /** * @param int $offset * @param int $limit * * @return array */
    
$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('');
                $user->setSessionId('');
                $user->setPassword('');
                $user->setEncoder('');
            }

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

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

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

        return $orderModel->getId();
    }

    /** * @param string $number * * @throws NonUniqueResultException * @throws NotFoundException * @throws ParameterMissingException * @throws PrivilegeException * * @return array<string, mixed>|OrderModel */
Home | Imprint | This part of the site doesn't use cookies.