Skip to content

Replacing deprecated methods from Magento_Sales module. #17410

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,16 @@ public function execute()
$cart->addOrderItem($item);
} catch (\Magento\Framework\Exception\LocalizedException $e) {
if ($this->_objectManager->get(\Magento\Checkout\Model\Session::class)->getUseNotice(true)) {
$this->messageManager->addNotice($e->getMessage());
$this->messageManager->addNoticeMessage($e->getMessage());
} else {
$this->messageManager->addError($e->getMessage());
$this->messageManager->addErrorMessage($e->getMessage());
}
return $resultRedirect->setPath('*/*/history');
} catch (\Exception $e) {
$this->messageManager->addException($e, __('We can\'t add this item to your shopping cart right now.'));
$this->messageManager->addExceptionMessage(
$e,
__('We can\'t add this item to your shopping cart right now.')
);
return $resultRedirect->setPath('checkout/cart');
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function execute()
$this->_objectManager->create(\Magento\Sales\Api\CreditmemoManagementInterface::class)
->notify($creditmemoId);

$this->messageManager->addSuccess(__('You sent the message.'));
$this->messageManager->addSuccessMessage(__('You sent the message.'));
$resultRedirect = $this->resultRedirectFactory->create();
$resultRedirect->setPath('sales/order_creditmemo/view', ['creditmemo_id' => $creditmemoId]);
return $resultRedirect;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function execute()
\Magento\Sales\Api\InvoiceManagementInterface::class
)->notify($invoice->getEntityId());

