order example

->create([$product]$salesChannelContext->getContext());
        $this->addTaxDataToSalesChannel($salesChannelContext$product['tax']);

        $lineItem = (new ProductLineItemFactory(new PriceDefinitionFactory()))->create(['id' => $productId, 'referencedId' => $productId]$salesChannelContext);

        $cart = $cartService->getCart($salesChannelContext->getToken()$salesChannelContext);

        $cart = $cartService->add($cart$lineItem$salesChannelContext);

        static::assertTrue($cart->has($productId));

        $orderId = $cartService->order($cart$salesChannelContextnew RequestDataBag());

        /** @var EntityRepository $orderRepository */
        $orderRepository = $this->getContainer()->get('order.repository');

        /** @var OrderEntity $order */
        $order = $orderRepository->search(new Criteria([$orderId])$salesChannelContext->getContext())->first();

        static::assertEquals($order->getLanguageId()$this->getDeDeLanguageId());
    }

    public function testOrderCartEn(): void
    {
// Search         if (isset($filters['search'])) {
            $filter = '%' . $filters['search'] . '%';

            $stmt->where('(s.namespace LIKE ? OR s.name LIKE ? OR s.value LIKE ?)', $filter);
            $secondStmt->where('(s1.namespace LIKE ? OR s1.name LIKE ? OR s1.value LIKE ?)', $filter);
        }

        $selectUnion = $this->database->select()->union(['(' . $stmt . ')', '(' . $secondStmt . ')'], Zend_Db_Select::SQL_UNION_ALL);

        if (!empty($order)) {
            $selectUnion->order($order['property'] . ' ' . $order['direction']);
        } else {
            $selectUnion->order('namespace');
        }

        $selectUnion->limit($limit$start);

        $countStmt = clone $selectUnion;
        $countStmt->reset('limitcount')
            ->reset('limitoffset');

        $sql = 'SELECT COUNT(*) FROM (' . $countStmt . ') as counter';
        
$cart = $this->itemRemoveRoute->remove($request$cart$context)->getCart();

        return $this->cart[$cart->getToken()] = $cart;
    }

    /** * @throws InconsistentCriteriaIdsException */
    public function order(Cart $cart, SalesChannelContext $context, RequestDataBag $data): string
    {
        $orderId = $this->orderRoute->order($cart$context$data)->getOrder()->getId();

        if (isset($this->cart[$cart->getToken()])) {
            unset($this->cart[$cart->getToken()]);
        }

        $cart = $this->createNew($context->getToken());
        $this->eventDispatcher->dispatch(new CartChangedEvent($cart$context));

        return $orderId;
    }

    
// now we test that the product can be added to a customers cart         $cart = $this->addProductToCart($product->id, $context);

        $this->assertLineItemInCart($cart$product->id);

        $this->assertLineItemUnitPrice($cart$product->id, 100);

        $this->assertLineItemTotalPrice($cart$product->id, 100);

        $orderId = $this->mailListener(function DMailEventListener $listener) use ($cart$context) {
            $orderId = $this->order($cart$context);

            $listener->assertSent('order_confirmation_mail');

            return $orderId;
        });

        $item = $this->assertProductInOrder($orderId$product->id);

        static::assertEquals(100, $item->getUnitPrice());

        static::assertEquals(100, $item->getTotalPrice());

        
