NewAction.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface;
  9. use Magento\Backend\App\Action;
  10. use Magento\Framework\App\ObjectManager;
  11. class NewAction extends \Magento\Backend\App\Action implements HttpGetActionInterface
  12. {
  13. /**
  14. * Authorization level of a basic admin session
  15. *
  16. * @see _isAllowed()
  17. */
  18. const ADMIN_RESOURCE = 'Magento_Sales::shipment';
  19. /**
  20. * @var \Magento\Shipping\Controller\Adminhtml\Order\ShipmentLoader
  21. */
  22. protected $shipmentLoader;
  23. /**
  24. * @var \Magento\Shipping\Model\ShipmentProviderInterface
  25. */
  26. private $shipmentProvider;
  27. /**
  28. * @param Action\Context $context
  29. * @param \Magento\Shipping\Controller\Adminhtml\Order\ShipmentLoader $shipmentLoader
  30. * @param \Magento\Shipping\Model\ShipmentProviderInterface $shipmentProvider
  31. */
  32. public function __construct(
  33. Action\Context $context,
  34. \Magento\Shipping\Controller\Adminhtml\Order\ShipmentLoader $shipmentLoader,
  35. \Magento\Shipping\Model\ShipmentProviderInterface $shipmentProvider = null
  36. ) {
  37. $this->shipmentLoader = $shipmentLoader;
  38. $this->shipmentProvider = $shipmentProvider ?: ObjectManager::getInstance()
  39. ->get(\Magento\Shipping\Model\ShipmentProviderInterface::class);
  40. parent::__construct($context);
  41. }
  42. /**
  43. * Shipment create page
  44. *
  45. * @return void
  46. */
  47. public function execute()
  48. {
  49. $this->shipmentLoader->setOrderId($this->getRequest()->getParam('order_id'));
  50. $this->shipmentLoader->setShipmentId($this->getRequest()->getParam('shipment_id'));
  51. $this->shipmentLoader->setShipment($this->shipmentProvider->getShipmentData());
  52. $this->shipmentLoader->setTracking($this->getRequest()->getParam('tracking'));
  53. $shipment = $this->shipmentLoader->load();
  54. if ($shipment) {
  55. $comment = $this->_objectManager->get(\Magento\Backend\Model\Session::class)->getCommentText(true);
  56. if ($comment) {
  57. $shipment->setCommentText($comment);
  58. }
  59. $this->_view->loadLayout();
  60. $this->_setActiveMenu('Magento_Sales::sales_order');
  61. $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Shipments'));
  62. $this->_view->getPage()->getConfig()->getTitle()->prepend(__('New Shipment'));
  63. $this->_view->renderLayout();
  64. } else {
  65. $this->_redirect('*/order/view', ['order_id' => $this->getRequest()->getParam('order_id')]);
  66. }
  67. }
  68. }