Вопрос

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
     {
Это было полезно?

Решение

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 
        }
    }

}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с magento.stackexchange
scroll top