Борис Думер
Борис Думер

Reputation: 11

Override SyliusCoreBundle Model User

Question pretty much duplicates How to override SyliusCoreBundle Model User but answers in original question doesn't seem to cover it. So the question is:

    sylius_resource:
        resources:
            sylius.user:
                classes:
                    model: myVendor\myBundles\webBundle\Entity\User

but still project uses Sylius\Component\Core\Model\User model.

Upvotes: 1

Views: 344

Answers (1)

Tragaknight
Tragaknight

Reputation: 413

You were almost there, and yes the below steps are not in the book yet - not sure why. Apart from the above you need to change the mapping in sylius.yml which is present in /vendor/sylius/sylius/src/Sylius/Bundle/CoreBundle/Resources/config/app/sylius.yml

Change in two places

sylius_installer:
    classes:
        user:
#            model: Sylius\Component\Core\Model\User # comment this out
            model: Acme\YourBundle\Entity\User

sylius_resource:
    resources:
        sylius.user:
            driver: doctrine/orm
            classes:
#                model: Sylius\Component\Core\Model\User # comment this out
                model: Acme\YourBundle\Entity\User

For your first question :

  1. You need to create a new entity class which extends the original User Model and place it in the above snippet put the path to your new entity class.
  2. In the Entity class you need to define your new fields and then their setters and getters. Also, you need to define an interface as well with the same name as the entity class like : UserInterface.php, just put in the method declarations of your extended entity class and have your entity implement this interface.
  3. Also you need to create an doctrine mapping file in Acme/YourBundle/Resources/config/doctrine/User.orm.xml. You can do through the documentation present at sylius user documentation to see the steps.
  4. Final step is to add the mapping which you have already done in app/config/config.yml.

For your Second question : You can use annotations in the sources you define in your own bundle i.e Acme/YourBundle but within the sylius sub bundles like resourcebundle etc you need to use what is being used within it already.

If there is a better way to doing this - please let me know as well !

Upvotes: 1

Related Questions