setTransactions example

if ($idx === 0) {
                static::assertEquals($parentProductId$lineItem->getId());
            } else {
                static::assertEquals($rootProductId$lineItem->getId());
            }
            ++$idx;
        }
        // set token to be equal for further comparison         $cart->setToken($convertedCart->getToken());

        // transactions are currently not supported so they are excluded for comparison         $cart->setTransactions(new TransactionCollection());

        $this->removeExtensions($cart);
        $this->removeExtensions($convertedCart);

        // remove delivery information from line items
        foreach ($cart->getDeliveries() as $delivery) {
            // remove address from ShippingLocation             $property = ReflectionHelper::getProperty(ShippingLocation::class, 'address');
            $property->setValue($delivery->getLocation(), null);

            
public function testOrderPaymentStatusRuleMatching(bool $expected, string $orderStateId, array $selectedOrderStateIds, string $operator): void
    {
        $stateMachineState = new StateMachineStateEntity();
        $stateMachineState->setTechnicalName(OrderTransactionStates::STATE_IN_PROGRESS);
        $orderTransactionCollection = new OrderTransactionCollection();
        $orderTransaction = new OrderTransactionEntity();
        $orderTransaction->setId(Uuid::randomHex());
        $orderTransaction->setStateId($orderStateId);
        $orderTransaction->setStateMachineState($stateMachineState);
        $orderTransactionCollection->add($orderTransaction);
        $order = new OrderEntity();
        $order->setTransactions($orderTransactionCollection);

        $cart = $this->createMock(Cart::class);
        $context = $this->createMock(SalesChannelContext::class);
        $scope = new FlowRuleScope($order$cart$context);

        $this->rule->assign(['stateIds' => $selectedOrderStateIds, 'operator' => $operator]);
        static::assertSame($expected$this->rule->match($scope));
    }

    public function testInvalidScopeIsFalse(): void
    {
        
$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') {
            $order->setOrderNumber('10000');
        }

        
if ($behavior->hookAware()) {
                $this->executor->execute(new CartHook($cart$context));
            }

            $this->calculateAmount($context$cart);

            $cart->addErrors(
                ...$this->validator->validate($cart$context)
            );

            $cart->setTransactions(
                $this->transactionProcessor->process($cart$context)
            );

            $cart->setRuleIds($context->getRuleIds());

            return $cart;
        }, 'cart');
    }

    private function runProcessors(Cart $original, Cart $cart, SalesChannelContext $context, CartBehavior $behavior): void
    {
        


    public function testThrowsExceptionOnNullPaymentHandler(): void
    {
        $transaction = new OrderTransactionEntity();
        $transaction->setId(Uuid::randomHex());
        $transaction->setStateId($this->ids->get('order-state'));
        $transaction->setPaymentMethodId($this->ids->get('payment'));

        $order = new OrderEntity();
        $order->setUniqueIdentifier($this->ids->get('test-order'));
        $order->setTransactions(new OrderTransactionCollection([$transaction]));

        $orderRepository = $this->createMock(EntityRepository::class);
        $orderRepository
            ->method('search')
            ->willReturn(
                new EntitySearchResult(
                    'order',
                    1,
                    new EntityCollection([$order]),
                    null,
                    new Criteria(),
                    
$transaction1->setId('foo');
        $transaction1->setStateId('foo');

        $transaction2 = new OrderTransactionEntity();
        $transaction2->setId('bar');
        $transaction2->setStateId('bar');

        $transactions = new OrderTransactionCollection([$transaction1$transaction2]);

        $order = new OrderEntity();
        $order->setId('foo');
        $order->setTransactions($transactions);

        $repo = $this->createMock(EntityRepository::class);
        $repo
            ->expects(static::once())
            ->method('search')
            ->willReturn(new EntitySearchResult('order', 1, new OrderCollection([$order]), null, new Criteria(), Context::createDefaultContext()));

        $stateLoader = $this->createMock(InitialStateIdLoader::class);
        $stateLoader
            ->expects(static::once())
            ->method('get')
            
$this->getContainer()->get('customer.repository')->create([$customer], Context::createDefaultContext());

        return $customerId;
    }

    private function fillCart(string $contextToken): void
    {
        $cart = $this->getContainer()->get(CartService::class)->createNew($contextToken);

        $productId = $this->createProduct();
        $cart->add(new LineItem('lineItem1', LineItem::PRODUCT_LINE_ITEM_TYPE, $productId));
        $cart->setTransactions($this->createTransaction());
    }

    private function createProduct(): string
    {
        $productId = Uuid::randomHex();

        $product = [
            'id' => $productId,
            'name' => 'Test product',
            'productNumber' => '123456789',
            'stock' => 1,
            
return $productId;
    }

    private function fillCart(string $contextToken, ?bool $useInactivePaymentMethod = false, ?bool $useFailedPaymentMethod = false): void
    {
        $cart = $this->getContainer()->get(CartService::class)->createNew($contextToken);

        $productId = $this->createProduct();
        $cart->add(new LineItem('lineItem1', LineItem::PRODUCT_LINE_ITEM_TYPE, $productId));

        if ($useInactivePaymentMethod) {
            $cart->setTransactions($this->createTransactionWithInactivePaymentMethod());

            return;
        }
        if ($useFailedPaymentMethod) {
            $cart->setTransactions($this->createTransactionWithFailedPaymentMethod());

            return;
        }
        $cart->setTransactions($this->createTransaction());
    }

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