0

I've successfully added custom attribute to checkout and when creating the order is saving in quote, and order table, but how to implement the same when creating an order via admin backend?

Thx in advance!

0

Use plugin around the parent Magento\Sales\Block\Adminhtml\Order\Create\Data blocks getChildHtml method. Within the plugin I then check the name of the block being rendered and inject my new block where appropriate. E.g

etc/adminhtml/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Sales\Block\Adminhtml\Order\Create\Data">
        <plugin name="after_order_create_data" type="Namespace\Module\Plugin\Sales\Block\Adminhtml\Order\Create\DataPlugin" sortOrder="10"/>
    </type>
</config>

view/adminhtml/layout/sales_order_create_index.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">

    <body>
        <referenceBlock name="data">
            <block class="Namespace\Module\Block\Adminhtml\Order\Create\Form\CustomBlock" template="Namespace_Module::order/create/form/newsection.phtml" name="newcustom_filed" />
        </referenceBlock>
    </body>
</page>

Plugin/Sales/Block/Adminhtml/Order/Create/DataPlugin.php

<?php
namespace Namespace\Module\Plugin\Sales\Block\Adminhtml\Order\Create;

class DataPlugin
{

    public function aroundGetChildHtml(\Magento\Sales\Block\Adminhtml\Order\Create\Data $subject, callable $proceed, $id, $useCache = true)
    {
        $html = $proceed($id, $useCache);

        if ($id == 'form_account') { // <- different sections can be targeted by changing block name
            $block = $subject->getChildHtml('newcustom_filed');
            $html = $html . $block;
        }

        return $html;
    }
}

view/adminhtml/templates/order/create/form/newsection.phtml

<!-- we are injecting into an existing section so close it first and then open new one. This may need to be adjusted depending on what block the new block is injected in -->
</section> 

<section id="order-customblock" class="admin__page-section order-customblock">

   <!-- put new block content here -->

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.