$this->deliveryNoteRenderer = $this->getContainer()->get(DeliveryNoteRenderer::class);
        $this->cartService = $this->getContainer()->get(CartService::class);
    }

    /** * @dataProvider deliveryNoteRendererDataProvider */
    public function testRender(string $deliveryNoteNumber, \Closure $assertionCallback): void
    {
        $cart = $this->generateDemoCart(3);

        $orderId = $this->cartService->order($cart$this->salesChannelContext, new RequestDataBag());

        $operation = new DocumentGenerateOperation($orderId, FileTypes::PDF, [
            'documentNumber' => $deliveryNoteNumber,
            'itemsPerPage' => 2,
        ]);

        $caughtEvent = null;

        $this->getContainer()->get('event_dispatcher')
            ->addListener(DeliveryNoteOrdersEvent::classfunction DDeliveryNoteOrdersEvent $event) use (&$caughtEvent): void {
                $caughtEvent = $event;
            });

    protected function _order(Zend_Db_Table_Select $select$order)
    {
        if (!is_array($order)) {
            $order = array($order);
        }

        foreach ($order as $val) {
            $select->order($val);
        }

        return $select;
    }

    /** * Support method for fetching rows. * * @param Zend_Db_Table_Select $select query options. * @return array An array containing the row results in FETCH_ASSOC mode. */
    
