vienthuong / shopware-php-sdk

A PHP SDK for Shopware 6 Admin API
MIT License
112 stars 44 forks source link

Wrong ID mapping on `syncDeleted()` #27

Closed solverat closed 2 years ago

solverat commented 2 years ago

Based on this documentation:

https://shopware.stoplight.io/docs/admin-api/ZG9jOjEyMzA4NTUx-bulk-payloads#deleting-relations

it is currently not possible to clear out relations because of the predefined id key mapping here: https://github.com/vienthuong/shopware-php-sdk/blob/78874d2ed9d74d6e4365b423d0284421bb7f1fa8/src/Repository/EntityRepository.php#L157-L159

Reproduction:

I basically had to do this:

$repository->syncDeleted([
    [
        'productId' => $product->id,
        'optionId'  => $option->id
    ]
], $context);
vienthuong commented 2 years ago

Hi @solverat initially syncDeleted is used as a shortcut of syncService to delete entities by the given array of ids For the association, I guess we need a more general approach but for now you can just use the syncService instead. I might tweak the method later but for now, you can use something like this (or feel free to create a PR)

        $syncService = new SyncService($context);

        $headers = ['fail-on-error' => true];

        $data = [[
            'productId' => $product->id,
            'optionId'  => $option->id
        ]];

        $payload = new SyncPayload();
        $operator = new SyncOperator($entityName, SyncOperator::DELETE_OPERATOR, $data);
        $payload->set($entityName, $operator);

        return $syncService->sync($payload, [], $headers);