createWithVersionId example

$ids = new IdsCollection();

        $product = (new ProductBuilder($ids, 'p1'))->price(100)->build();

        $context = Context::createDefaultContext();

        $this->getContainer()->get('product.repository')->create([$product]$context);

        $versionId = $this->getContainer()->get('product.repository')
            ->createVersion($ids->get('p1')$context);

        $versionContext = $context->createWithVersionId($versionId);

        $this->getContainer()->get('product.repository')
            ->update([['id' => $ids->get('p1'), 'name' => 'test']]$versionContext);

        // now ensure that we get a validate event for the merge request         $called = false;

        $this->addEventListener(
            $this->getContainer()->get('event_dispatcher'),
            PreWriteValidationEvent::class,
            function DPreWriteValidationEvent $event) use (&$called): void {
                
public function testGetSubscribedEvents(): void
    {
        $events = OrderStockSubscriber::getSubscribedEvents();

        static::assertArrayHasKey(StateMachineTransitionEvent::class$events);
        static::assertArrayHasKey(EntityWriteEvent::class$events);
    }

    public function testBeforeWriteCanBeDisabled(): void
    {
        $context = Context::createDefaultContext()->createWithVersionId($this->ids->create('version'));

        $stockStorage = $this->createMock(StockStorage::class);
        $stockStorage->expects(static::never())->method('alter');

        $stockSubscriber = new OrderStockSubscriber(
            $this->createMock(Connection::class),
            $stockStorage,
            false
        );

        $event = EntityWriteEvent::create(
            
new StaticDefinitionInstanceRegistry(
            [$definition = new ProductDefinition()],
            $this->createMock(ValidatorInterface::class),
            $this->createMock(EntityWriteGatewayInterface::class)
        );

        return $definition;
    }

    public function testBeforeWriteOnlyReactsToLiveVersions(): void
    {
        $context = Context::createDefaultContext()->createWithVersionId($this->ids->create('version'));

        $subscriber = new AvailableStockMirrorSubscriber();

        $definition = $this->getDefinition();

        $command = new UpdateCommand(
            $definition,
            ['stock' => 10],
            ['id' => $this->ids->getBytes('product-1')],
            new EntityExistence(
                ProductDefinition::ENTITY_NAME,
                [
if ($name) {
            $versionData['name'] = $name;
        }

        $context->scope(Context::SYSTEM_SCOPE, function D$context) use ($versionData): void {
            $this->entityWriter->upsert($this->versionDefinition, [$versionData]$context);
        });

        $affected = $this->cloneEntity($definition$id$id$versionId$contextnew CloneBehavior());

        $versionContext = $context->createWithVersionId($versionId);

        $event = EntityWrittenContainerEvent::createWithWrittenEvents($affected$versionContext->getContext()[]);
        $this->eventDispatcher->dispatch($event);

        $this->writeAuditLog($affected$context$versionId, true);

        return $versionId;
    }

    public function merge(string $versionId, WriteContext $writeContext): void
    {
        
static::assertEquals('foo', $context->getScope());
        });

        static::assertEquals(Context::SYSTEM_SCOPE, $context->getScope());
    }

    public function testVersionChange(): void
    {
        $versionId = Uuid::randomHex();

        $context = Context::createDefaultContext();
        $versionContext = $context->createWithVersionId($versionId);

        static::assertEquals(Defaults::LIVE_VERSION, $context->getVersionId());
        static::assertEquals($versionId$versionContext->getVersionId());
    }

    public function testVersionChangeInheritsExtensions(): void
    {
        $context = Context::createDefaultContext();
        $context->addExtension('foo', new ArrayEntity());

        static::assertNotNull($context->getExtension('foo'));

        

            [],
            [
                'HTTP_' . PlatformRequest::HEADER_VERSION_ID => $versionId,
            ]
        );
        $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
            ),
return $this->context;
    }

    public function resetPaths(): void
    {
        $this->paths = [];
        $this->set(LanguageDefinition::ENTITY_NAME, 'id', $this->context->getLanguageId());
    }

    public function createWithVersionId(string $versionId): self
    {
        return self::createFromContext($this->getContext()->createWithVersionId($versionId));
    }

    public function getExceptions(): WriteException
    {
        return $this->exceptions;
    }

    /** * @param callable(WriteContext): void $callback */
    public function scope(string $scope, callable $callback): void
    {


    public function testTranslationsAreAllSelectable(): void
    {
        $enContext = Context::createDefaultContext();
        $manufacturerId = Uuid::randomHex();
        $manufacturerRepository = $this->getContainer()->get('product_manufacturer.repository');

        $this->createManufacturer($manufacturerRepository$manufacturerId$enContext);

        $versionId = $manufacturerRepository->createVersion($manufacturerId$enContext);
        $enVersionContext = $enContext->createWithVersionId($versionId);
        $deContext = $this->createDeContext($enContext);
        $deVersionContext = $deContext->createWithVersionId($versionId);

        $manufacturerRepository->update([[
            'id' => $manufacturerId,
            'name' => 'version-en-GB',
        ]]$enVersionContext);

        $manufacturerRepository->update([[
            'id' => $manufacturerId,
            'name' => 'version-de-DE',
        ]],
static::assertNull($categories->get($categoryA)->getPath());
        static::assertEquals("|{$categoryA}|", $categories->get($categoryB)->getPath());
        static::assertEquals("|{$categoryA}|", $categories->get($categoryC)->getPath());
        static::assertEquals("|{$categoryA}|{$categoryC}|", $categories->get($categoryD)->getPath());

        static::assertEquals(1, $categories->get($categoryA)->getLevel());
        static::assertEquals(2, $categories->get($categoryB)->getLevel());
        static::assertEquals(2, $categories->get($categoryC)->getLevel());
        static::assertEquals(3, $categories->get($categoryD)->getLevel());

        $versionId = $this->categoryRepository->createVersion($categoryD$this->context);
        $versionContext = $this->context->createWithVersionId($versionId);

        /** @var CategoryEntity $category */
        $category = $this->categoryRepository->search(new Criteria([$categoryD])$versionContext)->first();
        static::assertInstanceOf(CategoryEntity::class$category);
        static::assertEquals('|' . $categoryA . '|' . $categoryC . '|', $category->getPath());

        // update parent of last category in version scope         $updated = ['id' => $categoryD, 'parentId' => $categoryA];

        $this->categoryRepository->update([$updated]$versionContext);

        
public function testCustomFieldOrderVersioning(): void
    {
        $id = Uuid::randomHex();
        $versionId = $this->context->getVersionId();

        $order = $this->getOrderFixture($id$versionId);

        // create order + order version and belonging context         $this->orderRepository->create([$order]$this->context);
        $versionedOrderId = $this->orderRepository->createVersion($id$this->context);
        $versionedContext = $this->context->createWithVersionId($versionedOrderId);

        /** @var OrderEntity $order */
        $order = $this->orderRepository->search(new Criteria([$id])$this->context)->first();

        /** @var OrderEntity $versionedOrder */
        $versionedOrder = $this->orderRepository->search(new Criteria([$id])$versionedContext)->first();

        // custom fields should be correctly copied from original order to versioned order         static::assertEquals($order->getCustomFields()$versionedOrder->getCustomFields());
    }

    
$order = $this->getOrderFixture($this->ids->get('o1')$context->getVersionId());

        $this->getContainer()->get('order.repository')->create([$order]$context);

        $versionId = $this->getContainer()->get('order.repository')->createVersion(
            $this->ids->get('o1'),
            $context,
            Uuid::randomHex(),
            Uuid::randomHex()
        );

        $versionContext = Context::createDefaultContext()->createWithVersionId($versionId);

        $orders = [
            [
                'id' => $this->ids->get('o1'),
                'tags' => [
                    ['id' => $this->ids->get('g')],
                ],
            ],
        ];

        $this->getContainer()->get('order.repository')->update($orders$versionContext);

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

        $event = $priceRepository->create([$price]$context);
        $productEvent = $event->getEventByEntityName('product');

        static::assertInstanceOf(EntityWrittenEvent::class$productEvent);
        static::assertEquals([$id]$productEvent->getIds());

        $versionId = $this->productRepository->createVersion($id$context);
        $version = $context->createWithVersionId($versionId);

        $priceRepository->delete([['id' => $id]]$version);

        $commits = $this->getCommits('product', $id$versionId);
        static::assertCount(1, $commits);

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

        $event = $mappingRepository->delete([['productId' => $id, 'categoryId' => $categoryId]]$version);

        
'id' => $id,
                'name' => 'sub 1',
            ],
        ];

        $context = Context::createDefaultContext();

        $this->repository->create([$data]$context);

        $versionId = $this->repository->createVersion($id$context);

        $versionContext = $context->createWithVersionId($versionId);

        $this->repository->update([
            [
                'id' => $id,
                'name' => 'updated root',
                'subCascade' => [
                    'id' => $id,
                    'name' => 'updated sub',
                ],
            ],
        ]$versionContext);

        
if (!Uuid::isValid($entityId)) {
            throw ApiException::invalidVersionId($versionId);
        }

        try {
            $entityDefinition = $this->definitionRegistry->getByEntityName($this->urlToSnakeCase($entity));
        } catch (DefinitionNotFoundException $e) {
            throw ApiException::definitionNotFound($e);
        }

        $versionContext = $context->createWithVersionId($versionId);

        $entityRepository = $this->definitionRegistry->getRepository($entityDefinition->getEntityName());

        $versionContext->scope(Context::CRUD_API_SCOPE, function DContext $versionContext) use ($entityId$entityRepository): void {
            $entityRepository->delete([['id' => $entityId]]$versionContext);
        });

        $versionRepository = $this->definitionRegistry->getRepository('version');
        $versionRepository->delete([['id' => $versionId]]$context);

        return new JsonResponse();
    }
public function getDecorated(): AbstractDocumentRenderer
    {
        throw new DecorationPatternException(self::class);
    }

    private function getOrder(string $orderId, string $versionId, Context $context, string $deepLinkCode = ''): OrderEntity
    {
        ['language_id' => $languageId] = $this->getOrdersLanguageId([$orderId]$versionId$this->connection)[0];

        // Get the correct order with versioning from reference invoice         $versionContext = $context->createWithVersionId($versionId)->assign([
            'languageIdChain' => array_unique(array_filter([$languageId$context->getLanguageId()])),
        ]);

        $criteria = OrderDocumentCriteriaFactory::create([$orderId]$deepLinkCode)
            ->addFilter(new EqualsFilter('lineItems.type', LineItem::CREDIT_LINE_ITEM_TYPE));

        /** @var ?OrderEntity $order */
        $order = $this->orderRepository->search($criteria$versionContext)->get($orderId);

        if ($order) {
            return $order;
        }
Home | Imprint | This part of the site doesn't use cookies.