Save and display ui_component's custom field
-
22-02-2021 - |
Question
I've added custom text box to source form using below code.
<field name="delivery_time" formElement="input" sortOrder="70">
<settings>
<dataType>text</dataType>
<label translate="true">Delivery Time</label>
</settings>
</field>
To save this field value I'm observing event controller_action_inventory_populate_source_with_data
.
I tried below in observer,
$request = $observer->getEvent()->getRequest();
$requestData = $request->getParam('general', []);
$deliveryTime = $requestData['delivery_time'];
I tried below code but it's not working,
$request->setParam('delivery_time',$deliveryTime);
$request->setPostValue('delivery_time',$deliveryTime);
I've created new column with delivery_time to table.
None of above is working Any idea ?
Any help will be appreciate. Thanks in advance.
Solution
To save this you have to create extension attribute for your entity.
https://devdocs.magento.com/guides/v2.3/extension-dev-guide/attributes.html
Check above to know how to create those.
Than you can use in observer like, setter and getter methods like getDeliveryTime
and setDeliveryTime
.
Hope it will help to solve your issue.
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange