CheckoutOrderPlacedEvent example


    public function testSetOrderStatus(array $config, array $expects): void
    {
        $orderId = Uuid::randomHex();
        $context = Context::createDefaultContext();

        $this->orderRepository->create($this->getOrderData($orderId$context)$context);
        $order = $this->orderRepository->search(new Criteria([$orderId])$context)->first();
        $event = new CheckoutOrderPlacedEvent($context$order, TestDefaults::SALES_CHANNEL);

        $subscriber = new SetOrderStateAction(
            $this->getContainer()->get(Connection::class),
            $this->getContainer()->get('logger'),
            $this->getContainer()->get(OrderService::class)
        );

        /** @var FlowFactory $flowFactory */
        $flowFactory = $this->getContainer()->get(FlowFactory::class);
        $flow = $flowFactory->create($event);
        $flow->setConfig($config);

        
$config = array_filter([
            'mailTemplateId' => $mailTemplateId,
            'recipient' => $recipients,
            'documentTypeIds' => $documentTypeIds,
        ]);

        $criteria = new Criteria([$orderId]);
        $criteria->addAssociation('transactions.stateMachineState');
        /** @var OrderEntity $order */
        $order = $orderRepository->search($criteria$context)->first();
        $event = new CheckoutOrderPlacedEvent($context$order, TestDefaults::SALES_CHANNEL);

        $documentIdOlder = null;
        $documentIdNewer = null;
        $documentIds = [];

        if ($documentTypeIds !== null && $documentTypeIds !== [] || $hasOrderSettingAttachment) {
            $documentIdOlder = $this->createDocumentWithFile($orderId$context);
            $documentIdNewer = $this->createDocumentWithFile($orderId$context);
            $documentIds[] = $documentIdNewer;
        }

        

class FlowFactoryTest extends TestCase
{
    public function testCreate(): void
    {
        $ids = new TestDataCollection();
        $order = new OrderEntity();
        $order->setId($ids->get('orderId'));

        $awareEvent = new CheckoutOrderPlacedEvent(Context::createDefaultContext(new AdminApiSource('test'))$order, TestDefaults::SALES_CHANNEL);
        $orderStorer = new OrderStorer($this->createMock(EntityRepository::class)$this->createMock(EventDispatcherInterface::class));
        $flowFactory = new FlowFactory([$orderStorer]);
        $flow = $flowFactory->create($awareEvent);

        static::assertEquals($ids->get('orderId')$flow->getStore('orderId'));
        static::assertInstanceOf(SystemSource::class$flow->getContext()->getSource());
        static::assertEquals(Context::SYSTEM_SCOPE, $flow->getContext()->getScope());
    }

    public function testRestore(): void
    {
        
$criteria->addAssociation('lineItems');

        /** @var OrderEntity|null $order */
        $order = $this->getContainer()
            ->get('order.repository')
            ->search($criteria$this->salesChannelContext->getContext())
            ->first();

        static::assertNotNull($order);

        $dispatcher = $this->getContainer()->get('event_dispatcher');
        $dispatcher->dispatch(new CheckoutOrderPlacedEvent(
            $this->salesChannelContext->getContext(),
            $order,
            $this->salesChannelContext->getSalesChannelId()
        ));

        $this->assertUpdatedCounts();
    }

    public function testItDoesNotFailWithZeroCustomerCount(): void
    {
        $this->createPromotionsAndOrder();

        
$entitySearchResult = $this->createMock(EntitySearchResult::class);
        $entitySearchResult->expects(static::once())
            ->method('get')
            ->willReturn($order);

        $orderRepo = $this->createMock(EntityRepository::class);
        $orderRepo->expects(static::once())
            ->method('search')
            ->willReturn($entitySearchResult);

        $awareEvent = new CheckoutOrderPlacedEvent(Context::createDefaultContext()$order, 'asdsad');

        $orderStorer = new OrderStorer($orderRepo$this->createMock(EventDispatcherInterface::class));
        $flowFactory = new FlowFactory([$orderStorer]);

        $flow = $flowFactory->create($awareEvent);
        $flow->setConfig($config);

        $stringTemplateRender = $this->createMock(StringTemplateRenderer::class);
        $stringTemplateRender->expects(static::exactly(6))
            ->method('render')
            ->willReturnOnConsecutiveCalls(
                
$this->dispatcher = $this->createMock(EventDispatcherInterface::class);
        $logger = $this->createMock(LoggerInterface::class);
        $this->flowFactory = $this->createMock(FlowFactory::class);

        $this->flowDispatcher = new FlowDispatcher($this->dispatcher, $logger$this->flowFactory);
        $this->flowDispatcher->setContainer($this->container);
    }

    public function testDispatchWithNotFlowEventAware(): void
    {
        $order = new OrderEntity();
        $event = new CheckoutOrderPlacedEvent(
            Context::createDefaultContext(),
            $order,
            Defaults::SALES_CHANNEL_TYPE_STOREFRONT
        );

        $this->dispatcher->expects(static::once())->method('dispatch');
        $this->flowDispatcher->dispatch($event);
    }

    public function testDispatchSkipTrigger(): void
    {
        
/** @var OrderEntity|null $orderEntity */
        $orderEntity = Profiler::trace('checkout-order::order-loading', fn () => $this->orderRepository->search($criteria$context->getContext())->first());

        if (!$orderEntity) {
            if (Feature::isActive('v6.6.0.0')) {
                throw CartException::invalidPaymentOrderNotStored($orderId);
            }

            throw new InvalidOrderException($orderId);
        }

        $event = new CheckoutOrderPlacedEvent(
            $context->getContext(),
            $orderEntity,
            $context->getSalesChannel()->getId()
        );

        Profiler::trace('checkout-order::event-listeners', function D) use ($event): void {
            $this->eventDispatcher->dispatch($event);
        });

        $this->cartPersister->delete($context->getToken()$context);

        

        $ids = \array_values($this->ids->getList(['id1', 'id2']));

        $filter = $this->getStockUpdateFilterMock($ids);

        $stockUpdater = new StockUpdater(
            $this->getConnectionMock(),
            $this->dispatcher,
            new StockUpdateFilterProvider([$filter]),
        );

        $event = new CheckoutOrderPlacedEvent(
            Context::createDefaultContext(),
            $this->createOrder(),
            $this->ids->get('sales-channel')
        );

        $stockUpdater->orderPlaced($event);
    }

    public function testStockUpdateFilterOnUpdate(): void
    {
        $ids = \array_values($this->ids->getList(['id1', 'id2']));

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