當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ShipmentLoader::load方法代碼示例

本文整理匯總了PHP中Magento\Shipping\Controller\Adminhtml\Order\ShipmentLoader::load方法的典型用法代碼示例。如果您正苦於以下問題:PHP ShipmentLoader::load方法的具體用法?PHP ShipmentLoader::load怎麽用?PHP ShipmentLoader::load使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Magento\Shipping\Controller\Adminhtml\Order\ShipmentLoader的用法示例。


在下文中一共展示了ShipmentLoader::load方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: executeInternal

    /**
     * Create pdf document with information about packages
     *
     * @return ResponseInterface|void
     */
    public function executeInternal()
    {
        $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) {
            /** @var \Zend_Pdf $pdf */
            $pdf = $this->_objectManager->create('Magento\Shipping\Model\Order\Pdf\Packaging')->getPdf($shipment);
            return $this->_fileFactory->create(
                'packingslip' . $this->_objectManager->get(
                    'Magento\Framework\Stdlib\DateTime\DateTime'
                )->date(
                    'Y-m-d_H-i-s'
                ) . '.pdf',
                $pdf->render(),
                DirectoryList::VAR_DIR,
                'application/pdf'
            );
        } else {
            $this->_forward('noroute');
        }
    }
開發者ID:nblair,項目名稱:magescotch,代碼行數:30,代碼來源:PrintPackage.php

示例2: execute

 /**
  * Add comment to shipment history
  *
  * @return void
  */
 public function execute()
 {
     try {
         $this->getRequest()->setParam('shipment_id', $this->getRequest()->getParam('id'));
         $data = $this->getRequest()->getPost('comment');
         if (empty($data['comment'])) {
             throw new \Magento\Framework\Model\Exception(__("The comment text field cannot be empty."));
         }
         $this->_title->add(__('Shipments'));
         $shipment = $this->shipmentLoader->load($this->_request);
         $shipment->addComment($data['comment'], isset($data['is_customer_notified']), isset($data['is_visible_on_front']));
         $shipment->sendUpdateEmail(!empty($data['is_customer_notified']), $data['comment']);
         $shipment->save();
         $this->_view->loadLayout(false);
         $response = $this->_view->getLayout()->getBlock('shipment_comments')->toHtml();
     } catch (\Magento\Framework\Model\Exception $e) {
         $response = array('error' => true, 'message' => $e->getMessage());
     } catch (\Exception $e) {
         $response = array('error' => true, 'message' => __('Cannot add new comment.'));
     }
     if (is_array($response)) {
         $response = $this->_objectManager->get('Magento\\Core\\Helper\\Data')->jsonEncode($response);
         $this->getResponse()->representJson($response);
     } else {
         $this->getResponse()->setBody($response);
     }
 }
開發者ID:Atlis,項目名稱:docker-magento2,代碼行數:32,代碼來源:AddComment.php

示例3: execute

 /**
  * Print label for one specific shipment
  *
  * @return ResponseInterface|void
  */
 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();
         $labelContent = $shipment->getShippingLabel();
         if ($labelContent) {
             $pdfContent = null;
             if (stripos($labelContent, '%PDF-') !== false) {
                 $pdfContent = $labelContent;
             } else {
                 $pdf = new \Zend_Pdf();
                 $page = $this->labelGenerator->createPdfPageFromImageString($labelContent);
                 if (!$page) {
                     $this->messageManager->addError(__('We don\'t recognize or support the file extension in this shipment: %1.', $shipment->getIncrementId()));
                 }
                 $pdf->pages[] = $page;
                 $pdfContent = $pdf->render();
             }
             return $this->_fileFactory->create('ShippingLabel(' . $shipment->getIncrementId() . ').pdf', $pdfContent, DirectoryList::VAR_DIR, 'application/pdf');
         }
     } catch (\Magento\Framework\Exception\LocalizedException $e) {
         $this->messageManager->addError($e->getMessage());
     } catch (\Exception $e) {
         $this->_objectManager->get('Psr\\Log\\LoggerInterface')->critical($e);
         $this->messageManager->addError(__('An error occurred while creating shipping label.'));
     }
     $this->_redirect('adminhtml/order_shipment/view', ['shipment_id' => $this->getRequest()->getParam('shipment_id')]);
 }
