Extending ProductVariant model with a trait

I’m trying to develop a plugin to manage rentals, and I need to add an isRental boolean to the ProductVariant model. So I’m following these instructions to do so by adding a ProductVariantTrait and ProductVariantInterface. But there must be another missing step, because the trait’s methods are not added to the app’s ProductVariant class (and doctrine:schema:update doesn’t see anything to update).

I can make it work by adding “use ProductVariantTrait” to the app’s ProductVariant class, but editing app code defeats the point of using a plugin. I guess I could create an empty inheritance class in the plugin and include the trait from there… but that defeats the point of using a trait! Is there supposed to be some way of getting the trait included from the plugin config? Has anyone done this successfully? Thanks.

Hi there.

You have indeed to create a new ProductVariant class in the tests directory and make it use your newly created trait.
This tests directory is the final application, so in order to use your plugin, one will have to do the same in its own app. So you might want to add that to your README.md :slight_smile: