I create custom status action class to change specific order to my custom status, I created "Packing" class, that change order status to 'packing'. it's working fine on Magento 2.1.5, but if I using it on Magento 2.1.2( I have some legacy product.) it always return 500 internal error.
This is Packing class which I overrode.
class Packing extends \Magento\Sales\Controller\Adminhtml\Order {
const ADMIN_RESOURCE = 'Magento_OrderStatus::packing';
/**
* Packing order
*
* @return \Magento\Backend\Model\View\Result\Redirect
*/
public function execute()
{
$resultRedirect = $this->resultRedirectFactory->create();
$orderId = $this->getRequest()->getParam('order_id');
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$order = $objectManager->create('\Magento\Sales\Model\Order')->load($orderId);
if ($order) {
try {
$order->setStatus('packing');
$order->save();
$this->messageManager->addSuccess(__('You put the order on packing.'));
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$this->messageManager->addError($e->getMessage());
} catch (\Exception $e) {
$this->messageManager->addError(__('You have not put the order on packing.'));
}
$resultRedirect->setPath('sales/order/view', ['order_id' => $order->getId()]);
return $resultRedirect;
}
$resultRedirect->setPath('sales/*/');
return $resultRedirect;
}
}
please tell me if you need more code. Thank you for answering my question.
edited
debugger mode showed me Magento\Sales\Controller\Adminhtml\Order::__construct() must be an instance of Magento\Backend\App\Action\Context
error function resides on Order.php from Sales Module.
/**
* @param Action\Context $context
* @param \Magento\Framework\Registry $coreRegistry
* @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory
* @param \Magento\Framework\Translate\InlineInterface $translateInline
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
* @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
* @param \Magento\Framework\View\Result\LayoutFactory $resultLayoutFactory
* @param \Magento\Framework\Controller\Result\RawFactory $resultRawFactory
* @param OrderManagementInterface $orderManagement
* @param OrderRepositoryInterface $orderRepository
* @param LoggerInterface $logger
*
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
public function __construct(
Action\Context $context,
\Magento\Framework\Registry $coreRegistry,
\Magento\Framework\App\Response\Http\FileFactory $fileFactory,
\Magento\Framework\Translate\InlineInterface $translateInline,
\Magento\Framework\View\Result\PageFactory $resultPageFactory,
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory,
\Magento\Framework\View\Result\LayoutFactory $resultLayoutFactory,
\Magento\Framework\Controller\Result\RawFactory $resultRawFactory,
OrderManagementInterface $orderManagement,
OrderRepositoryInterface $orderRepository,
LoggerInterface $logger
) {
$this->_coreRegistry = $coreRegistry;
$this->_fileFactory = $fileFactory;
$this->_translateInline = $translateInline;
$this->resultPageFactory = $resultPageFactory;
$this->resultJsonFactory = $resultJsonFactory;
$this->resultLayoutFactory = $resultLayoutFactory;
$this->resultRawFactory = $resultRawFactory;
$this->orderManagement = $orderManagement;
$this->orderRepository = $orderRepository;
$this->logger = $logger;
parent::__construct($context);
}