Email.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\Shipping\Controller\Adminhtml\Order\Shipment;
  8. use Magento\Backend\App\Action;
  9. use Magento\Framework\Controller\ResultFactory;
  10. /**
  11. * Class Email
  12. *
  13. * @package Magento\Shipping\Controller\Adminhtml\Order\Shipment
  14. */
  15. class Email extends \Magento\Backend\App\Action
  16. {
  17. /**
  18. * Authorization level of a basic admin session
  19. *
  20. * @see _isAllowed()
  21. */
  22. const ADMIN_RESOURCE = 'Magento_Sales::shipment';
  23. /**
  24. * @var \Magento\Shipping\Controller\Adminhtml\Order\ShipmentLoader
  25. */
  26. protected $shipmentLoader;
  27. /**
  28. * @param Action\Context $context
  29. * @param \Magento\Shipping\Controller\Adminhtml\Order\ShipmentLoader $shipmentLoader
  30. */
  31. public function __construct(
  32. Action\Context $context,
  33. \Magento\Shipping\Controller\Adminhtml\Order\ShipmentLoader $shipmentLoader
  34. ) {
  35. $this->shipmentLoader = $shipmentLoader;
  36. parent::__construct($context);
  37. }
  38. /**
  39. * Send email with shipment data to customer
  40. *
  41. * @return \Magento\Backend\Model\View\Result\Redirect
  42. */
  43. public function execute()
  44. {
  45. try {
  46. $this->shipmentLoader->setOrderId($this->getRequest()->getParam('order_id'));
  47. $this->shipmentLoader->setShipmentId($this->getRequest()->getParam('shipment_id'));
  48. $this->shipmentLoader->setShipment($this->getRequest()->getParam('shipment'));
  49. $this->shipmentLoader->setTracking($this->getRequest()->getParam('tracking'));
  50. $shipment = $this->shipmentLoader->load();
  51. if ($shipment) {
  52. $this->_objectManager->create(\Magento\Shipping\Model\ShipmentNotifier::class)
  53. ->notify($shipment);
  54. $shipment->save();
  55. $this->messageManager->addSuccess(__('You sent the shipment.'));
  56. }
  57. } catch (\Magento\Framework\Exception\LocalizedException $e) {
  58. $this->messageManager->addError($e->getMessage());
  59. } catch (\Exception $e) {
  60. $this->messageManager->addError(__('Cannot send shipment information.'));
  61. }
  62. $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
  63. return $resultRedirect->setPath('*/*/view', ['shipment_id' => $this->getRequest()->getParam('shipment_id')]);
  64. }
  65. }