Esempio n. 1
0
    /**
     * Run test execute method
     */
    public function testExecute()
    {
        $orderId = 1;
        $shipmentId = 1;
        $shipment = [];
        $tracking = [];
        $incrementId = '10000001';
        $comeFrom = true;

        $this->loadShipment($orderId, $shipmentId, $shipment, $tracking, $comeFrom, $this->shipmentMock);
        $this->shipmentMock->expects($this->once())->method('getIncrementId')->willReturn($incrementId);
        $this->resultPageFactoryMock->expects($this->once())
            ->method('create')
            ->willReturn($this->resultPageMock);

        $layoutMock = $this->getMock('Magento\Framework\View\Layout', ['getBlock', '__wakeup'], [], '', false);
        $this->resultPageMock->expects($this->once())
            ->method('getLayout')
            ->willReturn($layoutMock);
        $layoutMock->expects($this->once())
            ->method('getBlock')
            ->with('sales_shipment_view')
            ->willReturn($this->blockMock);
        $this->blockMock->expects($this->once())
            ->method('updateBackButtonUrl')
            ->with($comeFrom)
            ->willReturnSelf();

        $this->resultPageMock->expects($this->once())
            ->method('setActiveMenu')
            ->with('Magento_Sales::sales_shipment')
            ->willReturnSelf();
        $this->resultPageMock->expects($this->atLeastOnce())
            ->method('getConfig')
            ->willReturn($this->pageConfigMock);
        $this->pageConfigMock->expects($this->atLeastOnce())
            ->method('getTitle')
            ->willReturn($this->pageTitleMock);
        $this->pageTitleMock->expects($this->exactly(2))
            ->method('prepend')
            ->withConsecutive(
                ['Shipments'],
                ["#" . $incrementId]
            )
            ->willReturnSelf();

        $this->assertEquals($this->resultPageMock, $this->controller->executeInternal());
    }
Esempio n. 2
0
 private function processExistShipment(\Magento\Shipping\Block\Adminhtml\View $block)
 {
     $shipmentId = $block->getRequest()->getParam('shipment_id');
     if (empty($shipmentId)) {
         return;
     }
     /** @var \Magento\Sales\Model\Order\Shipment $shipment */
     $shipment = $this->shipmentRepository->get((int) $shipmentId);
     try {
         /** @var \Ess\M2ePro\Model\Order $order */
         $order = $this->amazonFactory->getObjectLoaded('Order', (int) $shipment->getOrderId(), 'magento_order_id');
     } catch (\Exception $exception) {
         return;
     }
     if (is_null($order) || !$order->getId()) {
         return;
     }
     if (!$order->isMagentoShipmentCreatedByOrder($shipment)) {
         return;
     }
     /** @var \Ess\M2ePro\Model\Amazon\Order $amazonOrder */
     $amazonOrder = $order->getChildObject();
     if (!$amazonOrder->isMerchantFulfillmentApplied() || !$amazonOrder->getData('merchant_fulfillment_label')) {
         return;
     }
     return;
     //TODO unsupported feature
     //        $getLabelUrl = $block->getUrl(
     //            'M2ePro/common_amazon_order_merchantFulfillment/getLabel',
     //            array('order_id' => $order->getId())
     //        );
     //
     //        $block->updateButton('print', 'onclick', 'window.open(\''.$getLabelUrl.'\')');
 }
 /**
  * @param \Magento\Shipping\Block\Adminhtml\View $subject
  */
 public function beforeGetBackUrl(\Magento\Shipping\Block\Adminhtml\View $subject)
 {
     if ($subject->getRequest()->getFullActionName() == 'adminhtml_order_shipment_view' && $this->_shipmentHelper->isMercadoEnviosMethod($subject->getShipment()->getOrder()->getShippingMethod())) {
         $subject->addButton('custom_button', ['label' => 'Print shipping label', 'onclick' => 'window.open(\' ' . $this->_shipmentHelper->getTrackingPrintUrl($subject->getRequest()->getParam('shipment_id')) . '\')', 'class' => 'go']);
     }
 }