如何获取所有 magento 订单状态(待处理、完成、处理等)的列表?
它应该显示所有值,例如 magento 后端的订单索引网格页面中的“状态”下拉字段。
只需使用这行简单的代码:
Mage::getModel('sales/order_status')->getResourceCollection()->getData();
例如:
var_dump( Mage::getModel('sales/order_status')->getResourceCollection()->getData() );
结果:
array(10) { [0]=> array(2) { ["status"]=> string(8) "canceled" ["label"]=> string(8) "Canceled" } [1]=> array(2) { ["status"]=> string(6) "closed" ["label"]=> string(6) "Closed" } [2]=> array(2) { ["status"]=> string(8) "complete" ["label"]=> string(8) "Complete" } [3]=> array(2) { ["status"]=> string(5) "fraud" ["label"]=> string(15) "Suspected Fraud" } [4]=> array(2) { ["status"]=> string(6) "holded" ["label"]=> string(7) "On Hold" } [5]=> array(2) { ["status"]=> string(14) "payment_review" ["label"]=> string(14) "Payment Review" } [6]=> array(2) { ["status"]=> string(7) "pending" ["label"]=> string(7) "Pending" } [7]=> array(2) { ["status"]=> string(15) "pending_payment" ["label"]=> string(15) "Pending Payment" } [8]=> array(2) { ["status"]=> string(14) "pending_paypal" ["label"]=> string(14) "Pending PayPal" } [9]=> array(2) { ["status"]=> string(10) "processing" ["label"]=> string(10) "Processing" } }
获取所有订单状态并将数组保存$orderStatus[status][label]
在$status
关联数组中:
$orderStatusCollection = Mage::getModel('sales/order_status')->getResourceCollection()->getData();
$status = array();
$status = array(
'-1'=>'Please Select..'
);
foreach($orderStatusCollection as $orderStatus) {
$status[] = array (
'value' => $orderStatus['status'], 'label' => $orderStatus['label']
);
}
以下是获取 dop-down 输出的方法:
$statuses = Mage::getModel('sales/order_status')->getCollection()
->toOptionArray()
echo '<pre>';print_r($statuses);echo '</pre>';
//this will output:
Array
(
[0] => Array
(
[status] => canceled
[label] => Canceled
)
[1] => Array
(
[status] => cancel_ogone
[label] => Cancelled Ogone
)
[2] => Array
(
[status] => closed
[label] => Closed
)
[3] => Array
(
[status] => complete
[label] => Complete
)
.....