$this->messageManager->addSuccess(__('You sent the message.'));
$this->messageManager->addSuccessMessage(__('You sent the message.'));
return $this->resultRedirectFactory->create()->setPath(
'sales/invoice/view',
['order_id' => $invoice->getOrder()->getId(), 'invoice_id' => $invoiceId]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected function getInvoice()
->get($this->getRequest()->getParam('invoice_id'));
$this->registry->register('current_invoice', $invoice);
} catch (\Exception $e) {
$this->messageManager->addError(__('Invoice capturing error'));
$this->messageManager->addErrorMessage(__('Invoice capturing error'));
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/Sales/Controller/Adminhtml/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,11 @@ protected function _initOrder()
try {
$order = $this->orderRepository->get($id);
} catch (NoSuchEntityException $e) {
$this->messageManager->addError(__('This order no longer exists.'));
$this->messageManager->addErrorMessage(__('This order no longer exists.'));
$this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true);
return false;
} catch (InputException $e) {
$this->messageManager->addError(__('This order no longer exists.'));
$this->messageManager->addErrorMessage(__('This order no longer exists.'));
$this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true);
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function execute()
$collection = $this->filter->getCollection($this->collectionFactory->create());
return $this->massAction($collection);
} catch (\Exception $e) {
$this->messageManager->addError($e->getMessage());
$this->messageManager->addErrorMessage($e->getMessage());
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
return $resultRedirect->setPath($this->redirectUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,12 @@ public function execute()
'order_id' => $address->getParentId()
]
);
$this->messageManager->addSuccess(__('You updated the order address.'));
$this->messageManager->addSuccessMessage(__('You updated the order address.'));
return $resultRedirect->setPath('sales/*/view', ['order_id' => $address->getParentId()]);
} catch (LocalizedException $e) {
$this->messageManager->addError($e->getMessage());
$this->messageManager->addErrorMessage($e->getMessage());
} catch (\Exception $e) {
$this->messageManager->addException($e, __('We can\'t update the order address right now.'));
$this->messageManager->addExceptionMessage($e, __('We can\'t update the order address right now.'));
}
return $resultRedirect->setPath('sales/*/address', ['address_id' => $address->getId()]);
} else {
Expand Down
8 changes: 4 additions & 4 deletions app/code/Magento/Sales/Controller/Adminhtml/Order/Cancel.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ public function execute()
{
$resultRedirect = $this->resultRedirectFactory->create();
if (!$this->isValidPostRequest()) {
$this->messageManager->addError(__('You have not canceled the item.'));
$this->messageManager->addErrorMessage(__('You have not canceled the item.'));
return $resultRedirect->setPath('sales/*/');
}
$order = $this->_initOrder();
if ($order) {
try {
$this->orderManagement->cancel($order->getEntityId());
$this->messageManager->addSuccess(__('You canceled the order.'));
$this->messageManager->addSuccessMessage(__('You canceled the order.'));
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$this->messageManager->addError($e->getMessage());
$this->messageManager->addErrorMessage($e->getMessage());
} catch (\Exception $e) {
$this->messageManager->addError(__('You have not canceled the item.'));
$this->messageManager->addErrorMessage(__('You have not canceled the item.'));
$this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
}
return $resultRedirect->setPath('sales/order/view', ['order_id' => $order->getId()]);
Expand Down
6 changes: 3 additions & 3 deletions app/code/Magento/Sales/Controller/Adminhtml/Order/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,22 +317,22 @@ protected function _processActionData($action = null)
}
}
if (!$isApplyDiscount) {
$this->messageManager->addError(
$this->messageManager->addErrorMessage(
__(
'"%1" coupon code was not applied. Do not apply discount is selected for item(s)',
$this->escaper->escapeHtml($couponCode)
)
);
} else {
if ($this->_getQuote()->getCouponCode() !== $couponCode) {
$this->messageManager->addError(
$this->messageManager->addErrorMessage(
__(
'The "%1" coupon code isn\'t valid. Verify the code and try again.',
$this->escaper->escapeHtml($couponCode)
)
);
} else {
$this->messageManager->addSuccess(__('The coupon code has been accepted.'));
$this->messageManager->addSuccessMessage(__('The coupon code has been accepted.'));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ public function execute()
\Magento\Sales\Api\CreditmemoManagementInterface::class
);
$creditmemoManagement->cancel($creditmemoId);
$this->messageManager->addSuccess(__('The credit memo has been canceled.'));
$this->messageManager->addSuccessMessage(__('The credit memo has been canceled.'));
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$this->messageManager->addError($e->getMessage());
$this->messageManager->addErrorMessage($e->getMessage());
} catch (\Exception $e) {
$this->messageManager->addError(__('Credit memo has not been canceled.'));
$this->messageManager->addErrorMessage(__('Credit memo has not been canceled.'));
}
$resultRedirect = $this->resultRedirectFactory->create();
$resultRedirect->setPath('sales/*/view', ['creditmemo_id' => $creditmemoId]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function execute()
$this->creditmemoSender->send($creditmemo);
}

$this->messageManager->addSuccess(__('You created the credit memo.'));
$this->messageManager->addSuccessMessage(__('You created the credit memo.'));
$this->_getSession()->getCommentText(true);
$resultRedirect->setPath('sales/order/view', ['order_id' => $creditmemo->getOrderId()]);
return $resultRedirect;
Expand All @@ -119,11 +119,11 @@ public function execute()
return $resultForward;
}
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$this->messageManager->addError($e->getMessage());
$this->messageManager->addErrorMessage($e->getMessage());
$this->_getSession()->setFormData($data);
} catch (\Exception $e) {
$this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
$this->messageManager->addError(__('We can\'t save the credit memo right now.'));
$this->messageManager->addErrorMessage(__('We can\'t save the credit memo right now.'));
}
$resultRedirect->setPath('sales/*/new', ['_current' => true]);
return $resultRedirect;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ public function execute()
$transactionSave->addObject($creditmemo->getInvoice());
}
$transactionSave->save();
$this->messageManager->addSuccess(__('You voided the credit memo.'));
$this->messageManager->addSuccessMessage(__('You voided the credit memo.'));
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$this->messageManager->addError($e->getMessage());
$this->messageManager->addErrorMessage($e->getMessage());
} catch (\Exception $e) {
$this->messageManager->addError(__('We can\'t void the credit memo.'));
$this->messageManager->addErrorMessage(__('We can\'t void the credit memo.'));
}
$resultRedirect = $this->resultRedirectFactory->create();
$resultRedirect->setPath('sales/*/view', ['creditmemo_id' => $creditmemo->getId()]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,15 @@ protected function _canCreditmemo($order)
* Check order existing
*/
if (!$order->getId()) {
$this->messageManager->addError(__('The order no longer exists.'));
$this->messageManager->addErrorMessage(__('The order no longer exists.'));
return false;
}

/**
* Check creditmemo create availability
*/
if (!$order->canCreditmemo()) {
$this->messageManager->addError(__('We can\'t create credit memo for the order.'));
$this->messageManager->addErrorMessage(__('We can\'t create credit memo for the order.'));
return false;
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ public function execute()
$resultRedirect->setPath('sales/order/');
}
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$this->messageManager->addError($e->getMessage());
$this->messageManager->addErrorMessage($e->getMessage());
$resultRedirect->setPath('sales/order/view', ['order_id' => $orderId]);
} catch (\Exception $e) {
$this->messageManager->addException($e, $e->getMessage());
$this->messageManager->addExceptionMessage($e, $e->getMessage());
$resultRedirect->setPath('sales/order/view', ['order_id' => $orderId]);
}
return $resultRedirect;
Expand Down
6 changes: 3 additions & 3 deletions app/code/Magento/Sales/Controller/Adminhtml/Order/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ public function execute()
if ($order) {
try {
$this->orderManagement->notify($order->getEntityId());
$this->messageManager->addSuccess(__('You sent the order email.'));
$this->messageManager->addSuccessMessage(__('You sent the order email.'));
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$this->messageManager->addError($e->getMessage());
$this->messageManager->addErrorMessage($e->getMessage());
} catch (\Exception $e) {
$this->messageManager->addError(__('We can\'t send the email order right now.'));
$this->messageManager->addErrorMessage(__('We can\'t send the email order right now.'));
$this->logger->critical($e);
}
return $this->resultRedirectFactory->create()->setPath(
Expand Down
8 changes: 4 additions & 4 deletions app/code/Magento/Sales/Controller/Adminhtml/Order/Hold.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ public function execute()
{
$resultRedirect = $this->resultRedirectFactory->create();
if (!$this->isValidPostRequest()) {
$this->messageManager->addError(__('You have not put the order on hold.'));
$this->messageManager->addErrorMessage(__('You have not put the order on hold.'));
return $resultRedirect->setPath('sales/*/');
}
$order = $this->_initOrder();
if ($order) {
try {
$this->orderManagement->hold($order->getEntityId());
$this->messageManager->addSuccess(__('You put the order on hold.'));
$this->messageManager->addSuccessMessage(__('You put the order on hold.'));
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$this->messageManager->addError($e->getMessage());
$this->messageManager->addErrorMessage($e->getMessage());
} catch (\Exception $e) {
$this->messageManager->addError(__('You have not put the order on hold.'));
$this->messageManager->addErrorMessage(__('You have not put the order on hold.'));
}
$resultRedirect->setPath('sales/order/view', ['order_id' => $order->getId()]);
return $resultRedirect;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ public function execute()
)->addObject(
$invoice->getOrder()
)->save();
$this->messageManager->addSuccess(__('You canceled the invoice.'));
$this->messageManager->addSuccessMessage(__('You canceled the invoice.'));
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$this->messageManager->addError($e->getMessage());
$this->messageManager->addErrorMessage($e->getMessage());
} catch (\Exception $e) {
$this->messageManager->addError(__('Invoice canceling error'));
$this->messageManager->addErrorMessage(__('Invoice canceling error'));
}
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultRedirectFactory->create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ public function execute()
)->addObject(
$invoice->getOrder()
)->save();
$this->messageManager->addSuccess(__('The invoice has been captured.'));
$this->messageManager->addSuccessMessage(__('The invoice has been captured.'));
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$this->messageManager->addError($e->getMessage());
$this->messageManager->addErrorMessage($e->getMessage());
} catch (\Exception $e) {
$this->messageManager->addError(__('Invoice capturing error'));
$this->messageManager->addErrorMessage(__('Invoice capturing error'));
}
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultRedirectFactory->create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ public function execute()
$resultPage->getConfig()->getTitle()->prepend(__('New Invoice'));
return $resultPage;
} catch (\Magento\Framework\Exception\LocalizedException $exception) {
$this->messageManager->addError($exception->getMessage());
$this->messageManager->addErrorMessage($exception->getMessage());
return $this->_redirectToOrder($orderId);
} catch (\Exception $exception) {
$this->messageManager->addException($exception, 'Cannot create an invoice.');
$this->messageManager->addExceptionMessage($exception, 'Cannot create an invoice.');
return $this->_redirectToOrder($orderId);
}
}
Expand Down
17 changes: 10 additions & 7 deletions app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ public function execute()
$formKeyIsValid = $this->_formKeyValidator->validate($this->getRequest());
$isPost = $this->getRequest()->isPost();
if (!$formKeyIsValid || !$isPost) {
$this->messageManager->addError(__("The invoice can't be saved at this time. Please try again later."));
$this->messageManager
->addErrorMessage(__("The invoice can't be saved at this time. Please try again later."));
return $resultRedirect->setPath('sales/order/index');
}

Expand Down Expand Up @@ -193,9 +194,9 @@ public function execute()
$transactionSave->save();

if (!empty($data['do_shipment'])) {
$this->messageManager->addSuccess(__('You created the invoice and shipment.'));
$this->messageManager->addSuccessMessage(__('You created the invoice and shipment.'));
} else {
$this->messageManager->addSuccess(__('The invoice has been created.'));
$this->messageManager->addSuccessMessage(__('The invoice has been created.'));
}

// send invoice/shipment emails
Expand All @@ -205,7 +206,7 @@ public function execute()
}
} catch (\Exception $e) {
$this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
$this->messageManager->addError(__('We can\'t send the invoice email right now.'));
$this->messageManager->addErrorMessage(__('We can\'t send the invoice email right now.'));
}
if ($shipment) {
try {
Expand All @@ -214,15 +215,17 @@ public function execute()
}
} catch (\Exception $e) {
$this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
$this->messageManager->addError(__('We can\'t send the shipment right now.'));
$this->messageManager->addErrorMessage(__('We can\'t send the shipment right now.'));
}
}
$this->_objectManager->get(\Magento\Backend\Model\Session::class)->getCommentText(true);
return $resultRedirect->setPath('sales/order/view', ['order_id' => $orderId]);
} catch (LocalizedException $e) {
$this->messageManager->addError($e->getMessage());
$this->messageManager->addErrorMessage($e->getMessage());
} catch (\Exception $e) {
$this->messageManager->addError(__("The invoice can't be saved at this time. Please try again later."));
$this->messageManager->addErrorMessage(
__("The invoice can't be saved at this time. Please try again later.")
);
$this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
}
return $resultRedirect->setPath('sales/*/new', ['order_id' => $orderId]);
Expand Down
Loading