2011-11-21 6 views
1

Magento에서 주문을 프로그래밍 방식으로 환불받을 수있는 방법은 무엇입니까? 보다 정확하게 말하자면, 보류 중 상태 및 상태에있는 주문을 적절한 환불 상태 및/또는 상태로 어떻게 변경할 수 있습니까?Magento - 프로그래밍 방식으로 환불을 처리하는 방법은 무엇입니까?

+0

오프라인에서 신용 메모를 발급 받으려하고 있습니까? 아니면 지불 게이트웨이를 통해 온라인 환불을 실행하겠다는 목표입니까? – benmarks

+0

Magento 측의 게이트 웨이에서 ipn 환불을 처리하려고합니다 (적절한 절차가 무엇이든간에 상태를 apropriate, 메모로 변경하십시오). 감사. –

답변

0

게이트웨이가 알림을 보내고 있으므로 실제로 IPN 기능을 통해이 작업을 수행 할 수 없습니다. Magento 이미 발생한 작업입니다. 실제로 온라인 환불을 원할 경우 CreditMemoController의 saveAction을 확장하거나 호출하는 것만으로는 충분하지 않습니다.

이것은 실제로 환불을 수행하지만 컨트롤러 내의 보호 된 방법에 의존하는 컨트롤러 작업입니다. 이것을 사용하려면 직접 게시물을 게시하십시오 (예 : https://yoursite.com/admin/sales/order/creditmemo/save/). 또는 꼬집어서이 메서드를 하나의 모 놀리 식 스크립트로 복제 할 수 있습니다.

<?php 

//taken from /app/code/core/Adminhtml/controllers/Sales/Order/CreditmemoController.php 


    /** 
    * Save creditmemo 
    * We can save only new creditmemo. Existing creditmemos are not editable 
    */ 
    public function saveAction() 
    { 
     $data = $this->getRequest()->getPost('creditmemo'); 
     if (!empty($data['comment_text'])) { 
      Mage::getSingleton('adminhtml/session')->setCommentText($data['comment_text']); 
     } 

     try { 
      $creditmemo = $this->_initCreditmemo(); 
      if ($creditmemo) { 
       if (($creditmemo->getGrandTotal() <=0) && (!$creditmemo->getAllowZeroGrandTotal())) { 
        Mage::throwException(
         $this->__('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'])) { 
        $creditmemo->setOfflineRequested((bool)(int)$data['do_offline']); 
       } 

       $creditmemo->register(); 
       if (!empty($data['send_email'])) { 
        $creditmemo->setEmailSent(true); 
       } 

       $creditmemo->getOrder()->setCustomerNoteNotify(!empty($data['send_email'])); 
       $this->_saveCreditmemo($creditmemo); 
       $creditmemo->sendEmail(!empty($data['send_email']), $comment); 
       $this->_getSession()->addSuccess($this->__('The credit memo has been created.')); 
       Mage::getSingleton('adminhtml/session')->getCommentText(true); 
       $this->_redirect('*/sales_order/view', array('order_id' => $creditmemo->getOrderId())); 
       return; 
      } else { 
       $this->_forward('noRoute'); 
       return; 
      } 
     } catch (Mage_Core_Exception $e) { 
      $this->_getSession()->addError($e->getMessage()); 
      Mage::getSingleton('adminhtml/session')->setFormData($data); 
     } catch (Exception $e) { 
      Mage::logException($e); 
      $this->_getSession()->addError($this->__('Cannot save the credit memo.')); 
     } 
     $this->_redirect('*/*/new', array('_current' => true)); 
    } 

HTH, 건배.

관련 문제