123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- /**
- *
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Shipping\Controller\Adminhtml\Order\Shipment;
- use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface;
- use Magento\Backend\App\Action;
- use Magento\Framework\App\ObjectManager;
- class NewAction extends \Magento\Backend\App\Action implements HttpGetActionInterface
- {
- /**
- * Authorization level of a basic admin session
- *
- * @see _isAllowed()
- */
- const ADMIN_RESOURCE = 'Magento_Sales::shipment';
- /**
- * @var \Magento\Shipping\Controller\Adminhtml\Order\ShipmentLoader
- */
- protected $shipmentLoader;
- /**
- * @var \Magento\Shipping\Model\ShipmentProviderInterface
- */
- private $shipmentProvider;
- /**
- * @param Action\Context $context
- * @param \Magento\Shipping\Controller\Adminhtml\Order\ShipmentLoader $shipmentLoader
- * @param \Magento\Shipping\Model\ShipmentProviderInterface $shipmentProvider
- */
- public function __construct(
- Action\Context $context,
- \Magento\Shipping\Controller\Adminhtml\Order\ShipmentLoader $shipmentLoader,
- \Magento\Shipping\Model\ShipmentProviderInterface $shipmentProvider = null
- ) {
- $this->shipmentLoader = $shipmentLoader;
- $this->shipmentProvider = $shipmentProvider ?: ObjectManager::getInstance()
- ->get(\Magento\Shipping\Model\ShipmentProviderInterface::class);
- parent::__construct($context);
- }
- /**
- * Shipment create page
- *
- * @return void
- */
- public function execute()
- {
- $this->shipmentLoader->setOrderId($this->getRequest()->getParam('order_id'));
- $this->shipmentLoader->setShipmentId($this->getRequest()->getParam('shipment_id'));
- $this->shipmentLoader->setShipment($this->shipmentProvider->getShipmentData());
- $this->shipmentLoader->setTracking($this->getRequest()->getParam('tracking'));
- $shipment = $this->shipmentLoader->load();
- if ($shipment) {
- $comment = $this->_objectManager->get(\Magento\Backend\Model\Session::class)->getCommentText(true);
- if ($comment) {
- $shipment->setCommentText($comment);
- }
- $this->_view->loadLayout();
- $this->_setActiveMenu('Magento_Sales::sales_order');
- $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Shipments'));
- $this->_view->getPage()->getConfig()->getTitle()->prepend(__('New Shipment'));
- $this->_view->renderLayout();
- } else {
- $this->_redirect('*/order/view', ['order_id' => $this->getRequest()->getParam('order_id')]);
- }
- }
- }
|