開發者ID:kidaa30,項目名稱:magento2-platformsh,代碼行數:37,代碼來源:PrintLabel.php

示例4: execute

 /**
  * Add new tracking number action
  *
  * @return void
  * @throws \Magento\Framework\Model\Exception
  */
 public function execute()
 {
     try {
         $carrier = $this->getRequest()->getPost('carrier');
         $number = $this->getRequest()->getPost('number');
         $title = $this->getRequest()->getPost('title');
         if (empty($carrier)) {
             throw new \Magento\Framework\Model\Exception(__('Please specify a carrier.'));
         }
         if (empty($number)) {
             throw new \Magento\Framework\Model\Exception(__('Please enter a tracking number.'));
         }
         $this->_title->add(__('Shipments'));
         $shipment = $this->shipmentLoader->load($this->_request);
         if ($shipment) {
             $track = $this->_objectManager->create('Magento\\Sales\\Model\\Order\\Shipment\\Track')->setNumber($number)->setCarrierCode($carrier)->setTitle($title);
             $shipment->addTrack($track)->save();
             $this->_view->loadLayout();
             $response = $this->_view->getLayout()->getBlock('shipment_tracking')->toHtml();
         } else {
             $response = array('error' => true, 'message' => __('Cannot initialize shipment for adding tracking number.'));
         }
     } catch (\Magento\Framework\Model\Exception $e) {
         $response = array('error' => true, 'message' => $e->getMessage());
     } catch (\Exception $e) {
         $response = array('error' => true, 'message' => __('Cannot add tracking number.'));
     }
     if (is_array($response)) {
         $response = $this->_objectManager->get('Magento\\Core\\Helper\\Data')->jsonEncode($response);
         $this->getResponse()->representJson($response);
     } else {
         $this->getResponse()->setBody($response);
     }
 }
開發者ID:Atlis,項目名稱:docker-magento2,代碼行數:40,代碼來源:AddTrack.php

示例5: execute

 /**
  * Add comment to shipment history
  *
  * @return void
  */
 public function execute()
 {
     try {
         $this->getRequest()->setParam('shipment_id', $this->getRequest()->getParam('id'));
         $data = $this->getRequest()->getPost('comment');
         if (empty($data['comment'])) {
             throw new \Magento\Framework\Exception\LocalizedException(__("The comment text field cannot be empty."));
         }
         $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();
         $shipment->addComment($data['comment'], isset($data['is_customer_notified']), isset($data['is_visible_on_front']));
         $this->shipmentCommentSender->send($shipment, !empty($data['is_customer_notified']), $data['comment']);
         $shipment->save();
         $resultLayout = $this->resultLayoutFactory->create();
         $resultLayout->addDefaultHandle();
         $response = $resultLayout->getLayout()->getBlock('shipment_comments')->toHtml();
     } catch (\Magento\Framework\Exception\LocalizedException $e) {
         $response = ['error' => true, 'message' => $e->getMessage()];
     } catch (\Exception $e) {
         $response = ['error' => true, 'message' => __('Cannot add new comment.')];
     }
     if (is_array($response)) {
         $response = $this->_objectManager->get('Magento\\Framework\\Json\\Helper\\Data')->jsonEncode($response);
         $this->getResponse()->representJson($response);
     } else {
         $this->getResponse()->setBody($response);
     }
 }
開發者ID:opexsw,項目名稱:magento2,代碼行數:36,代碼來源:AddComment.php

