How to add a custom model? ========================== In some cases you may be needing to add new models to your application in order to cover unique business needs. The process of extending Sylius with new entities is simple and intuitive. As an example we will take a **Supplier entity**, which may be really useful for shop maintenance. 1. Define your needs -------------------- A Supplier needs three essential fields: ``name``, ``description`` and ``enabled`` flag. 2. Generate the entity ---------------------- Symfony, the framework Sylius uses, provides the `SymfonyMakerBundle `_ that simplifies the process of adding a model. .. warning:: Remember to have the ``SymfonyMakerBundle`` imported in the AppKernel, as it is not there by default. You need to use such a command in your project directory. With the Maker Bundle .. code-block:: bash php bin/console make:entity The generator will ask you for the entity name and fields. See how it should look like to match our assumptions. .. image:: ../../_images/generating_entity.png :align: center .. note:: You can encounter error when generating entity with Maker Bundle, this can be fixed with `Maker bundle force annotation fix `_ .. image:: ../../_images/make_entity_error.png :align: center 3. Update the database using migrations --------------------------------------- Assuming that your database was up-to-date before adding the new entity, run: .. code-block:: bash php bin/console doctrine:migrations:diff This will generate a new migration file which adds the Supplier entity to your database. Then update the database using the generated migration: .. code-block:: bash php bin/console doctrine:migrations:migrate 4. Add ResourceInterface to your model class -------------------------------------------- Go to the generated class file and make it implement the ``ResourceInterface``: .. code-block:: php `. 10. Check the admin panel for your changes ------------------------------------------ .. tip:: To see what you can do with your new entity access the ``https://localhost:8000/admin/suppliers/`` url. Learn more ---------- * `GridBundle documentation `_ * `ResourceBundle documentation `_ * :doc:`Customization Guide `