1

I am trying to override an abstract class vendor/magento/module-sales/Controller/Adminhtml/Order/Create.php using di.xml but it is not working. I need to do some changes in method protected function _processActionData($action = null).

/vendor/magento/module-sales/Controller/Adminhtml/Order/Create.php

namespace Magento\Sales\Controller\Adminhtml\Order;
   abstract class Create extends \Magento\Backend\App\Action
   {
      protected function _processActionData($action = null)
      { ....
      }

/app/code/CustomAPI/Product/etc/di.xml

    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Sales\Controller\Adminhtml\Order\Create" type="CustomAPI\Product\Controller\Adminhtml\Order\Create" />
</config>

/app/code/CustomAPI/Product/Controller/Adminhtml/Order/Create.php

 namespace CustomAPI\Product\Controller\Adminhtml\Order

     class Create extends Magento\Sales\Controller\Adminhtml\Order\Create
     {
5
  • YOu cannot override Abstract class
    – Amit Bera
    Commented Nov 26, 2019 at 7:31
  • why you don't use event $this->_eventManager->dispatch('adminhtml_sales_order_create_process_data_before', $eventData);
    – Amit Bera
    Commented Nov 26, 2019 at 7:38
  • @AmitBera Could you Please tell me that how can I make changes in this function protected function _processActionData($action = null)
    – SharmaV
    Commented Nov 26, 2019 at 7:39
  • what changes you want inside on _processActionData
    – Amit Bera
    Commented Nov 26, 2019 at 7:40
  • I have added a custom discount check box on admin create order page. Then I need to perform an event on update Item and quantities.
    – SharmaV
    Commented Nov 26, 2019 at 7:49

1 Answer 1

2

I think in this case adminhtml_sales_order_create_process_item_before is best events.

At this event you can get

    $eventData = [
        'order_create_model' => $this->_getOrderCreateModel(),
        'request_model' => $this->getRequest(),
        'session' => $this->_getSession(),
    ];

Request params using $observer->getRequestModel().

and order create model using $observer->getOrderCreateModel().

and Session using $observer->getSession().

When update Item and quantities button hit then a param send to request update_items.

And update_items param only posted when we click on update Item and quantities. That means you put it as a condition on observer.

Observer class:

<?php

namespace Devbera\TestPractics\Obsever;

class UpdateItems implements \Magento\Framework\Event\ObserverInterface
{
    
    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        $request = $observer->getEvent()->getRequestModel();
        $orderCreateModel = $observer->getEvent()->getOrderCreateModel();
        
        if($request->getPost('update_items')){
            // Perform operation on 
        }
    }

}
5
  • Thanks It is working. Now I need to call protected function _processFiles($items) in observer. Could you please tell me how do I use it.
    – SharmaV
    Commented Nov 26, 2019 at 8:29
  • Might you use adminhtml_sales_order_create_process_item_before and it give same parameters. changes request item $this->getRequest()->getPost('item') details .Like $this->getRequest()->setPost('item', $yourparam)
    – Amit Bera
    Commented Nov 26, 2019 at 9:11
  • I need to run same these functions in observer also if ($this->getRequest()->getPost('update_items')) { $items = $this->getRequest()->getPost('item', []); $items = $this->_processFiles($items); $this->_getOrderCreateModel()->updateQuoteItems($items); } but I am unable to call $this->_processFiles($items) and $this->_getOrderCreateModel()->updateQuoteItems($items) in observer
    – SharmaV
    Commented Nov 26, 2019 at 9:42
  • I am facing this error Invalid method Magento\Sales\Model\AdminOrder\Create::_processFiles
    – SharmaV
    Commented Nov 26, 2019 at 9:51
  • this->_processFiles($items) you could not like this way.You can changes the params of items
    – Amit Bera
    Commented Nov 26, 2019 at 13:28

Your Answer

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

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