I’m trying to create a one-to-many relationship with additional attributes between my custom model and Magento products.
My expected workflow is the following:
- Create a database table called custommodel_product which contains the following columns:
- entity_id
- custommodel_id (with foreign key pointing to my custom model table)
- product_id (with foreign key pointing to Magento product table)
- position
- […]
- Add an input of type on the backend product new/edit page, consisting in:
- Create a data source PHP class that fetches a list of all instances of my custom model to display it in form
- Override product_form.xml in my module and add a with the class previously created as data source/options.
- Override product_listing.xml in my module and add a to display my custom model ID or attribute in product listing table.
- When saving a new/edited product, add/update row in my custom relationship table (custommodel_product)
- Create a class (?) that fetches all product entities from a instance of my custom model.
- Create a class (?) that fetches the custom model instance linked to a product if exists.
- When deleting a product or a shop, delete all rows in relationship table (custommodel_product) linked to the product/shop deleted.
My questions are:
- Is my workflow correct? Did I miss something, or does it contains incorrect/wrong steps ?
- How to implement this workflow ?
Note: For the moment, I’ve created the relationship table and also created a custom model/resource model as shown in this Magento StackExchange topic, but with additional attributes in the table (position, etc). It works more or less, but now I’m stuck, and I can’t manage to continue my workflow.