如何在Magento获得订单取消日期?

时间:2014-02-10 16:38:07

标签: magento magento-1.7

我正在处理订单Feed。如何获取Magento中取消订单的日期以及跟踪号更新时的发货日期?

2 个答案:

答案 0 :(得分:1)

要获取订单取消日期,您可以解析订单评论并获取评论的第一个Canceled状态的日期,如下所示:

$order = Mage::getModel('sales/order')->loadByIncrementId(100000050);

$commentCollection = $order->getStatusHistoryCollection();

foreach ($commentCollection as $comment) {    
  if ($comment->getStatus() === Mage_Sales_Model_Order::STATE_CANCELED) {
    $orderCancelDate = $comment->getCreatedAt();
  }
}

echo $orderCancelDate;

输出:

2014-02-11 03:43:09 <- Date\time order was marked `Canceled`

要获取订单的发货日期/时间以及跟踪号更新时的日期/时间,您可以获得如下所示的一切:

$order = Mage::getModel('sales/order')->loadByIncrementId(100000054);

$shipmentCollection = $order->getShipmentsCollection();

foreach ($shipmentCollection as $shipment) {

  // Date/Time when order shipment(s) were created
  echo $shipment->getCreatedAt() . "<br />";

  foreach($shipment->getAllTracks() as $trackingNumber) {

    // Date/Time when the tracking number(s) were updated
    echo $trackingNumber->getUpdatedAt();

    // Date/Time when the tracking number(s) were added
    // echo $trackingNumber->getCreatedAt();
  }
}

输出:

2014-02-11 05:35:10 <- Date\time order was marked `Shipped`
2014-02-11 05:35:38 <- Date\time tracking number(s) were updated

请记住,订单可以包含多个部分货件和每个分批货件的多个跟踪号码,这就是为什么您必须遍历它们才能获得正确的日期\时间。

祝你好运!

答案 1 :(得分:0)

Mage::getModel('sales/order')模型包含所有销售和订单详细信息。 你可以用这个, 考虑&#39; 10003 &#39;是订单号,

$order = Mage::getModel('sales/order')->load(10003);
$_totalData = $order->getData();
print_r($_totalData);

$ _ totalData将包含以下内容:

Array
(
    [entity_id] => 45
    [state] => processing
    [status] => pending
    [coupon_code] => stickytest
    [protect_code] => 1036b0
    [shipping_description] => Voucher code discount
    [is_virtual] => 0
    [store_id] => 1
    [customer_id] =>
    [base_discount_amount] => -195.0000
    [base_discount_canceled] =>
    [base_discount_invoiced] =>
    [base_discount_refunded] =>
    [base_grand_total] => 0.0000
    [base_shipping_amount] => 0.0000
    [base_shipping_canceled] =>
    [base_shipping_invoiced] =>
    [base_shipping_refunded] =>
    [base_shipping_tax_amount] => 0.0000
    [base_shipping_tax_refunded] =>
    [base_subtotal] => 177.2700
    [base_subtotal_canceled] =>
    [base_subtotal_invoiced] =>
    [base_subtotal_refunded] =>
    [base_tax_amount] => 0.0000
    [base_tax_canceled] =>
    [base_tax_invoiced] =>
    [base_tax_refunded] =>
    [base_to_global_rate] => 1.0000
    [base_to_order_rate] => 1.0000
    [base_total_canceled] =>
    [base_total_invoiced] =>
    [base_total_invoiced_cost] =>
    [base_total_offline_refunded] =>
    [base_total_online_refunded] =>
    [base_total_paid] =>
    [base_total_qty_ordered] =>
    [base_total_refunded] =>
    [discount_amount] => -195.0000
    [discount_canceled] =>
    [discount_invoiced] =>
    [discount_refunded] =>
    [grand_total] => 0.0000
    [shipping_amount] => 0.0000
    [shipping_canceled] =>
    [shipping_invoiced] =>
    [shipping_refunded] =>
    [shipping_tax_amount] => 0.0000
    [shipping_tax_refunded] =>
    [store_to_base_rate] => 1.0000
    [store_to_order_rate] => 1.0000
    [subtotal] => 177.2700
    [subtotal_canceled] =>
    [subtotal_invoiced] =>
    [subtotal_refunded] =>
    [tax_amount] => 0.0000
    [tax_canceled] =>
    [tax_invoiced] =>
    [tax_refunded] =>
    [total_canceled] =>
    [total_invoiced] =>
    [total_offline_refunded] =>
    [total_online_refunded] =>
    [total_paid] =>
    [total_qty_ordered] => 1.0000
    [total_refunded] =>
    [can_ship_partially] =>
    [can_ship_partially_item] =>
    [customer_is_guest] => 1
    [customer_note_notify] => 1
    [billing_address_id] => 89
    [customer_group_id] => 0
    [edit_increment] =>
    [email_sent] => 1
    [forced_shipment_with_invoice] =>
    [gift_message_id] =>
    [payment_auth_expiration] =>
    [paypal_ipn_customer_notified] =>
    [quote_address_id] =>
    [quote_id] => 215
    [shipping_address_id] => 90
    [adjustment_negative] =>
    [adjustment_positive] =>
    [base_adjustment_negative] =>
    [base_adjustment_positive] =>
    [base_shipping_discount_amount] => 0.0000
    [base_subtotal_incl_tax] => 195.0000
    [base_total_due] =>
    [payment_authorization_amount] =>
    [shipping_discount_amount] => 0.0000
    [subtotal_incl_tax] => 195.0000
    [total_due] =>
    [weight] => 1.0000
    [customer_dob] =>
    [increment_id] => 100000034
    [applied_rule_ids] => 4
    [base_currency_code] => AUD
    [customer_email] => someone@somewhere.com
    [customer_firstname] => billing[firstname]
    [customer_lastname] => billing[lastname]
    [customer_middlename] =>
    [customer_prefix] =>
    [customer_suffix] =>
    [customer_taxvat] =>
    [discount_description] => stickytest
    [ext_customer_id] =>
    [ext_order_id] =>
    [global_currency_code] => AUD
    [hold_before_state] =>
    [hold_before_status] =>
    [order_currency_code] => AUD
    [original_increment_id] =>
    [relation_child_id] =>
    [relation_child_real_id] =>
    [relation_parent_id] =>
    [relation_parent_real_id] =>
    [remote_ip] => 192.168.0.18
    [shipping_method] => matrixrate_matrixrate_free
    [store_currency_code] => AUD
    [store_name] => Main Website
Main Store
English
    [x_forwarded_for] =>
    [customer_note] =>
    [created_at] => 2012-11-19 10:53:11
    [updated_at] => 2012-11-19 10:53:12
    [total_item_count] => 1
    [customer_gender] =>
    [base_custbalance_amount] =>
    [currency_base_id] =>
    [currency_code] =>
    [currency_rate] =>
    [custbalance_amount] =>
    [is_hold] =>
    [is_multi_payment] =>
    [real_order_id] =>
    [tax_percent] =>
    [tracking_numbers] =>
    [hidden_tax_amount] => 17.7300
    [base_hidden_tax_amount] => 17.7300
    [shipping_hidden_tax_amount] => 0.0000
    [base_shipping_hidden_tax_amnt] => 0.0000
    [hidden_tax_invoiced] =>
    [base_hidden_tax_invoiced] =>
    [hidden_tax_refunded] =>
    [base_hidden_tax_refunded] =>
    [shipping_incl_tax] => 0.0000
    [base_shipping_incl_tax] => 0.0000
    [onestepcheckout_customercomment] => onestepcheckout_comments
    [onestepcheckout_customerfeedback] => Google
    [payment_authorization_expiration] =>
    [forced_do_shipment_with_invoice] =>
    [base_shipping_hidden_tax_amount] => 0.0000
)

有关详细信息,请参阅此link ..