hasLineItemWithState example

$criteria = new Criteria([$orderId]);
        $criteria->addAssociation('lineItems.downloads');
        $criteria->addAssociation('deliveries');

        $order = $this->orderRepository->search($criteria$this->salesChannelContext->getContext())->first();
        static::assertInstanceOf(OrderEntity::class$order);

        $lineItems = $order->getLineItems();
        static::assertNotNull($lineItems);
        $lineItems->sortByPosition();
        static::assertEquals(\count($productDownloads)$lineItems->count());
        static::assertTrue($lineItems->hasLineItemWithState(State::IS_DOWNLOAD));

        foreach ($productDownloads as $key => $downloadFiles) {
            $lineItem = $lineItems->getAt($key);
            static::assertNotNull($lineItem);
            static::assertNotNull($lineItem->getDownloads());
            static::assertEquals(\count($downloadFiles)$lineItem->getDownloads()->count());
            foreach ($lineItem->getDownloads() as $download) {
                static::assertFalse($download->isAccessGranted());

                try {
                    $request = new Request(['downloadId' => $download->getId(), 'orderId' => $orderId]);
                    
static::assertCount(0, $collection);
    }

    /** * @dataProvider lineItemStateProvider * * @param array<string, bool> $expectedResults */
    public function testHasLineItemWithState(LineItemCollection $collection, array $expectedResults): void
    {
        foreach ($expectedResults as $state => $expected) {
            static::assertSame($expected$collection->hasLineItemWithState($state), 'Line item of state `' . $state . '` could not be found.');
        }
    }

    public static function lineItemStateProvider(): \Generator
    {
        yield 'collection has line item with state download and physical' => [
            new LineItemCollection([
                (new LineItem('A', 'test'))->setStates([State::IS_PHYSICAL]),
                (new LineItem('B', 'test'))->setStates([State::IS_DOWNLOAD]),
            ]),
            [State::IS_PHYSICAL => true, State::IS_DOWNLOAD => true],
        ];
if ($page->getMetaInformation()) {
            $page->getMetaInformation()->setRobots('noindex,follow');
        }

        $page->setPaymentMethods($this->getPaymentMethods($context));
        $page->setShippingMethods($this->getShippingMethods($context));

        $cart = $this->cartService->get($context->getToken()$context, false, true);
        $this->validateCustomerAddresses($cart$context);
        $page->setCart($cart);

        $page->setShowRevocation($cart->getLineItems()->hasLineItemWithState(State::IS_DOWNLOAD));
        $page->setHideShippingAddress(!$cart->getLineItems()->hasLineItemWithState(State::IS_PHYSICAL));

        $this->eventDispatcher->dispatch(
            new CheckoutConfirmPageLoadedEvent($page$context$request)
        );

        return $page;
    }

    private function getPaymentMethods(SalesChannelContext $context): PaymentMethodCollection
    {
        

    public function __construct(private readonly EntityRepository $repository)
    {
    }

    public function validate(Cart $cart, ErrorCollection $errors, SalesChannelContext $context): void
    {
        $country = $context->getShippingLocation()->getCountry();
        $customer = $context->getCustomer();
        $validateShipping = $cart->getLineItems()->count() === 0
            || $cart->getLineItems()->hasLineItemWithState(State::IS_PHYSICAL);

        if (!$country->getActive() && $validateShipping) {
            $errors->add(new ShippingAddressBlockedError((string) $country->getTranslation('name')));

            return;
        }

        if (!$country->getShippingAvailable() && $validateShipping) {
            $errors->add(new ShippingAddressBlockedError((string) $country->getTranslation('name')));

            return;
        }
private readonly StateMachineRegistry $stateMachineRegistry
    ) {
    }

    /** * @throws ConstraintViolationException */
    public function createOrder(DataBag $data, SalesChannelContext $context): string
    {
        $cart = $this->cartService->getCart($context->getToken()$context);

        $this->validateOrderData($data$context$cart->getLineItems()->hasLineItemWithState(State::IS_DOWNLOAD));

        $this->validateCart($cart$context->getContext());

        return $this->cartService->order($cart$context$data->toRequestDataBag());
    }

    /** * @internal Should not be called from outside the core */
    public function orderStateTransition(
        string $orderId,
        
Home | Imprint | This part of the site doesn't use cookies.