Menu Close
    Start a Project Request quote Reading list Switch to dark mode

    How to create custom entity in Shopware6


    This article give you a brief introduction on how to create a custom entity in shopware6.


    If you want to create a custom entity then you need to create entity definition for your table. Shopware 6 uses data abstraction layer query for database.

    Plugin Base Class

    So let’s start with the plugin base class, first of all you need to create service.xml file into the directory <plugin root>/src/Resources/config/. Shopware 6 automatically find your service.xml file then create a custom entity definition class as below.

    The EntityDefinition class

    The main entry point for create custom entity is an EntityDefinition class. Further create a customEntityDefinition.php file into directory <plugin root>/src/Core/Content/Bundle.

    There is no need to create CustomEntityClass and CustomEntityCollection file, it is your choice . it has done without creating entity class and entity collection.

    Registering your custom entity

    Next you need to only register your custom entity definition class into service.xml file. As well as entity is register into DI container.

    This is how your services.xml could look like:

    Creating the table

    In addition to creating the database table create a new directory named src/Migration in your plugin root and add a migration class like this in there:

    Use of custom entity in your logic

    As well as With help of the DI container you can get custom repository. And You can get your entity repository through container.

    I hope it will help you. Thanks for reading 🙂

    . . .


    Add Your Comment

    Be the first to comment.

    Back to Top
    Hire Us!
    Brief us about your requirements and we'll get back to you.
    Woo! Hooy!
    We have just recieved your project brief and our expert will contact you shortly.
    Send Again