invalidSyncCriteriaException example

$operation->replacePayload($resolved);
            }
        }
    }

    private function handleCriteriaDelete(SyncOperation $operation, Context $context): void
    {
        $definition = $this->registry->getByEntityName($operation->getEntity());

        if (!$definition instanceof MappingEntityDefinition) {
            throw ApiException::invalidSyncCriteriaException($operation->getKey());
        }

        $criteria = $this->criteriaBuilder->fromArray(['filter' => $operation->getCriteria()]new Criteria()$definition$context);

        if (empty($criteria->getFilters())) {
            throw ApiException::invalidSyncCriteriaException($operation->getKey());
        }

        $ids = $this->searcher->search($definition$criteria$context);

        $operation->replacePayload(\array_values($ids->getIds()));
    }
/** * @internal * * @covers \Shopware\Core\Framework\Api\ApiException */
#[Package('core')] class ApiExceptionTest extends TestCase
{
    public function testInvalidSyncCriteriaException(): void
    {
        $exception = ApiException::invalidSyncCriteriaException('operationKey');

        static::assertEquals(ApiException::API_INVALID_SYNC_CRITERIA_EXCEPTION, $exception->getErrorCode());
        static::assertEquals('Sync operation operationKey, with action "delete", requires a criteria with at least one filter and can only be applied for mapping entities', $exception->getMessage());
    }

    public function testInvalidSyncOperationException(): void
    {
        $exception = ApiException::invalidSyncOperationException('message');

        static::assertEquals(ApiException::API_INVALID_SYNC_OPERATION_EXCEPTION, $exception->getErrorCode());
        static::assertEquals('message', $exception->getMessage());
    }
Home | Imprint | This part of the site doesn't use cookies.