2

We need to extend the Store Group model a bit by adding a couple of fields, needed mostly for external integrations. Following the example here we've added the extra columns to the database. Now we need to extend the input form to populate the fields from Magento admin as well.

I'm only able to find information about the EAV model, but from what I understand that isn't supported here. How should I go about extending the input form?

2
+50

Well the Magento2 admin forms for websites, stores and store groups sadly don't use the eav model or ui components, so you don't have that much of a choice if you want to extend the form and/or the data which is saved/loaded using the form.

The form for the store groups is located in: vendor/module-backend/Block/System/Store/Edit/Form/Store.php

Due to nearly all functions beeing protected in the call tree, maybe the best solution, to add additional form fields to the store group form, is using a preference for the above class.

Following the call tree of _prepareStoreFieldset function, you will see an additional function _initFormValues, called after this one. This is a good place to load your additional attribute values, if this is even necessary.

If you than take a look into the saving process of the store groups located in vendor/module-backend/Controller/Adminhtml/System/Store/Save.php (yes it uses the same controller for saving of websites, stores and store views) you see on line 93 $groupModel->setData($postData['group']);

So if you call your new store group input field, according to its name in the model, this should already handle the saving process of your new store group value.

btw. the store group model extends the AbstractExtensibleModel of Magento, means you also should be able to extend the store group's attributes by using extension_attributes.xml. But extension attributes also do NOT handle the saving and loading process for you. https://devdocs.magento.com/guides/v2.3/extension-dev-guide/extension_attributes/adding-attributes.html

(this answer is for magento CE 2.3.1, on other versions line numbers and so may be different)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.