Search code examples
shopwareshopware6shopware6-apishopware6-app

creating a new entity for shopware 6 and access it through store api


i need help creating custom entity please, i have created an extension inside the Apps directory with AppName/Manifisto.xml and AppName/Resources/entities.xml and activated the extension in admin dashboard but i can't see anything new on dashboard no entity, and i can't access it thought store-api or admin api i used the templates provided in the documentation:

AppName/Manifisto.xml

<?xml version="1.0" encoding="UTF-8"?>
<manifest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/shopware/platform/trunk/src/Core/Framework/App/Manifest/Schema/manifest-1.0.xsd">
<meta>
<name>MyExampleApp</name>
<label>Label</label>
<label lang="de-DE">Name</label>
<description>A description</description>
<description lang="de-DE">Eine Beschreibung</description>
<author>Your Company Ltd.</author>
<copyright>(c) by Your Company Ltd.</copyright>
<version>1.0.0</version>
<icon>Resources/config/plugin.png</icon>
<license>MIT</license>
</meta>
</manifest>

AppName/Resources/entities.xml

<?xml version="1.0" encoding="utf-8" ?>
<entities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/shopware/platform/trunk/src/Core/System/CustomEntity/Xml/entity-1.0.xsd">
<entity name="custom_entity_bundle">
<fields>
<string name="name" required="true" translatable="true"
store-api-aware="true" />
<price name="discount" required="true" store-api-aware="true"/>
<many-to-many name="products" reference="product" store-api-aware="true" />
</fields>
</entity>
</entities>

Solution

  • After you installed and activated the app you should be able to use the Admin-API at the api/custom-entity-bundle resource to POST new entries or PATCH existing ones or GET multiple or a single bundle, like you can do for all "core" entities. This API is automatically generated for you.

    To check if your custom entity was registered successfully during plugin installation you can check the DB and check that the custom_entity_bundle was created in the DB.

    The store-API won't be generated automatically for you, but you can add a custom store-api endpoint to retrieve the data you need via App Scripts.

    The administration UI also won't be generated for you (as of now), so you have to create your own custom module there if you want that the merchant can edit the custom entities himself.