getOrderCustomer example

$this->fillCart($this->salesChannelContext->getToken());

        $orderId = $this->orderService->createOrder($data$this->salesChannelContext);

        $criteria = new Criteria([$orderId]);

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

        static::assertInstanceOf(OrderEntity::class$newlyCreatedOrder);
        static::assertSame($orderId$newlyCreatedOrder->getId());
        $orderCustomer = $newlyCreatedOrder->getOrderCustomer();
        static::assertNotNull($orderCustomer);
        static::assertSame($vatIds$orderCustomer->getVatIds());
    }

    public function testCreateOrderSendsMail(): void
    {
        if (!$this->getContainer()->has(AccountOrderController::class)) {
            // ToDo: NEXT-16882 - Reactivate tests again             static::markTestSkipped('Order mail tests should be fixed without storefront in NEXT-16882');
        }

        
$documentStruct = $this->documentGenerator->preview(InvoiceRenderer::TYPE, $operation(string) $order->getDeepLinkCode()$this->context);

        static::assertNotEmpty($documentStruct->getContent());
    }

    public function testPreviewStorno(): void
    {
        $order = $this->getContainer()->get('order.repository')->search(new Criteria([$this->orderId])$this->context)->first();
        static::assertNotNull($order);
        static::assertInstanceOf(OrderEntity::class$order);
        $orderCustomer = $order->getOrderCustomer();
        static::assertNotNull($orderCustomer);
        $customerNo = (string) $orderCustomer->getCustomerNumber();

        $invoiceNumber = '9998';
        $invoiceConfig1 = new DocumentConfiguration();
        $invoiceConfig1->setDocumentNumber($invoiceNumber);

        $invoiceConfig2 = new DocumentConfiguration();
        $invoiceConfig2->setDocumentNumber('9999');

        $operation1 = new DocumentGenerateOperation($this->orderId, FileTypes::PDF, $invoiceConfig1->jsonSerialize());
        
 catch (PromotionCodeNotFoundException) {
                $individualCode = null;
            }

            // if we did not use an individual code we might have             // just used a global one or anything else, so just quit in this case.             if (!($individualCode instanceof PromotionIndividualCodeEntity)) {
                return;
            }

            /** @var OrderCustomerEntity $customer */
            $customer = $event->getOrder()->getOrderCustomer();

            // set the code to be redeemed             // and assign all required meta data             // for later needs             $individualCode->setRedeemed(
                $item->getOrderId(),
                $customer->getCustomerId() ?? '',
                $customer->getFirstName() . ' ' . $customer->getLastName()
            );

            // save in database
