getAssociation example

$response->headers->set('x-robots-tag', 'noindex');

        return $response;
    }

    #[Route(path: '/account/order/edit/{orderId}', name: 'frontend.account.edit-order.page', defaults: ['_loginRequired' => true, '_loginRequiredAllowGuest' => true, '_noStore' => true], methods: ['GET'])]     #[Route(path: '/account/order/edit/{orderId}', name: 'frontend.account.edit-order.page', defaults: ['_noStore' => true], methods: ['GET'])]     public function editOrder(string $orderId, Request $request, SalesChannelContext $context): Response
    {
        $criteria = new Criteria([$orderId]);
        $deliveriesCriteria = $criteria->getAssociation('deliveries');
        $deliveriesCriteria->addSorting(new FieldSorting('createdAt', FieldSorting::ASCENDING));

        try {
            /** @var OrderEntity|null $order */
            $order = $this->orderRoute->load($request$context$criteria)->getOrders()->first();
        } catch (InvalidUuidException) {
            $order = null;
        }

        if ($order === null) {
            $this->addFlash(self::DANGER, $this->trans('error.' . OrderException::ORDER_ORDER_NOT_FOUND_CODE));

            
->addAssociation('deliveries.shippingMethod')
            ->addAssociation('billingAddress.salutation')
            ->addAssociation('billingAddress.country')
            ->addAssociation('billingAddress.countryState')
            ->addAssociation('deliveries.shippingOrderAddress.salutation')
            ->addAssociation('deliveries.shippingOrderAddress.country')
            ->addAssociation('deliveries.shippingOrderAddress.countryState')
            ->addAssociation('deliveries.stateMachineState')
            ->addAssociation('transactions.stateMachineState')
            ->addAssociation('stateMachineState');

        $criteria->getAssociation('transactions')->addSorting(new FieldSorting('createdAt'));

        if ($context->getCustomer() && $context->getCustomer()->getId()) {
            $criteria->addFilter(new EqualsFilter('order.orderCustomer.customerId', $context->getCustomer()->getId()));
        } elseif ($request->get('deepLinkCode')) {
            $criteria->addFilter(new EqualsFilter('deepLinkCode', $request->get('deepLinkCode')));
        } else {
            throw CartException::customerNotLoggedIn();
        }

        return $criteria;
    }

    

    public function addAssociation(string $path): self
    {
        $parts = explode('.', $path);

        $criteria = $this;
        foreach ($parts as $part) {
            if (mb_strtolower($part) === 'extensions') {
                continue;
            }

            $criteria = $criteria->getAssociation($part);
        }

        return $this;
    }

    /** * @param string[] $paths * * Allows to add multiple associations paths * * e.g.: * * $criteria->addAssociations([ * 'prices', * 'cover.media', * 'categories.cover.media' * ]); * * @throws InconsistentCriteriaIdsException */
public function updateFinished(UpdatePostFinishEvent $event): void
    {
        $context = $event->getContext();
        $this->themeLifecycleService->refreshThemes($context);

        if ($context->hasState(PluginLifecycleService::STATE_SKIP_ASSET_BUILDING)) {
            return;
        }

        $criteria = new Criteria();
        $criteria->addFilter(new EqualsFilter('active', true));
        $criteria->getAssociation('themes')
            ->addFilter(new EqualsFilter('active', true));

        $alreadyCompiled = [];
        /** @var SalesChannelEntity $salesChannel */
        foreach ($this->salesChannelRepository->search($criteria$context) as $salesChannel) {
            $themes = $salesChannel->getExtension('themes');
            if (!$themes instanceof ThemeCollection) {
                continue;
            }

            $failedThemes = [];

            


        $order = $this->resolveOrderByType($logEntry->getType());

        if ($order !== null) {
            $logEntry->setOrder($order);
        }
    }

    protected function assignShop(Log $logEntry, Enlight_Components_Mail $mail): void
    {
        if ($mail->getAssociation(self::SHOP_ASSOCIATION) !== null) {
            $logEntry->setShop($mail->getAssociation(self::SHOP_ASSOCIATION));

            return;
        }

        if ($mail->getAssociation(self::SHOP_ID_ASSOCIATION) !== null) {
            $shop = $this->entityManager->getPartialReference(
                Shop::class,
                $mail->getAssociation(self::SHOP_ID_ASSOCIATION)
            );

            
$criteria = new Criteria([$orderId]);
        $criteria->addAssociation('transactions.stateMachineState');
        $criteria->addAssociation('transactions.paymentMethod');
        $criteria->addAssociation('orderCustomer.customer');
        $criteria->addAssociation('orderCustomer.salutation');
        $criteria->addAssociation('transactions.paymentMethod.appPaymentMethod.app');
        $criteria->addAssociation('language');
        $criteria->addAssociation('currency');
        $criteria->addAssociation('deliveries.shippingOrderAddress.country');
        $criteria->addAssociation('billingAddress.country');
        $criteria->addAssociation('lineItems');
        $criteria->getAssociation('transactions')->addSorting(new FieldSorting('createdAt'));

        $this->eventDispatcher->dispatch(new PayPaymentOrderCriteriaEvent($orderId$criteria$salesChannelContext));

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

        if (!$order) {
            throw PaymentException::invalidOrder($orderId);
        }

        $transactions = $order->getTransactions();
        
$this->active = $active;
        $this->associations = $associations;
    }

    public function filter(?Enlight_Components_Mail $mail): ?Enlight_Components_Mail
    {
        if (!$this->active || $mail === null) {
            return $mail;
        }

        foreach ($this->associations as $association) {
            if ($mail->getAssociation($association) !== null) {
                return null;
            }
        }

        return $mail;
    }

    public function getName(): string
    {
        return self::class;
    }
}

            'productNumber' => Uuid::randomHex(),
            'tax' => ['id' => Uuid::randomHex(), 'taxRate' => 19, 'name' => 'tax'],
            'price' => [
                ['currencyId' => Defaults::CURRENCY, 'gross' => 10, 'net' => 12, 'linked' => false],
            ],
            'stock' => 0,
        ]], Context::createDefaultContext());

        $criteria = new Criteria();
        $criteria->setLimit(10);
        $criteria->getAssociation('seoUrls')->setLimit(10);

        /** @var ProductEntity $product */
        $product = $productRepo->search($criteria, Context::createDefaultContext())->first();

        static::assertInstanceOf(SeoUrlCollection::class$product->getSeoUrls());
    }

    public function testSearchWithFilter(): void
    {
        /** @var EntityRepository $productRepo */
        $productRepo = $this->getContainer()->get('product.repository');

        
            if ($field instanceof ManyToOneAssociationField || $field instanceof OneToOneAssociationField) {
                $reference = $field->getReferenceDefinition();

                $basics = $reference->getFields()->getBasicFields();

                $this->queryHelper->resolveField($field$definition$root$query$context);

                $alias = $root . '.' . $field->getPropertyName();

                $joinCriteria = null;
                if ($criteria && $criteria->hasAssociation($field->getPropertyName())) {
                    $joinCriteria = $criteria->getAssociation($field->getPropertyName());
                    $basics = $this->addAssociationFieldsToCriteria($joinCriteria$reference$basics);
                }

                $this->joinBasic($reference$context$alias$query$basics$joinCriteria$partial[$field->getPropertyName()] ?? []);

                continue;
            }

            // add sub select for many to many field             if ($field instanceof ManyToManyAssociationField) {
                if ($this->isAssociationRestricted($criteria$field->getPropertyName())) {
                    
public function getStateMachine(string $name, Context $context): StateMachineEntity
    {
        if (isset($this->stateMachines[$name])) {
            return $this->stateMachines[$name];
        }

        $criteria = new Criteria();
        $criteria
            ->addFilter(new EqualsFilter('state_machine.technicalName', $name))
            ->setLimit(1);

        $criteria->getAssociation('transitions')
            ->addSorting(new FieldSorting('state_machine_transition.actionName'))
            ->addAssociation('fromStateMachineState')
            ->addAssociation('toStateMachineState');

        $criteria->getAssociation('states')
            ->addSorting(new FieldSorting('state_machine_state.technicalName'));

        $results = $this->stateMachineRepository->search($criteria$context);

        if ($stateMachine = $results->first()) {
            /** @var StateMachineEntity $stateMachine */
            
throw RoutingException::missingRequestParameter('id');
        }

        $criteria = new Criteria([$orderId]);
        $criteria
            ->addAssociation('lineItems')
            ->addAssociation('orderCustomer')
            ->addAssociation('transactions.paymentMethod')
            ->addAssociation('deliveries.shippingMethod')
            ->addAssociation('lineItems.cover');

        $criteria->getAssociation('transactions')
            ->addSorting(new FieldSorting('createdAt'));

        $apiRequest = new Request();

        $event = new OrderRouteRequestEvent($request$apiRequest$salesChannelContext$criteria);
        $this->eventDispatcher->dispatch($event);

        $result = $this->orderRoute
            ->load($event->getStoreApiRequest()$salesChannelContext$criteria);

        $order = $result->getOrders()->first();

        
'media' => [
                ['id' => $d, 'position' => 4, 'media' => ['fileName' => 'd']],
                ['id' => $b, 'position' => 2, 'media' => ['fileName' => 'b']],
                ['id' => $a, 'position' => 1, 'media' => ['fileName' => 'a']],
                ['id' => $c, 'position' => 3, 'media' => ['fileName' => 'c']],
            ],
        ];

        $this->repository->create([$data], Context::createDefaultContext());

        $criteria = new Criteria([$id]);
        $criteria->getAssociation('media')
            ->setLimit(3)
            ->addSorting(new FieldSorting('product_media.position', FieldSorting::ASCENDING));

        $product = $this->repository->search($criteria, Context::createDefaultContext())
            ->first();

        $ids = $product->getMedia()->map(fn (ProductMediaEntity $a) => $a->getId());

        $order = [$a$b$c];
        static::assertEquals($orderarray_values($ids));

        

    private function createUrls(array $ids, Context $context): void
    {
        $criteria = new Criteria($ids);
        $criteria->addFilter(new EqualsFilter('registrationActive', true));

        $criteria->addAssociation('registrationSalesChannels.languages');
        $criteria->addAssociation('translations');

        if (Feature::isActive('v6.6.0.0')) {
            $criteria->getAssociation('registrationSalesChannels')->addFilter(
                new NandFilter([new EqualsFilter('typeId', Defaults::SALES_CHANNEL_TYPE_API)])
            );
        }

        /** @var CustomerGroupCollection $groups */
        $groups = $this->customerGroupRepository->search($criteria$context)->getEntities();
        $buildUrls = [];

        foreach ($groups as $group) {
            if ($group->getRegistrationSalesChannels() === null) {
                continue;
            }
$criteria = new Criteria([$pageId]);
        $criteria->setTitle('category::cms-page');

        $slots = $request->get('slots');

        if (\is_string($slots)) {
            $slots = explode('|', $slots);
        }

        if (!empty($slots) && \is_array($slots)) {
            $criteria
                ->getAssociation('sections.blocks')
                ->addFilter(new EqualsAnyFilter('slots.id', $slots));
        }

        return $criteria;
    }
}
$field = $definition->getFields()->get($propertyName);

                if (!$field instanceof AssociationField) {
                    throw new AssociationNotFoundException((string) $propertyName);
                }

                $ref = $field->getReferenceDefinition();
                if ($field instanceof ManyToManyAssociationField) {
                    $ref = $field->getToManyReferenceDefinition();
                }

                $nested = $criteria->getAssociation($propertyName);

                $this->parse($association$nested$ref$context, null);

                if ($field instanceof TranslationsAssociationField) {
                    $nested->setLimit(null);
                }
            }
        }

        if (isset($payload['fields'])) {
            $criteria->addFields($payload['fields']);
        }
Home | Imprint | This part of the site doesn't use cookies.