SyncBehavior example

->media('media-3')
            ->build();

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

        $operations = [
            new SyncOperation('delete-media', 'product_media', 'delete', [['id' => $ids->get('media-2')]]),
            new SyncOperation('update-product', 'product', 'upsert', [['id' => $ids->get('p1'), 'media' => [['id' => $ids->get('media-3'), 'position' => 10]]]]),
        ];

        $this->service->sync($operations, Context::createDefaultContext()new SyncBehavior());
    }

    public function testSingleOperationWithDeletesAndWrites(): void
    {
        $ids = new TestDataCollection();

        $currency = [
            'name' => 'test',
            'factor' => 2,
            'symbol' => '€',
            'itemRounding' => json_decode(json_encode(new CashRoundingConfig(2, 0.01, true), \JSON_THROW_ON_ERROR), true, 512, \JSON_THROW_ON_ERROR),
            

    public function sync(array $payload): SyncResult
    {
        $operations = [];
        foreach ($payload as $key => $operation) {
            if (isset($operation['key'])) {
                $key = $operation['key'];
            }
            $operations[] = new SyncOperation((string) $key(string) $operation['entity'](string) $operation['action']$operation['payload']);
        }

        return $this->syncService->sync($operations$this->context, new SyncBehavior());
    }
}
'write',
                ProductDefinition::ENTITY_NAME,
                SyncOperation::ACTION_UPSERT,
                $payload
            ),
            new SyncOperation(
                'write',
                ProductConfiguratorSettingDefinition::ENTITY_NAME,
                SyncOperation::ACTION_UPSERT,
                $configuratorSettingPayload
            ),
        ], Context::createDefaultContext()new SyncBehavior());
    }

    public function reset(): void
    {
        $this->groupIdCache = [];
        $this->optionIdCache = [];
    }

    /** * convert "size: m, l, xl" to ["size|m", "size|l", "size|xl"] * * @return list<array<string>> */
/** * @throws ConnectionException * @throws InvalidSyncOperationException */
    #[Route(path: '/api/_action/sync', name: 'api.action.sync', methods: ['POST'])]     public function sync(Request $request, Context $context): JsonResponse
    {
        /** @var list<string> $indexingSkips */
        $indexingSkips = array_filter(explode(',', (string) $request->headers->get(PlatformRequest::HEADER_INDEXING_SKIP, '')));

        $behavior = new SyncBehavior(
            $request->headers->get(PlatformRequest::HEADER_INDEXING_BEHAVIOR),
            $indexingSkips
        );

        $payload = $this->serializer->decode($request->getContent(), 'json');

        $operations = [];
        foreach ($payload as $key => $operation) {
            if (isset($operation['key'])) {
                $key = $operation['key'];
            }
            
$upsert = new SyncOperation('foo', 'product', SyncOperation::ACTION_UPSERT, [
            ['id' => '1', 'name' => 'foo'],
            ['id' => '2', 'name' => 'bar'],
        ]);

        $delete = new SyncOperation('delete-foo', 'product', SyncOperation::ACTION_DELETE, [
            ['id' => '1'],
            ['id' => '2'],
        ]);

        $behavior = new SyncBehavior('disable-indexing', ['product.indexer']);
        $result = $service->sync([$upsert$delete], Context::createDefaultContext()$behavior);

        static::assertSame([
            'product' => [
                'deleted-id',
            ],
        ]$result->getDeleted());

        static::assertSame([
            'product' => [
                'created-id',
            ],

    private function createNewCategories(array $payload): void
    {
        $this->syncService->sync([
            new SyncOperation(
                'write',
                CategoryDefinition::ENTITY_NAME,
                SyncOperation::ACTION_UPSERT,
                $payload
            ),
        ], Context::createDefaultContext()new SyncBehavior());
    }
}
Home | Imprint | This part of the site doesn't use cookies.