示例6: execute

 /**
  * Remove tracking number from shipment
  *
  * @return void
  */
 public function execute()
 {
     $trackId = $this->getRequest()->getParam('track_id');
     $track = $this->_objectManager->create('Magento\\Sales\\Model\\Order\\Shipment\\Track')->load($trackId);
     if ($track->getId()) {
         try {
             $this->_title->add(__('Shipments'));
             $shipment = $this->shipmentLoader->load($this->_request);
             if ($shipment) {
                 $track->delete();
                 $this->_view->loadLayout();
                 $response = $this->_view->getLayout()->getBlock('shipment_tracking')->toHtml();
             } else {
                 $response = array('error' => true, 'message' => __('Cannot initialize shipment for delete tracking number.'));
             }
         } catch (\Exception $e) {
             $response = array('error' => true, 'message' => __('Cannot delete tracking number.'));
         }
     } else {
         $response = array('error' => true, 'message' => __('Cannot load track with retrieving identifier.'));
     }
     if (is_array($response)) {
         $response = $this->_objectManager->get('Magento\\Core\\Helper\\Data')->jsonEncode($response);
         $this->getResponse()->representJson($response);
     } else {
         $this->getResponse()->setBody($response);
     }
 }
開發者ID:Atlis,項目名稱:docker-magento2,代碼行數:33,代碼來源:RemoveTrack.php

示例7: execute

 /**
  * Remove tracking number from shipment
  *
  * @return void
  */
 public function execute()
 {
     $trackId = $this->getRequest()->getParam('track_id');
     /** @var \Magento\Sales\Model\Order\Shipment\Track $track */
     $track = $this->_objectManager->create('Magento\\Sales\\Model\\Order\\Shipment\\Track')->load($trackId);
     if ($track->getId()) {
         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) {
                 $track->delete();
                 $this->_view->loadLayout();
                 $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Shipments'));
                 $response = $this->_view->getLayout()->getBlock('shipment_tracking')->toHtml();
             } else {
                 $response = ['error' => true, 'message' => __('We can\'t initialize shipment for delete tracking number.')];
             }
         } catch (\Exception $e) {
             $response = ['error' => true, 'message' => __('We can\'t delete tracking number.')];
         }
     } else {
         $response = ['error' => true, 'message' => __('We can\'t load track with retrieving identifier right now.')];
     }
     if (is_array($response)) {
         $response = $this->_objectManager->get('Magento\\Framework\\Json\\Helper\\Data')->jsonEncode($response);
         $this->getResponse()->representJson($response);
     } else {
         $this->getResponse()->setBody($response);
     }
 }
開發者ID:pradeep-wagento,項目名稱:magento2,代碼行數:38,代碼來源:RemoveTrack.php

示例8: execute

 /**
  * Save shipment
  * We can save only new shipment. Existing shipments are not editable
  *
  * @return void
  */
 public function execute()
 {
     $data = $this->getRequest()->getPost('shipment');
     if (!empty($data['comment_text'])) {
         $this->_objectManager->get('Magento\\Backend\\Model\\Session')->setCommentText($data['comment_text']);
     }
     try {
         $shipment = $this->shipmentLoader->load($this->_request);
         if (!$shipment) {
             $this->_forward('noroute');
             return;
         }
         $shipment->register();
         $comment = '';
         if (!empty($data['comment_text'])) {
             $shipment->addComment($data['comment_text'], isset($data['comment_customer_notify']), isset($data['is_visible_on_front']));
             if (isset($data['comment_customer_notify'])) {
                 $comment = $data['comment_text'];
             }
         }
         if (!empty($data['send_email'])) {
             $shipment->setEmailSent(true);
         }
         $shipment->getOrder()->setCustomerNoteNotify(!empty($data['send_email']));
         $responseAjax = new \Magento\Framework\Object();
         $isNeedCreateLabel = isset($data['create_shipping_label']) && $data['create_shipping_label'];
         if ($isNeedCreateLabel && $this->labelGenerator->create($shipment, $this->_request)) {
             $responseAjax->setOk(true);
         }
         $this->_saveShipment($shipment);
         $shipment->sendEmail(!empty($data['send_email']), $comment);
         $shipmentCreatedMessage = __('The shipment has been created.');
         $labelCreatedMessage = __('You created the shipping label.');
         $this->messageManager->addSuccess($isNeedCreateLabel ? $shipmentCreatedMessage . ' ' . $labelCreatedMessage : $shipmentCreatedMessage);
         $this->_objectManager->get('Magento\\Backend\\Model\\Session')->getCommentText(true);
     } catch (\Magento\Framework\Model\Exception $e) {
         if ($isNeedCreateLabel) {
             $responseAjax->setError(true);
             $responseAjax->setMessage($e->getMessage());
         } else {
             $this->messageManager->addError($e->getMessage());
             $this->_redirect('*/*/new', array('order_id' => $this->getRequest()->getParam('order_id')));
         }
     } catch (\Exception $e) {
         $this->_objectManager->get('Magento\\Framework\\Logger')->logException($e);
         if ($isNeedCreateLabel) {
             $responseAjax->setError(true);
             $responseAjax->setMessage(__('An error occurred while creating shipping label.'));
         } else {
             $this->messageManager->addError(__('Cannot save shipment.'));
             $this->_redirect('*/*/new', array('order_id' => $this->getRequest()->getParam('order_id')));
         }
     }
     if ($isNeedCreateLabel) {
         $this->getResponse()->representJson($responseAjax->toJson());
     } else {
         $this->_redirect('sales/order/view', array('order_id' => $shipment->getOrderId()));
     }
 }
