1

I need to add new block to admin order create form (in totals section). First I tried to do it by adding sales_order_create_index.xml to my module and adding my block to

<referenceBlock name="data">

but it did not work and it's because all child blocks of "data" block are called in data.phtml with $block->getChildHtml() method.

UPDATE

Now I decited to use plugins instead, I added plugin to Magento\Sales\Block\Adminhtml\Order\Create\Data like this

class DataPlugin
{
    public function beforegetChildHtml($subject, $alias = '', $useCache = true){

       if($alias=='totals'){
          echo 'test';
       }

    }
}

And it's works. But how I can insert my block here instead of printing text

1 Answer 1

2

This is the way I can insert my custom block

namespace Exto\StoreCredit\Model\Plugin\Admin\Order\Create;

 class DataPlugin extends \Magento\Backend\Block\Template
 {

    public function beforegetChildHtml($subject, $alias = '', $useCache = true){
     if($alias=='totals'){
        echo $this->getLayout()
        ->createBlock('\Magento\Backend\Block\Template')
        ->setTemplate('Vendor_Module::test.phtml')
        ->toHtml();
     }

}

}

1
  • I need to create custom block in admin create form ....I follow ur steps ....But not working
    – Mahi M
    Jul 31, 2018 at 8:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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