コード例 #1
0
ファイル: AddComment.php プロジェクト: Atlis/docker-magento2
 /**
  * Add comment to creditmemo history
  *
  * @return void
  */
 public function execute()
 {
     try {
         $this->getRequest()->setParam('creditmemo_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(__('Credit Memos'));
         $creditmemo = $this->creditmemoLoader->load($this->_request);
         $comment = $creditmemo->addComment($data['comment'], isset($data['is_customer_notified']), isset($data['is_visible_on_front']));
         $comment->save();
         $creditmemo->sendUpdateEmail(!empty($data['is_customer_notified']), $data['comment']);
         $this->_view->loadLayout();
         $response = $this->_view->getLayout()->getBlock('creditmemo_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);
     }
 }
コード例 #2
0
ファイル: Save.php プロジェクト: Atlis/docker-magento2
 /**
  * Save creditmemo
  * We can save only new creditmemo. Existing creditmemos are not editable
  *
  * @return void
  */
 public function execute()
 {
     $data = $this->getRequest()->getPost('creditmemo');
     if (!empty($data['comment_text'])) {
         $this->_getSession()->setCommentText($data['comment_text']);
     }
     try {
         $creditmemo = $this->creditmemoLoader->load($this->_request);
         if ($creditmemo) {
             if ($creditmemo->getGrandTotal() <= 0 && !$creditmemo->getAllowZeroGrandTotal()) {
                 throw new \Magento\Framework\Model\Exception(__('Credit memo\'s total must be positive.'));
             }
             $comment = '';
             if (!empty($data['comment_text'])) {
                 $creditmemo->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 (isset($data['do_refund'])) {
                 $creditmemo->setRefundRequested(true);
             }
             if (isset($data['do_offline'])) {
                 //do not allow online refund for Refund to Store Credit
                 if (!$data['do_offline'] && !empty($data['refund_customerbalance_return_enable'])) {
                     throw new \Magento\Framework\Model\Exception(__('Cannot create online refund for Refund to Store Credit.'));
                 }
                 $creditmemo->setOfflineRequested((bool) (int) $data['do_offline']);
             }
             $creditmemo->register();
             if (!empty($data['send_email'])) {
                 $creditmemo->setEmailSent(true);
             }
             $creditmemo->getOrder()->setCustomerNoteNotify(!empty($data['send_email']));
             $transactionSave = $this->_objectManager->create('Magento\\Framework\\DB\\Transaction')->addObject($creditmemo)->addObject($creditmemo->getOrder());
             if ($creditmemo->getInvoice()) {
                 $transactionSave->addObject($creditmemo->getInvoice());
             }
             $transactionSave->save();
             $creditmemo->sendEmail(!empty($data['send_email']), $comment);
             $this->messageManager->addSuccess(__('You created the credit memo.'));
             $this->_getSession()->getCommentText(true);
             $this->_redirect('sales/order/view', array('order_id' => $creditmemo->getOrderId()));
             return;
         } else {
             $this->_forward('noroute');
             return;
         }
     } catch (\Magento\Framework\Model\Exception $e) {
         $this->messageManager->addError($e->getMessage());
         $this->_getSession()->setFormData($data);
     } catch (\Exception $e) {
         $this->_objectManager->get('Magento\\Framework\\Logger')->logException($e);
         $this->messageManager->addError(__('Cannot save the credit memo.'));
     }
     $this->_redirect('sales/*/new', array('_current' => true));
 }
コード例 #3
0
 public function testLoadByOrder()
 {
     $qty = 1;
     $data = ['items' => [1 => ['qty' => $qty, 'back_to_stock' => true]]];
     $this->loader->setCreditmemoId(0);
     $this->loader->setOrderId(1);
     $this->loader->setCreditmemo($data);
     $this->loader->setInvoiceId(1);
     $orderMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->setMethods([])->getMock();
     $orderMock->expects($this->once())->method('load')->willReturnSelf();
     $orderMock->expects($this->once())->method('getId')->willReturn(1);
     $orderMock->expects($this->once())->method('canCreditmemo')->willReturn(true);
     $this->orderFactoryMock->expects($this->once())->method('create')->willReturn($orderMock);
     $invoiceMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Invoice')->disableOriginalConstructor()->setMethods([])->getMock();
     $invoiceMock->expects($this->any())->method('load')->willReturnSelf();
     $invoiceMock->expects($this->any())->method('setOrder')->willReturnSelf();
     $invoiceMock->expects($this->any())->method('getId')->willReturn(1);
     $this->invoiceFactoryMock->expects($this->once())->method('create')->willReturn($invoiceMock);
     $serviceOrder = $this->getMockBuilder('Magento\\Sales\\Model\\Service\\Order')->disableOriginalConstructor()->setMethods([])->getMock();
     $creditmemoMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Creditmemo')->disableOriginalConstructor()->setMethods([])->getMock();
     $orderItemMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Item')->disableOriginalConstructor()->setMethods([])->getMock();
     $creditmemoItemMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Creditmemo\\Item')->disableOriginalConstructor()->setMethods([])->getMock();
     $creditmemoItemMock->expects($this->any())->method('getOrderItem')->willReturn($orderItemMock);
     $items = [$creditmemoItemMock, $creditmemoItemMock, $creditmemoItemMock];
     $creditmemoMock->expects($this->any())->method('getAllItems')->willReturn($items);
     $serviceOrder->expects($this->any())->method('prepareInvoiceCreditmemo')->willReturn($creditmemoMock);
     $this->serviceOrderFactoryMock->expects($this->once())->method('create')->willReturn($serviceOrder);
     $this->assertInstanceOf('Magento\\Sales\\Model\\Order\\Creditmemo', $this->loader->load());
 }
コード例 #4
0
ファイル: PrintActionTest.php プロジェクト: nblair/magescotch
    /**
     * @param int|null $creditmemoId
     */
    protected function prepareTestExecute($creditmemoId = null)
    {
        $orderId = 1;
        $creditmemo = 3;
        $invoiceId = 4;

        $this->requestMock->expects($this->any())
            ->method('getParam')
            ->willReturnMap(
                [
                    ['order_id', null, $orderId],
                    ['creditmemo_id', null, $creditmemoId],
                    ['creditmemo', null, $creditmemo],
                    ['invoice_id', null, $invoiceId]
                ]
            );
        $this->creditmemoLoaderMock->expects($this->once())
            ->method('setOrderId')
            ->with($orderId)
            ->willReturnSelf();
        $this->creditmemoLoaderMock->expects($this->once())
            ->method('setCreditmemoId')
            ->with($creditmemoId)
            ->willReturnSelf();
        $this->creditmemoLoaderMock->expects($this->once())
            ->method('setCreditmemo')
            ->with($creditmemo)
            ->willReturnSelf();
        $this->creditmemoLoaderMock->expects($this->once())
            ->method('setInvoiceId')
            ->with($invoiceId)
            ->willReturnSelf();
        $this->creditmemoLoaderMock->expects($this->once())
            ->method('load');
    }
コード例 #5
0
 public function testLoadByOrder()
 {
     $orderId = 1234;
     $invoiceId = 99;
     $qty = 1;
     $data = ['items' => [1 => ['qty' => $qty, 'back_to_stock' => true]]];
     $this->loader->setCreditmemoId(0);
     $this->loader->setOrderId($orderId);
     $this->loader->setCreditmemo($data);
     $this->loader->setInvoiceId($invoiceId);
     $orderMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->setMethods([])->getMock();
     $orderMock->expects($this->once())->method('load')->willReturnSelf();
     $orderMock->expects($this->once())->method('getId')->willReturn($orderId);
     $orderMock->expects($this->once())->method('canCreditmemo')->willReturn(true);
     $this->orderFactoryMock->expects($this->once())->method('create')->willReturn($orderMock);
     $invoiceMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Invoice')->disableOriginalConstructor()->getMock();
     $invoiceMock->expects($this->any())->method('setOrder')->willReturnSelf();
     $invoiceMock->expects($this->any())->method('getId')->willReturn(1);
     $this->invoiceRepositoryMock->expects($this->once())->method('get')->willReturn($invoiceMock);
     $creditmemoMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Creditmemo')->disableOriginalConstructor()->setMethods([])->getMock();
     $orderItemMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Item')->disableOriginalConstructor()->setMethods([])->getMock();
     $creditmemoItemMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Creditmemo\\Item')->disableOriginalConstructor()->setMethods([])->getMock();
     $creditmemoItemMock->expects($this->any())->method('getOrderItem')->willReturn($orderItemMock);
     $items = [$creditmemoItemMock, $creditmemoItemMock, $creditmemoItemMock];
     $creditmemoMock->expects($this->any())->method('getAllItems')->willReturn($items);
     $data['qtys'] = [1 => $qty];
     $this->creditmemoFactoryMock->expects($this->any())->method('createByInvoice')->with($invoiceMock, $data)->willReturn($creditmemoMock);
     $this->assertEquals($creditmemoMock, $this->loader->load());
 }
コード例 #6
0
ファイル: View.php プロジェクト: Atlis/docker-magento2
 /**
  * Creditmemo information page
  *
  * @return void
  */
 public function execute()
 {
     $creditmemo = $this->creditmemoLoader->load($this->_request);
     if ($creditmemo) {
         if ($creditmemo->getInvoice()) {
             $this->_title->add(__("View Memo for #%1", $creditmemo->getInvoice()->getIncrementId()));
         } else {
             $this->_title->add(__("View Memo"));
         }
         $this->_view->loadLayout();
         $this->_view->getLayout()->getBlock('sales_creditmemo_view')->updateBackButtonUrl($this->getRequest()->getParam('come_from'));
         $this->_setActiveMenu('Magento_Sales::sales_creditmemo');
         $this->_view->renderLayout();
     } else {
         $this->_forward('noroute');
     }
 }
コード例 #7
0
ファイル: UpdateQty.php プロジェクト: Atlis/docker-magento2
 /**
  * Update items qty action
  *
  * @return void
  */
 public function execute()
 {
     try {
         $creditmemo = $this->creditmemoLoader->load($this->_request, true);
         $this->_view->loadLayout();
         $response = $this->_view->getLayout()->getBlock('order_items')->toHtml();
     } catch (\Magento\Framework\Model\Exception $e) {
         $response = array('error' => true, 'message' => $e->getMessage());
     } catch (\Exception $e) {
         $response = array('error' => true, 'message' => __('Cannot update the item\'s quantity.'));
     }
     if (is_array($response)) {
         $response = $this->_objectManager->get('Magento\\Core\\Helper\\Data')->jsonEncode($response);
         $this->getResponse()->representJson($response);
     } else {
         $this->getResponse()->setBody($response);
     }
 }
コード例 #8
0
ファイル: NewAction.php プロジェクト: Atlis/docker-magento2
 /**
  * Creditmemo create page
  *
  * @return void
  */
 public function execute()
 {
     $this->_title->add(__('Credit Memos'));
     if ($creditmemo = $this->creditmemoLoader->load($this->_request)) {
         if ($creditmemo->getInvoice()) {
             $this->_title->add(__("New Memo for #%1", $creditmemo->getInvoice()->getIncrementId()));
         } else {
             $this->_title->add(__("New Memo"));
         }
         if ($comment = $this->_objectManager->get('Magento\\Backend\\Model\\Session')->getCommentText(true)) {
             $creditmemo->setCommentText($comment);
         }
         $this->_view->loadLayout();
         $this->_setActiveMenu('Magento_Sales::sales_order');
         $this->_view->renderLayout();
     } else {
         $this->_forward('noroute');
     }
 }
コード例 #9
0
ファイル: Cancel.php プロジェクト: aiesh/magento2
 /**
  * Cancel creditmemo action
  *
  * @return void
  */
 public function execute()
 {
     $this->creditmemoLoader->setOrderId($this->getRequest()->getParam('order_id'));
     $this->creditmemoLoader->setCreditmemoId($this->getRequest()->getParam('creditmemo_id'));
     $this->creditmemoLoader->setCreditmemo($this->getRequest()->getParam('creditmemo'));
     $this->creditmemoLoader->setInvoiceId($this->getRequest()->getParam('invoice_id'));
     $creditmemo = $this->creditmemoLoader->load();
     if ($creditmemo) {
         try {
             $creditmemo->cancel();
             $transactionSave = $this->_objectManager->create('Magento\\Framework\\DB\\Transaction');
             $transactionSave->addObject($creditmemo);
             $transactionSave->addObject($creditmemo->getOrder());
             if ($creditmemo->getInvoice()) {
                 $transactionSave->addObject($creditmemo->getInvoice());
             }
             $transactionSave->save();
             $this->messageManager->addSuccess(__('The credit memo has been canceled.'));
         } catch (\Magento\Framework\Model\Exception $e) {
             $this->messageManager->addError($e->getMessage());
         } catch (\Exception $e) {
             $this->messageManager->addError(__('You canceled the credit memo.'));
         }
         $this->_redirect('sales/*/view', array('creditmemo_id' => $creditmemo->getId()));
     } else {
         $this->_forward('noroute');
     }
 }
コード例 #10
0
ファイル: View.php プロジェクト: nblair/magescotch
 /**
  * Creditmemo information page
  *
  * @return \Magento\Backend\Model\View\Result\Page|\Magento\Backend\Model\View\Result\Forward
  */
 public function executeInternal()
 {
     $this->creditmemoLoader->setOrderId($this->getRequest()->getParam('order_id'));
     $this->creditmemoLoader->setCreditmemoId($this->getRequest()->getParam('creditmemo_id'));
     $this->creditmemoLoader->setCreditmemo($this->getRequest()->getParam('creditmemo'));
     $this->creditmemoLoader->setInvoiceId($this->getRequest()->getParam('invoice_id'));
     $creditmemo = $this->creditmemoLoader->load();
     if ($creditmemo) {
         $resultPage = $this->resultPageFactory->create();
         $resultPage->getLayout()->getBlock('sales_creditmemo_view')
             ->updateBackButtonUrl($this->getRequest()->getParam('come_from'));
         $resultPage->setActiveMenu('Magento_Sales::sales_creditmemo');
         if ($creditmemo->getInvoice()) {
             $resultPage->getConfig()->getTitle()->prepend(
                 __("View Memo for #%1", $creditmemo->getInvoice()->getIncrementId())
             );
         } else {
             $resultPage->getConfig()->getTitle()->prepend(__("View Memo"));
         }
         return $resultPage;
     } else {
         $resultForward = $this->resultForwardFactory->create();
         $resultForward->forward('noroute');
         return $resultForward;
     }
 }
コード例 #11
0
 /**
  * Add comment to creditmemo history
  *
  * @return \Magento\Framework\Controller\Result\Raw|\Magento\Framework\Controller\Result\Json
  */
 public function execute()
 {
     try {
         $this->getRequest()->setParam('creditmemo_id', $this->getRequest()->getParam('id'));
         $data = $this->getRequest()->getPost('comment');
         if (empty($data['comment'])) {
             throw new \Magento\Framework\Exception\LocalizedException(__('Please enter a comment.'));
         }
         $this->creditmemoLoader->setOrderId($this->getRequest()->getParam('order_id'));
         $this->creditmemoLoader->setCreditmemoId($this->getRequest()->getParam('creditmemo_id'));
         $this->creditmemoLoader->setCreditmemo($this->getRequest()->getParam('creditmemo'));
         $this->creditmemoLoader->setInvoiceId($this->getRequest()->getParam('invoice_id'));
         $creditmemo = $this->creditmemoLoader->load();
         $comment = $creditmemo->addComment($data['comment'], isset($data['is_customer_notified']), isset($data['is_visible_on_front']));
         $comment->save();
         $this->creditmemoCommentSender->send($creditmemo, !empty($data['is_customer_notified']), $data['comment']);
         $resultPage = $this->resultPageFactory->create();
         $response = $resultPage->getLayout()->getBlock('creditmemo_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)) {
         $resultJson = $this->resultJsonFactory->create();
         $resultJson->setData($response);
         return $resultJson;
     } else {
         $resultRaw = $this->resultRawFactory->create();
         $resultRaw->setContents($response);
         return $resultRaw;
     }
 }
コード例 #12
0
 /**
  * Creditmemo create page
  *
  * @return \Magento\Backend\Model\View\Result\Page|\Magento\Backend\Model\View\Result\Forward
  */
 public function execute()
 {
     $this->creditmemoLoader->setOrderId($this->getRequest()->getParam('order_id'));
     $this->creditmemoLoader->setCreditmemoId($this->getRequest()->getParam('creditmemo_id'));
     $this->creditmemoLoader->setCreditmemo($this->getRequest()->getParam('creditmemo'));
     $this->creditmemoLoader->setInvoiceId($this->getRequest()->getParam('invoice_id'));
     $creditmemo = $this->creditmemoLoader->load();
     if ($creditmemo) {
         if ($comment = $this->_objectManager->get('Magento\\Backend\\Model\\Session')->getCommentText(true)) {
             $creditmemo->setCommentText($comment);
         }
         $resultPage = $this->resultPageFactory->create();
         $resultPage->setActiveMenu('Magento_Sales::sales_order');
         $resultPage->getConfig()->getTitle()->prepend(__('Credit Memos'));
         if ($creditmemo->getInvoice()) {
             $resultPage->getConfig()->getTitle()->prepend(__("New Memo for #%1", $creditmemo->getInvoice()->getIncrementId()));
         } else {
             $resultPage->getConfig()->getTitle()->prepend(__("New Memo"));
         }
         return $resultPage;
     } else {
         $resultForward = $this->resultForwardFactory->create();
         $resultForward->forward('noroute');
         return $resultForward;
     }
 }
コード例 #13
0
ファイル: Void.php プロジェクト: shabbirvividads/magento2
 /**
  * Void creditmemo action
  *
  * @return \Magento\Backend\Model\View\Result\Redirect|\Magento\Backend\Model\View\Result\Forward
  */
 public function execute()
 {
     $this->creditmemoLoader->setOrderId($this->getRequest()->getParam('order_id'));
     $this->creditmemoLoader->setCreditmemoId($this->getRequest()->getParam('creditmemo_id'));
     $this->creditmemoLoader->setCreditmemo($this->getRequest()->getParam('creditmemo'));
     $this->creditmemoLoader->setInvoiceId($this->getRequest()->getParam('invoice_id'));
     $creditmemo = $this->creditmemoLoader->load();
     if ($creditmemo) {
         try {
             $creditmemo->void();
             $transactionSave = $this->_objectManager->create('Magento\\Framework\\DB\\Transaction');
             $transactionSave->addObject($creditmemo);
             $transactionSave->addObject($creditmemo->getOrder());
             if ($creditmemo->getInvoice()) {
                 $transactionSave->addObject($creditmemo->getInvoice());
             }
             $transactionSave->save();
             $this->messageManager->addSuccess(__('You voided the credit memo.'));
         } catch (\Magento\Framework\Exception\LocalizedException $e) {
             $this->messageManager->addError($e->getMessage());
         } catch (\Exception $e) {
             $this->messageManager->addError(__('We can\'t void the credit memo.'));
         }
         $resultRedirect = $this->resultRedirectFactory->create();
         $resultRedirect->setPath('sales/*/view', ['creditmemo_id' => $creditmemo->getId()]);
         return $resultRedirect;
     } else {
         $resultForward = $this->resultForwardFactory->create();
         $resultForward->forward('noroute');
         return $resultForward;
     }
 }
コード例 #14
0
ファイル: UpdateQty.php プロジェクト: nblair/magescotch
 /**
  * Update items qty action
  *
  * @return \Magento\Framework\Controller\Result\Json|\Magento\Framework\Controller\Result\Raw
  */
 public function executeInternal()
 {
     try {
         $this->creditmemoLoader->setOrderId($this->getRequest()->getParam('order_id'));
         $this->creditmemoLoader->setCreditmemoId($this->getRequest()->getParam('creditmemo_id'));
         $this->creditmemoLoader->setCreditmemo($this->getRequest()->getParam('creditmemo'));
         $this->creditmemoLoader->setInvoiceId($this->getRequest()->getParam('invoice_id'));
         $this->creditmemoLoader->load();
         $resultPage = $this->resultPageFactory->create();
         $response = $resultPage->getLayout()->getBlock('order_items')->toHtml();
     } catch (\Magento\Framework\Exception\LocalizedException $e) {
         $response = ['error' => true, 'message' => $e->getMessage()];
     } catch (\Exception $e) {
         $response = ['error' => true, 'message' => __('We can\'t update the item\'s quantity right now.')];
     }
     if (is_array($response)) {
         $resultJson = $this->resultJsonFactory->create();
         $resultJson->setData($response);
         return $resultJson;
     } else {
         $resultRaw = $this->resultRawFactory->create();
         $resultRaw->setContents($response);
         return $resultRaw;
     }
 }
コード例 #15
0
ファイル: Void.php プロジェクト: Atlis/docker-magento2
 /**
  * Void creditmemo action
  *
  * @return void
  */
 public function execute()
 {
     $creditmemo = $this->creditmemoLoader->load($this->_request);
     if ($creditmemo) {
         try {
             $creditmemo->void();
             $transactionSave = $this->_objectManager->create('Magento\\Framework\\DB\\Transaction')->addObject($creditmemo)->addObject($creditmemo->getOrder());
             if ($creditmemo->getInvoice()) {
                 $transactionSave->addObject($creditmemo->getInvoice());
             }
             $transactionSave->save();
             $this->messageManager->addSuccess(__('You voided the credit memo.'));
         } catch (\Magento\Framework\Model\Exception $e) {
             $this->messageManager->addError($e->getMessage());
         } catch (\Exception $e) {
             $this->messageManager->addError(__('We can\'t void the credit memo.'));
         }
         $this->_redirect('sales/*/view', array('creditmemo_id' => $creditmemo->getId()));
     } else {
         $this->_forward('noroute');
     }
 }
コード例 #16
0
 /**
  * Create pdf for current creditmemo
  *
  * @return ResponseInterface|\Magento\Backend\Model\View\Result\Forward
  */
 public function execute()
 {
     $this->creditmemoLoader->setOrderId($this->getRequest()->getParam('order_id'));
     $this->creditmemoLoader->setCreditmemoId($this->getRequest()->getParam('creditmemo_id'));
     $this->creditmemoLoader->setCreditmemo($this->getRequest()->getParam('creditmemo'));
     $this->creditmemoLoader->setInvoiceId($this->getRequest()->getParam('invoice_id'));
     $this->creditmemoLoader->load();
     return parent::execute();
 }
コード例 #17
0
ファイル: PrintAction.php プロジェクト: aiesh/magento2
 /**
  * Create pdf for current creditmemo
  *
  * @return ResponseInterface|void
  */
 public function execute()
 {
     $this->_title->add(__('Credit Memos'));
     $this->creditmemoLoader->setOrderId($this->getRequest()->getParam('order_id'));
     $this->creditmemoLoader->setCreditmemoId($this->getRequest()->getParam('creditmemo_id'));
     $this->creditmemoLoader->setCreditmemo($this->getRequest()->getParam('creditmemo'));
     $this->creditmemoLoader->setInvoiceId($this->getRequest()->getParam('invoice_id'));
     $this->creditmemoLoader->load();
     parent::execute();
 }
コード例 #18
0
 /**
  * Save creditmemo
  * We can save only new creditmemo. Existing creditmemos are not editable
  *
  * @return \Magento\Backend\Model\View\Result\Redirect|\Magento\Backend\Model\View\Result\Forward
  *
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function execute()
 {
     $resultRedirect = $this->resultRedirectFactory->create();
     $data = $this->getRequest()->getPost('creditmemo');
     if (!empty($data['comment_text'])) {
         $this->_getSession()->setCommentText($data['comment_text']);
     }
     try {
         $this->creditmemoLoader->setOrderId($this->getRequest()->getParam('order_id'));
         $this->creditmemoLoader->setCreditmemoId($this->getRequest()->getParam('creditmemo_id'));
         $this->creditmemoLoader->setCreditmemo($this->getRequest()->getParam('creditmemo'));
         $this->creditmemoLoader->setInvoiceId($this->getRequest()->getParam('invoice_id'));
         $creditmemo = $this->creditmemoLoader->load();
         if ($creditmemo) {
             if (!$creditmemo->isValidGrandTotal()) {
                 throw new \Magento\Framework\Exception\LocalizedException(__('The credit memo\'s total must be positive.'));
             }
             if (!empty($data['comment_text'])) {
                 $creditmemo->addComment($data['comment_text'], isset($data['comment_customer_notify']), isset($data['is_visible_on_front']));
                 $creditmemo->setCustomerNote($data['comment_text']);
                 $creditmemo->setCustomerNoteNotify(isset($data['comment_customer_notify']));
             }
             if (isset($data['do_offline'])) {
                 //do not allow online refund for Refund to Store Credit
                 if (!$data['do_offline'] && !empty($data['refund_customerbalance_return_enable'])) {
                     throw new \Magento\Framework\Exception\LocalizedException(__('Cannot create online refund for Refund to Store Credit.'));
                 }
             }
             $creditmemoManagement = $this->_objectManager->create('Magento\\Sales\\Api\\CreditmemoManagementInterface');
             $creditmemoManagement->refund($creditmemo, (bool) $data['do_offline'], !empty($data['send_email']));
             if (!empty($data['send_email'])) {
                 $this->creditmemoSender->send($creditmemo);
             }
             $this->messageManager->addSuccess(__('You created the credit memo.'));
             $this->_getSession()->getCommentText(true);
             $resultRedirect->setPath('sales/order/view', ['order_id' => $creditmemo->getOrderId()]);
             return $resultRedirect;
         } else {
             $resultForward = $this->resultForwardFactory->create();
             $resultForward->forward('noroute');
             return $resultForward;
         }
     } catch (\Magento\Framework\Exception\LocalizedException $e) {
         $this->messageManager->addError($e->getMessage());
         $this->_getSession()->setFormData($data);
     } catch (\Exception $e) {
         $this->_objectManager->get('Psr\\Log\\LoggerInterface')->critical($e);
         $this->messageManager->addError(__('We can\'t save the credit memo right now.'));
     }
     $resultRedirect->setPath('sales/*/new', ['_current' => true]);
     return $resultRedirect;
 }
コード例 #19
0
 /**
  * @param Creditmemo $dataObject
  * @return bool|\Magento\Sales\Model\Order\Creditmemo
  */
 public function getModel(Creditmemo $dataObject)
 {
     $this->creditmemoLoader->setOrderId($dataObject->getOrderId());
     $this->creditmemoLoader->setCreditmemoId($dataObject->getEntityId());
     $items = [];
     foreach ($dataObject->getItems() as $item) {
         $items[$item->getOrderItemId()] = ['qty' => $item->getQty()];
     }
     $creditmemo = ['items' => $items, 'shipping_amount' => $dataObject->getShippingAmount(), 'adjustment_positive' => $dataObject->getAdjustmentPositive(), 'adjustment_negative' => $dataObject->getAdjustmentNegative()];
     $this->creditmemoLoader->setCreditmemo($creditmemo);
     $this->creditmemoLoader->setInvoiceId($dataObject->getInvoiceId());
     return $this->creditmemoLoader->load();
 }
コード例 #20
0
 /**
  *  test execute method
  */
 public function testExecute()
 {
     $this->requestMock->expects($this->exactly(4))->method('getParam')->will($this->returnValueMap([['order_id', null, 'order_id'], ['creditmemo_id', null, 'creditmemo_id'], ['creditmemo', null, 'creditmemo'], ['invoice_id', null, 'invoice_id']]));
     $this->creditmemoLoaderMock->expects($this->once())->method('setOrderId')->with($this->equalTo('order_id'));
     $this->creditmemoLoaderMock->expects($this->once())->method('setCreditmemoId')->with($this->equalTo('creditmemo_id'));
     $this->creditmemoLoaderMock->expects($this->once())->method('setCreditmemo')->with($this->equalTo('creditmemo'));
     $this->creditmemoLoaderMock->expects($this->once())->method('setInvoiceId')->with($this->equalTo('invoice_id'));
     $this->creditmemoLoaderMock->expects($this->once())->method('load')->will($this->returnValue($this->creditmemoMock));
     $this->creditmemoMock->expects($this->exactly(2))->method('getInvoice')->will($this->returnValue($this->invoiceMock));
     $this->invoiceMock->expects($this->once())->method('getIncrementId')->will($this->returnValue('invoice-increment-id'));
     $this->titleMock->expects($this->exactly(2))->method('prepend')->will($this->returnValueMap([['Credit Memos', null], ['New Memo for #invoice-increment-id', null], ['item-title', null]]));
     $this->objectManagerMock->expects($this->once())->method('get')->with($this->equalTo('Magento\\Backend\\Model\\Session'))->will($this->returnValue($this->backendSessionMock));
     $this->backendSessionMock->expects($this->once())->method('getCommentText')->with($this->equalTo(true))->will($this->returnValue('comment'));
     $this->creditmemoMock->expects($this->once())->method('setCommentText')->with($this->equalTo('comment'));
     $this->resultPageMock->expects($this->any())->method('getConfig')->will($this->returnValue($this->pageConfigMock));
     $this->pageConfigMock->expects($this->any())->method('getTitle')->willReturn($this->titleMock);
     $this->resultPageFactoryMock->expects($this->once())->method('create')->willReturn($this->resultPageMock);
     $this->resultPageMock->expects($this->once())->method('setActiveMenu')->with('Magento_Sales::sales_order')->willReturnSelf();
     $this->resultPageMock->expects($this->atLeastOnce())->method('getConfig')->willReturn($this->pageConfigMock);
     $this->assertInstanceOf('Magento\\Backend\\Model\\View\\Result\\Page', $this->controller->execute());
 }
コード例 #21
0
 /**
  *  test execute method
  */
 public function testExecute()
 {
     $this->requestMock->expects($this->exactly(4))->method('getParam')->will($this->returnValueMap([['order_id', null, 'order_id'], ['creditmemo_id', null, 'creditmemo_id'], ['creditmemo', null, 'creditmemo'], ['invoice_id', null, 'invoice_id']]));
     $this->creditmemoLoaderMock->expects($this->once())->method('setOrderId')->with($this->equalTo('order_id'));
     $this->creditmemoLoaderMock->expects($this->once())->method('setCreditmemoId')->with($this->equalTo('creditmemo_id'));
     $this->creditmemoLoaderMock->expects($this->once())->method('setCreditmemo')->with($this->equalTo('creditmemo'));
     $this->creditmemoLoaderMock->expects($this->once())->method('setInvoiceId')->with($this->equalTo('invoice_id'));
     $this->creditmemoLoaderMock->expects($this->once())->method('load')->will($this->returnValue($this->creditmemoMock));
     $this->creditmemoMock->expects($this->exactly(2))->method('getInvoice')->will($this->returnValue($this->invoiceMock));
     $this->invoiceMock->expects($this->once())->method('getIncrementId')->will($this->returnValue('invoice-increment-id'));
     $this->titleMock->expects($this->exactly(3))->method('add')->will($this->returnValueMap([['Credit Memos', null], ['New Memo for #invoice-increment-id', null], ['item-title', null]]));
     $this->objectManagerMock->expects($this->once())->method('get')->with($this->equalTo('Magento\\Backend\\Model\\Session'))->will($this->returnValue($this->backendSessionMock));
     $this->backendSessionMock->expects($this->once())->method('getCommentText')->with($this->equalTo(true))->will($this->returnValue('comment'));
     $this->creditmemoMock->expects($this->once())->method('setCommentText')->with($this->equalTo('comment'));
     $this->viewMock->expects($this->once())->method('loadLayout');
     $this->viewMock->expects($this->once())->method('renderLayout');
     $this->viewMock->expects($this->once())->method('getLayout')->will($this->returnValue($this->layoutMock));
     $this->layoutMock->expects($this->once())->method('getBlock')->with($this->equalTo('menu'))->will($this->returnValue($this->blockMenuMock));
     $this->blockMenuMock->expects($this->once())->method('setActive')->with($this->equalTo('Magento_Sales::sales_order'));
     $this->blockMenuMock->expects($this->once())->method('getMenuModel')->will($this->returnValue($this->modelMenuMock));
     $this->modelMenuMock->expects($this->once())->method('getParentItems')->will($this->returnValue([$this->modelMenuItem]));
     $this->modelMenuItem->expects($this->once())->method('getTitle')->will($this->returnValue('item-title'));
     $this->assertNull($this->controller->execute());
 }
コード例 #22
0
ファイル: PrintAction.php プロジェクト: Atlis/docker-magento2
 /**
  * Create pdf for current creditmemo
  *
  * @return ResponseInterface|void
  */
 public function execute()
 {
     $this->_title->add(__('Credit Memos'));
     $this->creditmemoLoader->load($this->_request);
     parent::execute();
 }