getStateId example


        $data = [
            'id' => $ids->create('order' . $i),
            'billingAddressId' => $ids->create('billing-address' . $i),
            'itemRounding' => json_decode(json_encode(new CashRoundingConfig(2, 0.01, true), \JSON_THROW_ON_ERROR), true, 512, \JSON_THROW_ON_ERROR),
            'totalRounding' => json_decode(json_encode(new CashRoundingConfig(2, 0.01, true), \JSON_THROW_ON_ERROR), true, 512, \JSON_THROW_ON_ERROR),
            'currencyId' => Defaults::CURRENCY,
            'languageId' => Defaults::LANGUAGE_SYSTEM,
            'salesChannelId' => TestDefaults::SALES_CHANNEL,
            'orderDateTime' => (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT),
            'currencyFactor' => 1,
            'stateId' => $this->getStateId('open', 'order.state'),
            'price' => new CartPrice(0, 0, 0, new CalculatedTaxCollection()new TaxRuleCollection(), CartPrice::TAX_STATE_GROSS),
            'shippingCosts' => new CalculatedPrice(0, 0, new CalculatedTaxCollection()new TaxRuleCollection()),
            'orderCustomer' => [
                'id' => $ids->get('customer' . $i),
                'salutationId' => $this->getValidSalutationId(),
                'email' => 'test',
                'firstName' => 'test',
                'lastName' => 'test',
            ],
            'addresses' => [
                [
                    

#[Package('checkout')] class OrderTransactionCollection extends EntityCollection
{
    public function filterByState(string $state): self
    {
        return $this->filter(fn (OrderTransactionEntity $transaction) => $transaction->getStateMachineState()->getTechnicalName() === $state);
    }

    public function filterByStateId(string $stateId): self
    {
        return $this->filter(fn (OrderTransactionEntity $transaction) => $transaction->getStateId() === $stateId);
    }

    /** * @return list<string> */
    public function getOrderIds(): array
    {
        return $this->fmap(fn (OrderTransactionEntity $orderTransaction) => $orderTransaction->getOrderId());
    }

    public function filterByOrderId(string $id): self
    {
public function testUpdateOrder(): void
    {
        $ids = new IdsCollection();

        $order = [
            'id' => $ids->get('order'),
            'itemRounding' => json_decode(json_encode(new CashRoundingConfig(2, 0.01, true), \JSON_THROW_ON_ERROR), true, 512, \JSON_THROW_ON_ERROR),
            'totalRounding' => json_decode(json_encode(new CashRoundingConfig(2, 0.01, true), \JSON_THROW_ON_ERROR), true, 512, \JSON_THROW_ON_ERROR),
            'billingAddressId' => $ids->get('billing'),
            'currencyId' => Defaults::CURRENCY,
            'salesChannelId' => TestDefaults::SALES_CHANNEL,
            'stateId' => $this->getStateId(),
            'currencyFactor' => 1,
            'orderDateTime' => new \DateTime(),
            'price' => json_decode(json_encode(new CartPrice(1, 1, 1, new CalculatedTaxCollection()new TaxRuleCollection(), CartPrice::TAX_STATE_FREE), \JSON_THROW_ON_ERROR), true, 512, \JSON_THROW_ON_ERROR),
            'shippingCosts' => json_decode(json_encode(new CalculatedPrice(1, 1, new CalculatedTaxCollection()new TaxRuleCollection()), \JSON_THROW_ON_ERROR), true, 512, \JSON_THROW_ON_ERROR),
        ];

        $this->getContainer()->get('order.repository')
            ->create([$order], Context::createDefaultContext());

        $this->getContainer()->get(Connection::class)
            ->executeStatement('UPDATE `order` SET total_rounding = NULL WHERE id = :id', ['id' => $ids->getBytes('order')]);

        
protected function assertOrderTransactionState(string $state, string $transactionId): void
    {
        $criteria = new Criteria([$transactionId]);
        $criteria->addAssociation('state');

        /** @var OrderTransactionEntity|null $transaction */
        $transaction = $this->orderTransactionRepository->search($criteria$this->context)->first();
        static::assertNotNull($transaction);

        $states = $this->stateMachineRegistry->getStateMachine(OrderTransactionStates::STATE_MACHINE, $this->context)->getStates();
        static::assertNotNull($states);
        $actualState = $states->get($transaction->getStateId());
        static::assertNotNull($actualState);
        static::assertSame($state$actualState->getTechnicalName());
    }

    protected function assertRefundState(string $state, string $refundId): void
    {
        $criteria = new Criteria([$refundId]);
        $criteria->addAssociation('state');

        /** @var OrderTransactionCaptureRefundEntity|null $refund */
        $refund = $this->orderTransactionCaptureRefundRepository->search($criteria$this->context)->first();
        
static::assertSame($serialized['deliveries']['shippingOrderAddress']['company']$shippingAddress->getCompany());
        static::assertSame($serialized['deliveries']['shippingOrderAddress']['department']$shippingAddress->getDepartment());
        static::assertSame($serialized['deliveries']['shippingOrderAddress']['countryId']$shippingAddress->getCountryId());
        static::assertSame($serialized['deliveries']['shippingOrderAddress']['countryStateId']$shippingAddress->getCountryStateId());

        static::assertNotNull($lineItems = $order->getLineItems());
        static::assertNotNull($lineItem = $lineItems->first());

        static::assertSame($serialized['lineItems'], '1x ' . $lineItem->getProductId());

        static::assertSame($serialized['amountTotal']$order->getAmountTotal());
        static::assertSame($serialized['stateId']$order->getStateId());
        static::assertSame($serialized['orderDateTime']$order->getOrderDateTime()->format('Y-m-d\Th:i:s.vP'));
    }

    private function createOrder(): OrderEntity
    {
        // create product         $productId = Uuid::randomHex();
        $product = $this->getProductData($productId);

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


        $state = [
            'technical_name' => 'authorized',
            'translations' => [
                'en-GB' => 'Authorized',
                'de-DE' => 'Autorisiert',
            ],
            'transition' => 'authorize',
            'from' => $this->getStateIds($connection$machineId['open', 'in_progress', 'reminded']),
            'to' => [
                'paid' => $this->getStateId($connection$machineId, 'paid'),
                'paid_partially' => $this->getStateId($connection$machineId, 'paid_partially'),
                'fail' => $this->getStateId($connection$machineId, 'failed'),
                'cancel' => $this->getStateId($connection$machineId, 'cancelled'),
            ],
        ];

        $this->insertState($connection$state$machineId);

        $state = [
            'technical_name' => 'chargeback',
            'translations' => [
                
private function createOrder(TestDataCollection $ids): void
    {
        $data = [
            'id' => $ids->create('order'),
            'orderNumber' => Uuid::randomHex(),
            'billingAddressId' => $ids->create('billing-address'),
            'currencyId' => Defaults::CURRENCY,
            'languageId' => Defaults::LANGUAGE_SYSTEM,
            'salesChannelId' => TestDefaults::SALES_CHANNEL,
            'orderDateTime' => (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT),
            'currencyFactor' => 1,
            'stateId' => $this->getStateId('open', 'order.state'),
            'price' => new CartPrice(200, 200, 200, new CalculatedTaxCollection()new TaxRuleCollection(), CartPrice::TAX_STATE_GROSS),
            'shippingCosts' => new CalculatedPrice(0, 0, new CalculatedTaxCollection()new TaxRuleCollection()),
            'itemRounding' => json_decode(json_encode(new CashRoundingConfig(2, 0.01, true), \JSON_THROW_ON_ERROR), true, 512, \JSON_THROW_ON_ERROR),
            'totalRounding' => json_decode(json_encode(new CashRoundingConfig(2, 0.01, true), \JSON_THROW_ON_ERROR), true, 512, \JSON_THROW_ON_ERROR),
            'ruleIds' => [$ids->get('rule')],
            'orderCustomer' => [
                'id' => $ids->get('order_customer'),
                'salutationId' => $this->getValidSalutationId(),
                'email' => 'test',
                'firstName' => 'test',
                'lastName' => 'test',
                
// read versioned order         $criteria = new Criteria([$orderId]);
        $criteria->addAssociation('lineItems');
        /** @var OrderEntity|null $order */
        $order = $this->getContainer()->get('order.repository')->search($criteria$this->context->createWithVersionId($versionId))->get($orderId);
        static::assertNotNull($order);
        static::assertNotNull($order->getLineItems());
        static::assertSame('test comment', $order->getCustomerComment());
        static::assertSame('test_affiliate_code', $order->getAffiliateCode());
        static::assertSame('test_campaign_code', $order->getCampaignCode());
        static::assertSame($oldOrderStateId$order->getStateId());

        $product = null;
        foreach ($order->getLineItems() as $lineItem) {
            if ($lineItem->getIdentifier() === $productId) {
                $product = $lineItem;
            }
        }

        static::assertNotNull($product);
        static::assertNotNull($product->getPrice());
        $productPriceInclTax = 10 + ($productPrice * $productTaxRate / 100);
        
'id' => $orderTransactionStateMachineId,
                    'initialStateId' => $remindedStateId,
                ],
            ],
            $this->context
        );

        $transactionId = $this->createTransaction($orderId$paymentMethodId$this->context);
        /** @var OrderTransactionEntity $transaction */
        $transaction = $this->orderTransactionRepository->search(new Criteria([$transactionId])$this->context)->first();
        static::assertNotNull($transaction);
        static::assertSame($transaction->getStateId()$remindedStateId);

        $salesChannelContext = $this->getSalesChannelContext($paymentMethodId);
        $response = $this->paymentService->handlePaymentByOrder($orderIdnew RequestDataBag()$salesChannelContext);

        static::assertNotNull($response);
        static::assertEquals(AsyncTestPaymentHandler::REDIRECT_URL, $response->getTargetUrl());
    }

    private function getSalesChannelContext(string $paymentMethodId): SalesChannelContext
    {
        return $this->getContainer()->get(SalesChannelContextFactory::class)
            
$transactions = $order->getTransactions();
        if ($transactions === null || $transactions->count() < 1) {
            return false;
        }

        /** @var OrderTransactionEntity $lastTransaction */
        $lastTransaction = $transactions->last();

        foreach ($transactions as $transaction) {
            if ($transaction->getPaymentMethodId() === $paymentMethodId && $lastTransaction->getId() === $transaction->getId()) {
                $initialState = $this->initialStateIdLoader->get(OrderTransactionStates::STATE_MACHINE);
                if ($transaction->getStateId() === $initialState) {
                    return true;
                }

                try {
                    $this->orderService->orderTransactionStateTransition(
                        $transaction->getId(),
                        StateMachineTransitionActions::ACTION_REOPEN,
                        new ParameterBag(),
                        $context
                    );

                    
$recalculatedCart = $this->recalculateCart($cart$salesChannelContext);

        $conversionContext = (new OrderConversionContext())
            ->setIncludeCustomer(false)
            ->setIncludeBillingAddress(false)
            ->setIncludeDeliveries(true)
            ->setIncludeTransactions(false)
            ->setIncludeOrderDate(false);

        $orderData = $this->orderConverter->convertToOrder($recalculatedCart$salesChannelContext$conversionContext);
        $orderData['id'] = $order->getId();
        $orderData['stateId'] = $order->getStateId();
        if ($order->getDeliveries()?->first()?->getStateId()) {
            $orderData['deliveries'][0]['stateId'] = $order->getDeliveries()->first()->getStateId();
        }

        // change scope to be able to write protected state fields of transactions and deliveries         $context->scope(Context::SYSTEM_SCOPE, function DContext $context) use ($orderData): void {
            $this->orderRepository->upsert([$orderData]$context);
        });
    }

    /** * @throws DeliveryWithoutAddressException * @throws InconsistentCriteriaIdsException * @throws CartException * @throws ProductNotFoundException */

    final public const TECHNICAL_NAME = 'individual_states';

    public function match(TaxRuleEntity $taxRuleEntity, ?CustomerEntity $customer, ShippingLocation $shippingLocation): bool
    {
        if ($taxRuleEntity->getType()->getTechnicalName() !== self::TECHNICAL_NAME
            || !$this->metPreconditions($taxRuleEntity$shippingLocation)
        ) {
            return false;
        }

        $stateId = $this->getStateId($shippingLocation);
        $states = $taxRuleEntity->getData()['states'];

        if (!\in_array($stateId$states, true)) {
            return false;
        }

        if ($taxRuleEntity->getActiveFrom() !== null) {
            return $this->isTaxActive($taxRuleEntity);
        }

        return true;
    }

        if (!$scope instanceof FlowRuleScope) {
            return false;
        }

        if (!$deliveries = $scope->getOrder()->getDeliveries()) {
            return false;
        }

        $deliveryStateIds = [];
        foreach ($deliveries->getElements() as $delivery) {
            $deliveryStateIds[] = $delivery->getStateId();
        }

        return RuleComparison::uuids($deliveryStateIds$this->stateIds, $this->operator);
    }

    public function getConfig(): RuleConfig
    {
        return (new RuleConfig())
            ->operatorSet(RuleConfig::OPERATOR_SET_STRING, false, true)
            ->entitySelectField(
                'stateIds',
                
'created_at' => (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT),
                ]
            );
        } catch (UniqueConstraintViolationException) {
            // don't add state if it already exists             return;
        }

        $this->insertTranslations($stateId$connection);

        // from         $this->insertTransition('process_unconfirmed', $machineId$this->getStateId($connection$machineId, 'open')$stateId$connection);
        $this->insertTransition('process_unconfirmed', $machineId$this->getStateId($connection$machineId, 'reminded')$stateId$connection);
        $this->insertTransition('process_unconfirmed', $machineId$this->getStateId($connection$machineId, 'failed')$stateId$connection);
        $this->insertTransition('process_unconfirmed', $machineId$this->getStateId($connection$machineId, 'cancelled')$stateId$connection);
        $this->insertTransition('process_unconfirmed', $machineId$this->getStateId($connection$machineId, 'paid_partially')$stateId$connection);

        // to         $this->insertTransition('paid', $machineId$stateId$this->getStateId($connection$machineId, 'paid')$connection);
        $this->insertTransition('paid_partially', $machineId$stateId$this->getStateId($connection$machineId, 'paid_partially')$connection);
        $this->insertTransition('fail', $machineId$stateId$this->getStateId($connection$machineId, 'failed')$connection);
        $this->insertTransition('cancel', $machineId$stateId$this->getStateId($connection$machineId, 'cancelled')$connection);
        $this->insertTransition('authorize', $machineId$stateId$this->getStateId($connection$machineId, 'authorized')$connection);
        

        if (!$scope instanceof FlowRuleScope || $this->stateIds === null) {
            return false;
        }

        if (!$transactions = $scope->getOrder()->getTransactions()) {
            return false;
        }

        /** @var OrderTransactionEntity $last */
        $last = $transactions->last();
        $paymentMethodId = $last->getStateId();

        foreach ($transactions->getElements() as $transaction) {
            $technicalName = $transaction->getStateMachineState()?->getTechnicalName();
            if ($technicalName !== null
                && $technicalName !== OrderTransactionStates::STATE_FAILED
                && $technicalName !== OrderTransactionStates::STATE_CANCELLED
            ) {
                $paymentMethodId = $transaction->getStateId();

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