0

After upgrading magento I found this critical error. Please guide me to solve this error.

Compatibility tool error : Call method 'Magento\Sales\Api\Data\OrderInterface::save' that does not exist on version '2.4.5'

I have my custom module file like, I have extended class and trying to save custom attribute value.

namespace Softweb\CustomCheckout\Controller\Adminhtml\Order;

use Magento\Framework\App\Action\HttpPostActionInterface;

/**
 * Class SaveSapOrderId
 */
class SaveSapInfo extends \Magento\Sales\Controller\Adminhtml\Order implements HttpPostActionInterface
{
    public function execute()
    {
        $order = $this->_initOrder();
        if ($order) {
            try {
                $data = $this->getRequest()->getPost('sap_order_id');
                $order->setData('sap_order_id', $data);
                $order->save();
                $this->messageManager->addSuccessMessage(__('Your SAP information saved successfully'));
            } catch (\Magento\Framework\Exception\LocalizedException $e) {
                $this->messageManager->addErrorMessage($e->getMessage());
            } catch (\Exception $e) {
                $this->messageManager->addErrorMessage(__('We can\'t save SAP Order ID.'));
                $this->logger->critical($e);
            }
            return $this->resultRedirectFactory->create()->setPath(
                'sales/order/view',
                [
                    'order_id' => $order->getEntityId()
                ]
            );
        }
        return $this->resultRedirectFactory->create()->setPath('sales/*/');
    }
}
1
  • Please Elaborate more, how you are using the Interface..? Dec 29, 2022 at 6:32

1 Answer 1

0

Try this code to save order

use Magento\Sales\Api\OrderManagementInterface;
use Magento\Sales\Api\Data\OrderInterface;
class SaveSapInfo extends \Magento\Sales\Controller\Adminhtml\Order 
implements HttpPostActionInterface
 {   
 private $orderManagement;

  public function __construct(
     OrderManagementInterface $orderManagement
   ){
     $this->orderManagement = $orderManagement;
    }
public function execute()
{
    $order = $this->_initOrder();
    if ($order) {
        try {
            $data = $this->getRequest()->getPost('sap_order_id');
            $order->setData('sap_order_id', $data);
            $this->orderManagement->save($order->getEntityId());
            $this->messageManager->addSuccessMessage(__('Your SAP information saved successfully'));
        } catch (\Magento\Framework\Exception\LocalizedException $e) {
            $this->messageManager->addErrorMessage($e->getMessage());
        } catch (\Exception $e) {
            $this->messageManager->addErrorMessage(__('We can\'t save SAP Order ID.'));
            $this->logger->critical($e);
        }
        return $this->resultRedirectFactory->create()->setPath(
            'sales/order/view',
            [
                'order_id' => $order->getEntityId()
            ]
        );
    }
    return $this->resultRedirectFactory->create()->setPath('sales/*/');
   }
}

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.