AI Agent技术社区

AI Agent技术社区 Magento订单状态迷思

Magento订单状态迷思

Magento订单状态迷思01require_once('app/Mage.php');02umask(0);03Mage::app('default');04 05$order = Mage::getMod

Magento订单状态迷思

01 require_once('app/Mage.php');
02 umask(0);
03 Mage::app('default');
04  
05 $order = Mage::getModel('sales/order');
06 $order->loadByIncrementId(100000001);  // 100000001为订单编号
07  
08 // 获取订单状态
09 $status = $order->getStatus();
10 $state  = $order->getState();
11  
12 echo $status;
13 echo "\r\n";
14 echo $state;
15  
16 // 设置订单状态
17 $order->setStatus(Mage_Sales_Model_Order::STATE_PROCESSING);
18 $order->save();

订单有两个状态变量:state和status,这让人困惑,只有测试下了,于是下了个单,然后在Magneto后台处理订单,得出下面的状态值。

01 1. 新订单
02 state  : new
03 status : pending
04  
05 2. 配送后
06 state  : processing
07 status : processing
08  
09 3. 收款后
10 state  : processing
11 status : processing
12  
13 4. 订单完成
14 state  : complete
15 status : complete
16  
17 5. 订单取消
18 state  : canceled
19 status : canceled
20  
21 6. 订单关闭
22 state  : closed
23 status : closed
24  
25 7. 订单挂起
26 state  : holded
27 status : holded

在Magento代码文件app\code\core\Mage\Sales\Model\Order.php中定义了订单的状态常量:

01 /**
02  * Order model
03  *
04  * Supported events:
05  *  sales_order_load_after
06  *  sales_order_save_before
07  *  sales_order_save_after
08  *  sales_order_delete_before
09  *  sales_order_delete_after
10  *
11  * @author Magento Core Team <core@magentocommerce.com>
12  */
13 class Mage_Sales_Model_Order extends Mage_Sales_Model_Abstract
14 {
15  
16     /**
17      * Order states
18      */
19     const STATE_NEW             = 'new';
20     const STATE_PENDING_PAYMENT = 'pending_payment';
21     const STATE_PROCESSING      = 'processing';
22     const STATE_COMPLETE        = 'complete';
23     const STATE_CLOSED          = 'closed';
24     const STATE_CANCELED        = 'canceled';
25     const STATE_HOLDED          = 'holded';
26     const STATE_PAYMENT_REVIEW  = 'payment_review'; // added magento 1.4
27  
28     /**
29      * Order flags
30      */
31     const ACTION_FLAG_CANCEL    = 'cancel';
32     const ACTION_FLAG_HOLD      = 'hold';
33     const ACTION_FLAG_UNHOLD    = 'unhold';
34     const ACTION_FLAG_EDIT      = 'edit';
35     const ACTION_FLAG_CREDITMEMO= 'creditmemo';
36     const ACTION_FLAG_INVOICE   = 'invoice';
37     const ACTION_FLAG_REORDER   = 'reorder';
38     const ACTION_FLAG_SHIP      = 'ship';
39     const ACTION_FLAG_COMMENT   = 'comment';
40  
41     // ...
42 }
43 </core@magentocommerce.com>

其中,pending_payment, payment_review 没有测试到,后来发现是支付(Paypal, Amazon Pay)过程中引入的状态。具体请看 Magento orders: states and statuses,文章阐述了Order States and Order Statuses的区别, 还有如何在Magento订单中增加自定义状态。

Logo

Agent 垂直技术社区,欢迎活跃、内容共建。

更多推荐

  • 浏览量 906
  • 收藏 0
  • 0

所有评论(0)

查看更多评论 
已为社区贡献22条内容