$cart = $this->getContainer()->get(CartService::class)
            ->getCart($context->getToken()$context);

        return $this->getContainer()->get(CartService::class)
            ->add($cart$product$context);
    }

    protected function order(Cart $cart, SalesChannelContext $context, ?RequestDataBag $data = null): string
    {
        return $this->getContainer()->get(CartService::class)
            ->order($cart$context$data ?? new RequestDataBag());
    }

    protected function assertProductInOrder(string $orderId, string $productId): OrderLineItemEntity
    {
        $criteria = new Criteria();
        $criteria->setLimit(1);

        $criteria->addFilter(new AndFilter([
            new EqualsFilter('referencedId', $productId),
            new EqualsFilter('type', LineItem::PRODUCT_LINE_ITEM_TYPE),
            new EqualsFilter('orderId', $orderId),
        ]));
$factory = new ProductLineItemFactory(new PriceDefinitionFactory());
        $lineItem = $factory->create(['id' => $id, 'referencedId' => $id, 'quantity' => $quantity]$this->context);

        $cart = $this->cartService->getCart($this->context->getToken()$this->context);

        $cart = $this->cartService->add($cart$lineItem$this->context);

        $item = $cart->get($id);
        static::assertInstanceOf(LineItem::class$item);
        static::assertSame($quantity$item->getQuantity());

        return $this->cartService->order($cart$this->context, new RequestDataBag());
    }

    private function transitionOrder(string $orderId, string $transition): void
    {
        $registry = $this->getContainer()->get(StateMachineRegistry::class);
        $transitionObject = new Transition('order', $orderId$transition, 'stateId');

        $registry->transition($transitionObject, Context::createDefaultContext());
    }
}
/** * @param array<int, string[]>|null $productDownloads */
    private function placeOrder(?array $productDownloads = null): string
    {
        $productDownloads ??= [[]];

        $cart = $this->cartService->createNew($this->salesChannelContext->getToken());
        $cart = $this->addProducts($cart$productDownloads);

        return $this->cartService->order($cart$this->salesChannelContext, new RequestDataBag());
    }

    /** * @param array<int, string[]> $productDownloads */
    private function assertOrderWithoutGrantedAccess(string $orderId, array $productDownloads): string
    {
        $criteria = new Criteria([$orderId]);
        $criteria->addAssociation('lineItems.downloads');
        $criteria->addAssociation('deliveries');

        
$dispatcher = $this->getContainer()->get('event_dispatcher');

        $phpunit = $this;
        $eventDidRun = false;
        $listenerClosure = function DMailSentEvent $event) use (&$eventDidRun$phpunit): void {
            $eventDidRun = true;
            $phpunit->assertStringContainsString('Shipping costs: €0.00', $event->getContents()['text/html']);
        };

        $this->addEventListener($dispatcher, MailSentEvent::class$listenerClosure);

        $cartService->order($cart$contextnew RequestDataBag());

        $dispatcher->removeListener(MailSentEvent::class$listenerClosure);

        static::assertTrue($eventDidRun, 'The mail.sent Event did not run');
    }

    public function testCartCreatedWithGivenToken(): void
    {
        $salesChannelContextFactory = $this->getContainer()->get(SalesChannelContextFactory::class);
        $context = $salesChannelContextFactory->create(Uuid::randomHex(), TestDefaults::SALES_CHANNEL);

        
$this->documentGenerator = $this->getContainer()->get(DocumentGenerator::class);
    }

    /** * @dataProvider stornoNoteRendererDataProvider * * @param array<string, string> $additionalConfig */
    public function testRender(array $additionalConfig, \Closure $assertionCallback): void
    {
        $cart = $this->generateDemoCart([7, 31]);
        $orderId = $this->cartService->order($cart$this->salesChannelContext, new RequestDataBag());

        $invoiceConfig = new DocumentConfiguration();
        $invoiceConfig->setDocumentNumber('1001');

        $operationInvoice = new DocumentGenerateOperation($orderId, FileTypes::PDF, $invoiceConfig->jsonSerialize());

        $result = $this->documentGenerator->generate(InvoiceRenderer::TYPE, [$orderId => $operationInvoice]$this->context)->getSuccess()->first();
        static::assertNotNull($result);
        $invoiceId = $result->getId();

        $config = [
            
static::assertInstanceOf(OrderEntity::class$order);
        static::assertInstanceOf(TagCollection::class$order->getTags());
        static::assertContains($ids->get('tag-1')$order->getTags()->getIds());
        static::assertContains($ids->get('tag-2')$order->getTags()->getIds());
    }

    private function placeOrder(IdsCollection $ids): void
    {
        $cart = $this->cartService->createNew($this->salesChannelContext->getToken());
        $cart = $this->addProducts($cart$ids);

        $ids->set('order', $this->cartService->order($cart$this->salesChannelContext, new RequestDataBag()));
    }

    private function addProducts(Cart $cart, IdsCollection $ids): Cart
    {
        $taxIds = $this->salesChannelContext->getTaxRules()->getIds();
        $ids->set('t1', (string) array_pop($taxIds));

        $this->productRepository->create([
            (new ProductBuilder($ids, 'product'))
                ->price(100)
                ->tax('t1')
                
$this->createFailedPaymentMethodData();

        $contextToken = Uuid::randomHex();

        $this->fillCart($contextToken, false, true);

        $requestDataBag = $this->createRequestDataBag('');
        $salesChannelContext = $this->createSalesChannelContext($contextToken, true);
        $request = $this->createRequest();

        /** @var RedirectResponse|Response $response */
        $response = $this->getContainer()->get(CheckoutController::class)->order($requestDataBag$salesChannelContext$request);

        static::assertInstanceOf(RedirectResponse::class$response);
        static::assertStringContainsString('/account/order/edit', $response->getTargetUrl(), 'Target Url does not point to /checkout/finish');
    }

    public function testAffiliateAndCampaignTracking(): void
    {
        $request = $this->createRequest();
        $request->getSession()->set(AffiliateTrackingListener::AFFILIATE_CODE_KEY, self::TEST_AFFILIATE_CODE);
        $request->getSession()->set(AffiliateTrackingListener::CAMPAIGN_CODE_KEY, self::TEST_CAMPAIGN_CODE);

        
/** * @internal */
#[Package('checkout')] trait DocumentTrait
{
    use IntegrationTestBehaviour;
    use TaxAddToSalesChannelTestBehaviour;

    private function persistCart(Cart $cart): string
    {
        return $this->getContainer()->get(CartService::class)->order($cart$this->salesChannelContext, new RequestDataBag());
    }

    /** * @param array<string, string> $options */
    private function createCustomer(array $options = []): string
    {
        $customerId = Uuid::randomHex();
        $addressId = Uuid::randomHex();

        $customer = [
            
/** * @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,
        string $transition,
        ParameterBag $data,
        Context $context
    ): StateMachineStateEntity {
        
Home | Imprint | This part of the site doesn't use cookies.