$storable->setData(MailAware::MAIL_STRUCT, $mailStruct);
    }

    private function restoreOrderData(StorableFlow $storable): void
    {
        /** @var OrderEntity|null $order */
        $order = $storable->getData(OrderAware::ORDER);
        if (!$order) {
            return;
        }

        $customer = $order->getOrderCustomer();
        if (!$customer) {
            return;
        }

        $storable->setData(MailAware::SALES_CHANNEL_ID, $order->getSalesChannelId());
        $mailStruct = new MailRecipientStruct([$customer->getEmail() => $customer->getFirstName() . $customer->getLastName()]);
        $storable->setData(MailAware::MAIL_STRUCT, $mailStruct);
    }

    private function restoreCustomerData(StorableFlow $storable): void
    {
        

                    'deepLinkCode' => $deepLinkCode,
                    'email' => $expectedCustomer->getEmail(),
                    'zipcode' => '12345',
                ],
            ),
            $this->salesChannel
        );

        static::assertEquals(
            $expectedCustomer->getId(),
            $page->getOrders()->first()->getOrderCustomer()->getCustomerId(),
        );
    }

    protected function getPageLoader(): AccountOrderPageLoader
    {
        return $this->getContainer()->get(AccountOrderPageLoader::class);
    }
}

    public function restoreByOrder(string $orderId, Context $context, array $overrideOptions = []): SalesChannelContext
    {
        $order = $this->getOrderById($orderId$context);
        if ($order === null) {
            throw OrderException::orderNotFound($orderId);
        }

        if ($order->getOrderCustomer() === null) {
            throw OrderException::missingAssociation('orderCustomer');
        }

        $customer = $order->getOrderCustomer()->getCustomer();
        $customerGroupId = null;
        if ($customer) {
            $customerGroupId = $customer->getGroupId();
        }

        $billingAddress = $order->getBillingAddress();
        $countryStateId = null;
        
$update->execute([
                'id' => Uuid::fromHexToBytes($id),
                'count' => (int) $total,
                'customerCount' => json_encode($totals, \JSON_THROW_ON_ERROR),
            ]);
        }
    }

    public function orderPlaced(CheckoutOrderPlacedEvent $event): void
    {
        $lineItems = $event->getOrder()->getLineItems();
        $customer = $event->getOrder()->getOrderCustomer();

        if (!$lineItems || !$customer) {
            return;
        }

        $promotionIds = [];
        /** @var OrderLineItemEntity $lineItem */
        foreach ($lineItems as $lineItem) {
            if ($lineItem->getType() !== PromotionProcessor::LINE_ITEM_TYPE) {
                continue;
            }

            

        );
        $response = $this->getBrowser()->getResponse();

        static::assertEquals(Response::HTTP_NO_CONTENT, $response->getStatusCode());

        // read order         $versionContext = $this->context->createWithVersionId($versionId);
        /** @var OrderEntity $order */
        $order = $this->getContainer()->get('order.repository')->search(new Criteria([$orderId])$versionContext)->get($orderId);

        static::assertNotNull($order->getOrderCustomer());

        // recalculate order 2nd time         $this->getBrowser()->request(
            'POST',
            sprintf(
                '/api/_action/order/%s/recalculate',
                $orderId
            ),
            [],
            [],
            [
                
'SELECT `first_name`, `last_name`, `email` FROM `user` WHERE `admin` = 1'
                );
                static::assertIsArray($admin);
                static::assertEquals($mailService->data['recipients'][$admin['email'] => $admin['first_name'] . ' ' . $admin['last_name']]);

                break;
            case 'custom':
                static::assertEquals($mailService->data['recipients']$recipients['data']);

                break;
            default:
                static::assertEquals($mailService->data['recipients'][$order->getOrderCustomer()?->getEmail() => $order->getOrderCustomer()?->getFirstName() . ' ' . $order->getOrderCustomer()?->getLastName()]);
        }

        if ($documentTypeIds !== null && $documentTypeIds !== []) {
            $criteria = new Criteria(array_filter([$documentIdOlder$documentIdNewer]));
            $documents = $documentRepository->search($criteria$context);

            $newDocument = $documents->get($documentIdNewer);
            static::assertNotNull($newDocument);
            static::assertInstanceOf(DocumentEntity::class$newDocument);
            static::assertTrue($newDocument->getSent());

            
$order->setId(Uuid::randomHex());
        $order->setBillingAddressId('order-address-id');
        $order->setCurrencyId('order-currency-id');
        $order->setLanguageId('order-language-id');
        $order->setSalesChannelId(TestDefaults::SALES_CHANNEL);
        $order->setTotalRounding($this->cashRoundingConfig);
        $order->setItemRounding($this->cashRoundingConfig);
        $order->setRuleIds(['order-rule-id-1', 'order-rule-id-2']);
        $order->setTaxStatus(CartPrice::TAX_STATE_FREE);

        if ($toManipulate !== 'order-no-order-customer') {
            $order->setOrderCustomer($this->getOrderCustomer());
        }
        if ($toManipulate !== 'order-no-transactions') {
            $order->setTransactions($orderTransactionCollection);
        }
        if ($toManipulate !== 'order-no-line-items') {
            $order->setLineItems($orderLineItemCollection);
        }
        if ($toManipulate !== 'order-no-deliveries') {
            $order->setDeliveries($orderDeliveryCollection);
        }
        if ($toManipulate !== 'order-no-order-number') {
            


    public static function getAvailableData(): EventDataCollection
    {
        return (new EventDataCollection())
            ->add('order', new EntityType(OrderDefinition::class));
    }

    public function getMailStruct(): MailRecipientStruct
    {
        if (!$this->mailRecipientStruct instanceof MailRecipientStruct) {
            if ($this->order->getOrderCustomer() === null) {
                throw new MailEventConfigurationException('Data for mailRecipientStruct not available.', self::class);
            }

            $this->mailRecipientStruct = new MailRecipientStruct([
                $this->order->getOrderCustomer()->getEmail() => $this->order->getOrderCustomer()->getFirstName() . ' ' . $this->order->getOrderCustomer()->getLastName(),
            ]);
        }

        return $this->mailRecipientStruct;
    }

    


    public function getContext(): Context
    {
        return $this->context;
    }

    public function getMailStruct(): MailRecipientStruct
    {
        if (!$this->mailRecipientStruct instanceof MailRecipientStruct) {
            $this->mailRecipientStruct = new MailRecipientStruct([
                $this->order->getOrderCustomer()?->getEmail() => $this->order->getOrderCustomer()?->getFirstName() . ' ' . $this->order->getOrderCustomer()?->getLastName(),
            ]);
        }

        return $this->mailRecipientStruct;
    }

    public function getSalesChannelId(): string
    {
        return $this->salesChannelId;
    }

    
/** * @param array<string, array<string, bool>|string> $overrideOptions * * @throws InconsistentCriteriaIdsException */
    public function assembleSalesChannelContext(OrderEntity $order, Context $context, array $overrideOptions = []): SalesChannelContext
    {
        if ($order->getTransactions() === null) {
            throw OrderException::missingAssociation('transactions');
        }
        if ($order->getOrderCustomer() === null) {
            throw OrderException::missingAssociation('orderCustomer');
        }

        $customerId = $order->getOrderCustomer()->getCustomerId();
        $customerGroupId = null;

        if ($customerId) {
            /** @var CustomerEntity|null $customer */
            $customer = $this->customerRepository->search(new Criteria([$customerId])$context)->get($customerId);
            if ($customer !== null) {
                $customerGroupId = $customer->getGroupId();
            }
/** * @throws CustomerNotLoggedInException * @throws WrongGuestCredentialsException * @throws GuestNotAuthenticatedException */
    private function checkGuestAuth(?OrderEntity $order, Request $request): void
    {
        if ($order === null) {
            throw new GuestNotAuthenticatedException();
        }

        $orderCustomer = $order->getOrderCustomer();
        if ($orderCustomer === null) {
            throw CartException::customerNotLoggedIn();
        }

        $guest = $orderCustomer->getCustomer() !== null && $orderCustomer->getCustomer()->getGuest();
        // Throw exception when customer is not guest         if (!$guest) {
            throw CartException::customerNotLoggedIn();
        }

        // Verify email and zip code with this order
return $this->orderTransaction;
    }

    public function getContext(): Context
    {
        return $this->context;
    }

    public function getMailStruct(): MailRecipientStruct
    {
        if (!$this->mailRecipientStruct instanceof MailRecipientStruct) {
            $orderCustomer = $this->order->getOrderCustomer();
            if ($orderCustomer === null) {
                throw new AssociationNotFoundException('orderCustomer');
            }

            $this->mailRecipientStruct = new MailRecipientStruct([
                $orderCustomer->getEmail() => $orderCustomer->getFirstName() . ' ' . $orderCustomer->getLastName(),
            ]);
        }

        return $this->mailRecipientStruct;
    }

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