開發者ID:Atlis,項目名稱:docker-magento2,代碼行數:65,代碼來源:Save.php

示例9: execute

 /**
  * Return grid with shipping items for Ajax request
  *
  * @return ResponseInterface
  */
 public function execute()
 {
     $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'));
     $this->shipmentLoader->load();
     return $this->getResponse()->setBody($this->_view->getLayout()->createBlock('Magento\\Shipping\\Block\\Adminhtml\\Order\\Packaging\\Grid')->setIndex($this->getRequest()->getParam('index'))->toHtml());
 }
開發者ID:kidaa30,項目名稱:magento2-platformsh,代碼行數:14,代碼來源:GetShippingItemsGrid.php

示例10: execute

 /**
  * Create pdf document with information about packages
  *
  * @return ResponseInterface|void
  */
 public function execute()
 {
     $shipment = $this->shipmentLoader->load($this->_request);
     if ($shipment) {
         $pdf = $this->_objectManager->create('Magento\\Shipping\\Model\\Order\\Pdf\\Packaging')->getPdf($shipment);
         return $this->_fileFactory->create('packingslip' . $this->_objectManager->get('Magento\\Framework\\Stdlib\\DateTime\\DateTime')->date('Y-m-d_H-i-s') . '.pdf', $pdf->render(), \Magento\Framework\App\Filesystem::VAR_DIR, 'application/pdf');
     } else {
         $this->_forward('noroute');
     }
 }
開發者ID:Atlis,項目名稱:docker-magento2,代碼行數:15,代碼來源:PrintPackage.php

示例11: getModel

 /**
  * @param Shipment $dataObject
  * @return \Magento\Sales\Model\Order\Shipment
  * @throws \Exception
  */
 public function getModel(Shipment $dataObject)
 {
     $this->shipmentLoader->setOrderId($dataObject->getOrderId());
     $this->shipmentLoader->setShipmentId($dataObject->getEntityId());
     $items = [];
     foreach ($dataObject->getItems() as $item) {
         $items[$item->getOrderItemId()] = $item->getQty();
     }
     $shipmentItems = ['items' => $items];
     $this->shipmentLoader->setShipment($shipmentItems);
     $this->shipmentLoader->setTracking($dataObject->getTracks());
     return $this->shipmentLoader->load();
 }
開發者ID:aiesh,項目名稱:magento2,代碼行數:18,代碼來源:ShipmentConverter.php

