vienthuong / shopware-php-sdk

A PHP SDK for Shopware 6 Admin API
MIT License
111 stars 43 forks source link

Does this sdk work with custom entities? #50

Open almare opened 2 years ago

almare commented 2 years ago

I tried to import my products which uses custom entities but without success. Then I tried to get a created product with my custom association also without success. So my question is does this sdk support custom extensions at all? I didn't find any documentation about that topic. Thanks

vienthuong commented 2 years ago

Hi @almare The custom entities is not yet implemented in this SDK and I will try to implement it in the future but unfortunately I am not sure when it will be available. And can you describe more what your specific needs? code example etc?

Any help would welcome :)

larsbo commented 1 year ago

Any progress with custom associations?

Use case: A shopware plugin adds a new entity and an association to an existing entity. if you wan to load the shopware entity together with the new association it not shows up in the result:

$orderRepository = RepositoryFactory::create(OrderDefinition::ENTITY_NAME);

$criteria = new Criteria();
$criteria->addAssociation('custom_entity');

$result = $orderRepository->search($criteria, $context);

The custom association should show up inside the extensions response part: https://github.com/vienthuong/shopware-php-sdk/blob/772876c243b64003094a7bd648d5e92ae446089d/src/Repository/EntityRepository.php#L81

But this doesn't work because of the default Accept header here: https://github.com/vienthuong/shopware-php-sdk/blob/772876c243b64003094a7bd648d5e92ae446089d/src/Repository/EntityRepository.php#L313 If you change this to just application/json the response contains the extension data but the sdk cannot parse it correctly.

larsbo commented 1 year ago

The reason for the missing associations is that the sdk only considers the data part of the response here: https://github.com/vienthuong/shopware-php-sdk/blob/772876c243b64003094a7bd648d5e92ae446089d/src/Hydrate/EntityHydrator.php#L83-L93

And because of the application/vnd.api+json accept header the shopware 6 api but the associations not into the data.extensions part but into a separate included response part:

Bildschirm­foto 2023-03-08 um 14 01 17
Schrank commented 3 months ago

Hi! Same problem here. My impression is, that this API works the same way as Shopware internally, that means if we add the Collection, Definition and Entity then it should work. So it would be cool to have some kind of script which generates the three classes from the counterpart in shopware. Although I'm not sure wether it works that way 🙈