2011-12-01 5 views
3

Magento에서 이미 완료 또는 닫힌 상태에 도달 한 주문을 프로그래밍 방식으로 다시 열 수 있습니까? 주문의 상태를 변경하는 데 사용되는 다음 코드가 있지만 완료되었거나 닫힌 주문에 대해서는 작동하지 않습니다.Magento에서 주문 완료/주문 완료?

// connect to magento 
require_once('app/Mage.php'); 
umask(022); 
Mage::app(); 

// check admin credentials 
Mage::getSingleton('core/session', array('name' => 'adminhtml')); 
$admin = Mage::getSingleton('admin/session'); 

if ($admin->isLoggedIn()) { 
    // update order status 
    $orderIncrementId = "100000001"; 
    $order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId); 
    $order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true)->save(); 
} 

현재 코드 here이 있습니다. 이 페이지에서는 Magento 1.3.2.4에서 테스트했지만 Magento 1.6.x를 사용하고 있다고합니다. 어쩌면 그것이 문제일까요?

더 자세한 정보가 필요하면 알려주세요. 제공 할 수있는 도움에 감사드립니다.

답변

2

여기 Magento 버전 문제가 있다고 생각하지 않습니다.

특정 상황에서 Magento는 단지 으로의 상태를 Mage_Sales_Model_Order::STATE_PROCESSING으로 다시 전환 할 수 없습니다.

예를 들어, 보통 환불 (creditmemos)이있는 주문에는 Mage_Sales_Model_Order::STATE_PROCESSING 상태를 저장할 수 없습니다. 1.3.2.4 또는 1.6.x에서도 마찬가지입니다.

이것은 디자인입니다.

Magento가 주문 상태를 각각 STATE_COMPLETE 또는 STATE_CLOSED으로 재설정하도록하려면 Mage_Sales_Model_Order::_checkState()을 확인하십시오.

protected function _checkState() 
{ 
    if (!$this->getId()) { 
     return $this; 
    } 

    $userNotification = $this->hasCustomerNoteNotify() ? $this->getCustomerNoteNotify() : null; 

    if (!$this->isCanceled() 
     && !$this->canUnhold() 
     && !$this->canInvoice() 
     && !$this->canShip()) { 
     if (0 == $this->getBaseGrandTotal() || $this->canCreditmemo()) { 
      if ($this->getState() !== self::STATE_COMPLETE) { 
       $this->_setState(self::STATE_COMPLETE, true, '', $userNotification); 
      } 
     } 
     /** 
     * Order can be closed just in case when we have refunded amount. 
     * In case of "0" grand total order checking ForcedCanCreditmemo flag 
     */ 
     elseif (floatval($this->getTotalRefunded()) || (!$this->getTotalRefunded() 
      && $this->hasForcedCanCreditmemo()) 
     ) { 
      if ($this->getState() !== self::STATE_CLOSED) { 
       $this->_setState(self::STATE_CLOSED, true, '', $userNotification); 
      } 
     } 
    } 

    if ($this->getState() == self::STATE_NEW && $this->getIsInProcess()) { 
     $this->setState(self::STATE_PROCESSING, true, '', $userNotification); 
    } 
    return $this; 
} 

은 귀하의 질문에 대답하려면, 당신은 당신이 STATE_PROCESSING을 설정할 수 있습니다 자신의 방법으로 _checkState() 방법을 재정 의하여 뭘 하려는지 달성 할 수있다.

이지만 Magento가 알지도 예상하거나 처리 할 수없는 새로운 상태 컨텍스트가 생성 될 가능성이 높습니다.

변경 사항으로 인해 혼란이 야기되면 나를 비난하지 마십시오. 너는 경고 받았다. ^^

관련 문제