1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?php
- /**
- *
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Shipping\Controller\Adminhtml\Order\Shipment;
- use Magento\Backend\App\Action;
- use Magento\Framework\Controller\ResultFactory;
- /**
- * Class Email
- *
- * @package Magento\Shipping\Controller\Adminhtml\Order\Shipment
- */
- class Email extends \Magento\Backend\App\Action
- {
- /**
- * Authorization level of a basic admin session
- *
- * @see _isAllowed()
- */
- const ADMIN_RESOURCE = 'Magento_Sales::shipment';
- /**
- * @var \Magento\Shipping\Controller\Adminhtml\Order\ShipmentLoader
- */
- protected $shipmentLoader;
- /**
- * @param Action\Context $context
- * @param \Magento\Shipping\Controller\Adminhtml\Order\ShipmentLoader $shipmentLoader
- */
- public function __construct(
- Action\Context $context,
- \Magento\Shipping\Controller\Adminhtml\Order\ShipmentLoader $shipmentLoader
- ) {
- $this->shipmentLoader = $shipmentLoader;
- parent::__construct($context);
- }
- /**
- * Send email with shipment data to customer
- *
- * @return \Magento\Backend\Model\View\Result\Redirect
- */
- public function execute()
- {
- try {
- $this->shipmentLoader->setOrderId($this->getRequest()->getParam('order_id'));
- $this->shipmentLoader->setShipmentId($this->getRequest()->getParam('shipment_id'));
- $this->shipmentLoader->setShipment($this->getRequest()->getParam('shipment'));
- $this->shipmentLoader->setTracking($this->getRequest()->getParam('tracking'));
- $shipment = $this->shipmentLoader->load();
- if ($shipment) {
- $this->_objectManager->create(\Magento\Shipping\Model\ShipmentNotifier::class)
- ->notify($shipment);
- $shipment->save();
- $this->messageManager->addSuccess(__('You sent the shipment.'));
- }
- } catch (\Magento\Framework\Exception\LocalizedException $e) {
- $this->messageManager->addError($e->getMessage());
- } catch (\Exception $e) {
- $this->messageManager->addError(__('Cannot send shipment information.'));
- }
- $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
- return $resultRedirect->setPath('*/*/view', ['shipment_id' => $this->getRequest()->getParam('shipment_id')]);
- }
- }
|