EntityNotFoundException example

if (\array_key_exists($currencyId$this->currencyFactor)) {
            return $this->currencyFactor[$currencyId];
        }

        $currencyFactor = $this->connection->fetchOne(
            'SELECT `factor` FROM `currency` WHERE `id` = :currencyId',
            ['currencyId' => Uuid::fromHexToBytes($currencyId)]
        );

        if (!$currencyFactor) {
            throw new EntityNotFoundException('currency', $currencyId);
        }

        return $this->currencyFactor[$currencyId] = (float) $currencyFactor;
    }

    private function validateTaxFree(SalesChannelContext $context, Cart $cart, CartBehavior $behaviorContext): Cart
    {
        $totalCartNetAmount = $cart->getPrice()->getPositionPrice();
        if ($context->getTaxState() === CartPrice::TAX_STATE_GROSS) {
            $totalCartNetAmount = $totalCartNetAmount - $cart->getLineItems()->getPrices()->getCalculatedTaxes()->getAmount();
        }
        
if ($source->getUserId() === null) {
            return $this->languageLocaleProvider->getLocaleForLanguageId($context->getLanguageId());
        }

        $criteria = new Criteria([$source->getUserId()]);
        $criteria->addAssociation('locale');

        $user = $this->userRepository->search($criteria$context)->first();

        if ($user === null) {
            throw new EntityNotFoundException(UserDefinition::ENTITY_NAME, $source->getUserId());
        }

        /** @var LocaleEntity $locale */
        $locale = $user->getLocale();

        return $locale->getCode();
    }
}
if ($source->getUserId() === null) {
            return 'en-GB';
        }

        $criteria = new Criteria([$source->getUserId()]);
        $criteria->addAssociation('locale');

        $user = $this->userRepository->search($criteria$context)->first();

        if ($user === null) {
            throw new EntityNotFoundException(UserDefinition::ENTITY_NAME, $source->getUserId());
        }

        /** @var LocaleEntity $locale */
        $locale = $user->getLocale();

        return $locale->getCode();
    }
}
public function getDecorated(): AbstractMappingService
    {
        throw new DecorationPatternException(self::class);
    }

    public function createTemplate(Context $context, string $profileId): string
    {
        /** @var ImportExportProfileEntity|null $profile */
        $profile = $this->profileRepository->search(new Criteria([$profileId])$context)->first();
        if ($profile === null) {
            throw new EntityNotFoundException('import_export_profile', $profileId);
        }
        $mappings = $profile->getMapping();
        if (empty($mappings)) {
            throw new \RuntimeException('ImportExportProfile "' . $profileId . '" has no mappings');
        }

        $config = new Config($mappings[][]);
        $headers = [];
        $mappings = MappingCollection::fromIterable($mappings)->sortByPosition();

        /** @var Mapping $mapping */
        
public function buildFilters(string $id, Context $context): array
    {
        $criteria = new Criteria([$id]);

        /** @var ProductStreamEntity|null $stream */
        $stream = $this->repository
            ->search($criteria$context)
            ->get($id);

        if (!$stream) {
            throw new EntityNotFoundException('product_stream', $id);
        }

        $data = $stream->getApiFilter();
        if (!$data) {
            throw new NoFilterException($id);
        }

        $filters = [];
        $exception = new SearchRequestException();

        foreach ($data as $filter) {
            
'tags',
            'transactions.stateMachineState',
            'stateMachineState',
        ]);

        $this->eventDispatcher->dispatch(new OrderPaymentMethodChangedCriteriaEvent($orderId$criteria$context));

        /** @var OrderEntity|null $order */
        $order = $this->orderRepository->search($criteria$context->getContext())->first();

        if ($order === null) {
            throw new EntityNotFoundException('order', $orderId);
        }

        return $order;
    }

    /** * @throws PaymentMethodNotChangeableException */
    private function validatePaymentState(OrderEntity $order): void
    {
        if ($this->orderService->isPaymentChangeableByTransactionState($order)) {
            
$this->getContainer()->get(DefinitionInstanceRegistry::class)
        );
    }

    /** * @dataProvider templateProfileProvider */
    public function testCreateTemplateFromProfileMapping($profile): void
    {
        if ($profile === null) {
            $profileId = Uuid::randomHex();
            self::expectExceptionObject(new EntityNotFoundException('import_export_profile', $profileId));
            $this->mappingService->createTemplate(Context::createDefaultContext()$profileId);
        }

        $this->profileRepository->create([$profile], Context::createDefaultContext());

        if (empty($profile['mapping'])) {
            static::expectException(\RuntimeException::class);
        }

        $fileId = $this->mappingService->createTemplate(Context::createDefaultContext()$profile['id']);

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