示例12: executeInternal

    /**
     * Add new tracking number action
     *
     * @return void
     * @throws \Magento\Framework\Exception\LocalizedException
     */
    public function executeInternal()
    {
        try {
            $carrier = $this->getRequest()->getPost('carrier');
            $number = $this->getRequest()->getPost('number');
            $title = $this->getRequest()->getPost('title');
            if (empty($carrier)) {
                throw new \Magento\Framework\Exception\LocalizedException(__('Please specify a carrier.'));
            }
            if (empty($number)) {
                throw new \Magento\Framework\Exception\LocalizedException(__('Please enter a tracking number.'));
            }
            $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) {
                $track = $this->_objectManager->create(
                    'Magento\Sales\Model\Order\Shipment\Track'
                )->setNumber(
                    $number
                )->setCarrierCode(
                    $carrier
                )->setTitle(
                    $title
                );
                $shipment->addTrack($track)->save();

                $this->_view->loadLayout();
                $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Shipments'));
                $response = $this->_view->getLayout()->getBlock('shipment_tracking')->toHtml();
            } else {
                $response = [
                    'error' => true,
                    'message' => __('We can\'t initialize shipment for adding tracking number.'),
                ];
            }
        } catch (\Magento\Framework\Exception\LocalizedException $e) {
            $response = ['error' => true, 'message' => $e->getMessage()];
        } catch (\Exception $e) {
            $response = ['error' => true, 'message' => __('Cannot add tracking number.')];
        }
        if (is_array($response)) {
            $response = $this->_objectManager->get('Magento\Framework\Json\Helper\Data')->jsonEncode($response);
            $this->getResponse()->representJson($response);
        } else {
            $this->getResponse()->setBody($response);
        }
    }
開發者ID:nblair,項目名稱:magescotch,代碼行數:56,代碼來源:AddTrack.php

示例13: execute

 /**
  * Send email with shipment data to customer
  *
  * @return \Magento\Backend\Model\View\Result\Redirect
  */
 public function execute()
 {
     $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')->notify($shipment);
         $shipment->save();
         $this->messageManager->addSuccess(__('You sent the shipment.'));
     }
     return $this->getDefaultResult();
 }
開發者ID:opexsw,項目名稱:magento2,代碼行數:19,代碼來源:Email.php

示例14: execute

 /**
  * Shipment information page
  *
  * @return void
  */
 public function execute()
 {
     $this->_title->add(__('Shipments'));
     $shipment = $this->shipmentLoader->load($this->_request);
     if ($shipment) {
         $this->_title->add("#" . $shipment->getIncrementId());
         $this->_view->loadLayout();
         $this->_view->getLayout()->getBlock('sales_shipment_view')->updateBackButtonUrl($this->getRequest()->getParam('come_from'));
         $this->_setActiveMenu('Magento_Sales::sales_order');
         $this->_view->renderLayout();
     } else {
         $this->_forward('noroute');
     }
 }
開發者ID:Atlis,項目名稱:docker-magento2,代碼行數:19,代碼來源:View.php

示例15: testLoadOrderId

 public function testLoadOrderId()
 {
     $this->loader->unsetData('shipment_id');
     $orderMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->setMethods(['getForcedShipmentWithInvoice', 'getId', 'canShip'])->getMock();
     $this->orderRepository->expects($this->once())->method('get')->will($this->returnValue($orderMock));
     $orderMock->expects($this->once())->method('getId')->will($this->returnValue($this->loader->getOrderId()));
     $orderMock->expects($this->any())->method('getForcedShipmentWithInvoice')->will($this->returnValue(false));
     $orderMock->expects($this->once())->method('canShip')->will($this->returnValue(true));
     $shipmentModelMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Shipment')->disableOriginalConstructor()->setMethods([])->getMock();
     $this->shipmentFactory->expects($this->once())->method('create')->with($orderMock, $this->loader->getShipment()['items'])->willReturn($shipmentModelMock);
     $trackMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Shipment\\Track')->disableOriginalConstructor()->setMethods([])->getMock();
     $this->trackFactoryMock->expects($this->any())->method('create')->will($this->returnValue($trackMock));
     $trackMock->expects($this->any())->method('addData')->will($this->returnValueMap([[$this->loader->getTracking()[0], $trackMock], [$this->loader->getTracking()[1], $trackMock]]));
     $shipmentModelMock->expects($this->any())->method('addTrack')->with($this->equalTo($trackMock))->will($this->returnSelf());
     $this->registryMock->expects($this->once())->method('register')->with('current_shipment', $shipmentModelMock);
     $this->assertEquals($shipmentModelMock, $this->loader->load());
 }
開發者ID:tingyeeh,項目名稱:magento2,代碼行數:17,代碼來源:ShipmentLoaderTest.php


注:本文中的Magento\Shipping\Controller\Adminhtml\Order\ShipmentLoader::load方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。