I have created a custom module (brand) with associated service, workflows, API routes and admin page/components to upsert entries. I have defined links between the module and products. Using CURL I am able to associate a brand with a product using the "additional_data"-parameter sent to "/admin/products". I am currently hooking in to the updateProductsWorkflow.hooks.productsUpdated() to achieve this.
Now I would like to create a custom widget that allows editors to associate a product with a brand while editing a product in the Admin UI.
I have created a widget that injects in the "product.details.side.before"-zone. The widget is fetching all available brands from a custom API-route and maps the entries inside a <Select>-component. This is where I am unsure on how to proceed.
The props passed to the widget contains product-data of type <AdminProduct> which does not contain my "brands" field so in order to fetch the current associated brand for the product I am using the SDK to fetch the product once again with the "?fields=+brand.*" parameters. I am not sure if this is the correct way of doing things.
Now here is where I need help.
In order to edit/update or delete the associated brand (essentially defined links) with the product currently being edited should I:
- Create a workflow that manages linkdefinitions between the brand-module and product that is called from a custom API-route that my widget is requesting?
- Send a POST-request to "/admin/products" from my widget with brand-id in the additional_data-parameter and hook into the updateProductsWorkflow.hooks.productsUpdated()?
- Create a workflow that manages linkdefinitions between the brand and product and call it from the widget directly?
- Do things completely different?
Any help appreciated!