cancel
Showing results for 
Search instead for 
Did you mean: 

Custom field in order creation form

Custom field in order creation form

Hello everyone,

 

I have added a custom field to the admin order creation form and it seems to work well.

The only issue is that when I submit the new order, I don't see my field value in the order_save_before event observer. What am I missing?

 

Here is the way I added the field:

/Vendor/Module/view/adminhtml/layout/sales_order_create_index.xml

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <head>
    </head>
    <body>
        <referenceBlock name="content">
            <block class="Vendor\Module\Block\Adminhtml\Order\Create\MyCustomField" name="my_custom_field" template="Vendor_Module::order/create/my_custom_field.phtml" after="billing_address"/>
        </referenceBlock>
    </body>
</page>

 

/Vendor/Module/Block/Adminhtml/Order/Create/MyCustomField
class MyCustomField extends Magento\Sales\Block\Adminhtml\Order\Create\AbstractCreate
{
    /**
     * Constructor
     */
    public function _construct()
    {
        parent::_construct();
    }
}
 
/Vendor/Module/view/adminhtml/templates/order/create/my_custom_field.phtml
<input type="text" name="order[customfield]" value="customvalue"/>
 
Thanks a lot for your answers.
3 REPLIES 3

Re: Custom field in order creation form

Hi Davidfiaty,

 

My advice for you: Never edit the core files . And before you make any customization, look on github if there is already a similar extension for your task and then customize that.

 

Best Regards

Re: Custom field in order creation form

@thinkcells I don't understand your answer.

First, I am not editing any core file, and this is not even mentioned anywhere in my question. 

Second, my question is very specific. I have looked at existing extensions, which helped me to add a field to the order edit form.

 

I am having an issue retrieving a value after order submit, which is why I posted the question.

You don't have to answer if you don't have anything constructive or relevant to say.

 

Thank you.

Re: Custom field in order creation form

In the code posted above, /Vendor/Module is not a core magento 2 path.

It's a path to my custom module. "Vendor" is my brand, "Module" is my module.

The path /Vendor/Module doesn't exist in Magento 2 core.