M2 order订单相关的代码

3.25K 浏览开发笔记

M2 order订单相关的代码

一,通过订单id获取订单信息

Get Order Information From Order ID

<?php 
$orderid = 2; 
$objectManager = MagentoFrameworkAppObjectManager::getInstance(); 
$order = $objectManager->create('MagentoSalesApiDataOrderInterface')->load($orderid);  //fetch whole order information print_r($order->getData());   
//Or fetch specific information echo $order->IncrementId(); 
echo $order->getGrandTotal(); 
echo $order->getSubtotal(); 
?>

二,根据订单号(increment_id)获取订单信息

<?php 
$orderid = '000000013';   
$objectManager = MagentoFrameworkAppObjectManager::getInstance(); 
$order = $objectManager->create(MagentoSalesModelOrder::class)->loadByIncrementId($orderid);    //fetch whole order information print_r($order->getData());   
//Or fetch specific information 
echo $order->IncrementId(); 
echo $order->getGrandTotal(); 
echo $order->getSubtotal(); ?>

三,获取订单items产品信息

Get Order Items Information

<?php 
$orderid = 2;   
$objectManager = MagentoFrameworkAppObjectManager::getInstance(); 
$order = $objectManager->create('MagentoSalesApiDataOrderInterface')->load($orderid);   //Loop through each item and fetch data 
foreach ($order->getAllItems() as $item) {    
//fetch whole item information    
print_r($item->getData());      
//Or fetch specific item information    
echo $item->getId();    
echo $item->getProductType();    
echo $item->getQtyOrdered();    
echo $item->getPrice();        
} 
?>

四,获取订单支付信息

Get Order Payment Information

<?php 
$orderid = 2;   
$objectManager = MagentoFrameworkAppObjectManager::getInstance(); 
$order = $objectManager->create('MagentoSalesApiDataOrderInterface')->load($orderid);   
//fetch whole payment information 
print_r($order->getPayment()->getData());   
//Or fetch specific payment information 
echo $order->getPayment()->getAmountPaid(); 
echo $order->getPayment()->getMethod(); 
echo $order->getPayment()->getAdditionalInformation('method_title'); 
?>

五,获取订单联系人信息

Get Order Customer Information

<?php 
$orderid = 2;   
$objectManager = MagentoFrameworkAppObjectManager::getInstance(); 
$order = $objectManager->create('MagentoSalesApiDataOrderInterface')->load($orderid);   
//fetch customer information 
echo $order->getCustomerId(); 
echo $order->getCustomerEmail(); 
echo $order->getCustomerFirstname(); 
echo $order->getCustomerLastname(); 
?>

六,获取订单支付地址和发货地址

Get Order Shipping And Billing Information

<?php 
$orderid = 2;   
$objectManager = MagentoFrameworkAppObjectManager::getInstance(); 
$order = $objectManager->create('MagentoSalesApiDataOrderInterface')->load($orderid);   
//fetch whole billing information 
print_r($order->getBillingAddress()->getData());   
//Or fetch specific billing information 
echo $order->getBillingAddress()->getCity(); 
echo $order->getBillingAddress()->getRegionId(); 
echo $order->getBillingAddress()->getCountryId();   
//fetch whole shipping information 
print_r($order->getShippingAddress()->getData());   
//Or fetch specific shipping information 
echo $order->getShippingAddress()->getCity(); 
echo $order->getShippingAddress()->getRegionId(); 
echo $order->getShippingAddress()->getCountryId();   
?>

七,订单数组示例

Array (     
[entity_id] => 13     
[state] => processing     
[status] => processing     
[coupon_code] =>     
[protect_code] => b885638f4086bd118e9c120cc5ff4e75     
[shipping_description] => Flat Rate - Fixed     
[is_virtual] => 0     
[store_id] => 1     
[customer_id] =>     
[base_discount_amount] => 0.0000     
[base_discount_canceled] =>     
[base_discount_invoiced] => 0.0000     
[base_discount_refunded] =>     
[base_grand_total] => 30.0000     
[base_shipping_amount] => 5.0000     
[base_shipping_canceled] =>     
[base_shipping_invoiced] => 5.0000     
[base_shipping_refunded] =>     
[base_shipping_tax_amount] => 0.0000    
[base_shipping_tax_refunded] =>     
[base_subtotal] => 25.0000     
[base_subtotal_canceled] =>     
[base_subtotal_invoiced] => 25.0000     
[base_subtotal_refunded] =>     
[base_tax_amount] => 0.0000     
[base_tax_canceled] =>     
[base_tax_invoiced] => 0.0000     
[base_tax_refunded] =>     
[base_to_global_rate] => 1.0000     
[base_to_order_rate] => 1.0000     
[base_total_canceled] =>     
[base_total_invoiced] => 30.0000     
[base_total_invoiced_cost] => 0.0000     
[base_total_offline_refunded] =>     
[base_total_online_refunded] =>     
[base_total_paid] => 30.0000     
[base_total_qty_ordered] =>     
[base_total_refunded] =>     
[discount_amount] => 0.0000     
[discount_canceled] =>     
[discount_invoiced] => 0.0000     
[discount_refunded] =>     
[grand_total] => 30.0000     
[shipping_amount] => 5.0000     
[shipping_canceled] =>     
[shipping_invoiced] => 5.0000     
[shipping_refunded] =>     
[shipping_tax_amount] => 0.0000     
[shipping_tax_refunded] =>     
[store_to_base_rate] => 0.0000     
[store_to_order_rate] => 0.0000     
[subtotal] => 25.0000     
[subtotal_canceled] =>     
[subtotal_invoiced] => 25.0000     
[subtotal_refunded] =>     
[tax_amount] => 0.0000     
[tax_canceled] =>     
[tax_invoiced] => 0.0000     
[tax_refunded] =>     
[total_canceled] =>     
[total_invoiced] => 30.0000     
[total_offline_refunded] =>     
[total_online_refunded] =>     
[total_paid] => 30.0000     
[total_qty_ordered] => 1.0000     
[total_refunded] =>     
[can_ship_partially] =>     
[can_ship_partially_item] =>     
[customer_is_guest] => 1     
[customer_note_notify] => 0     
[billing_address_id] => 25     
[customer_group_id] => 0     
[edit_increment] =>     
[email_sent] =>     
[send_email] => 1     
[forced_shipment_with_invoice] =>     
[payment_auth_expiration] =>     
[quote_address_id] =>     
[quote_id] => 60     
[shipping_address_id] => 24     
[adjustment_negative] =>     
[adjustment_positive] =>     
[base_adjustment_negative] =>     
[base_adjustment_positive] =>     
[base_shipping_discount_amount] => 0.0000     
[base_subtotal_incl_tax] => 25.0000     
[base_total_due] => 0.0000     
[payment_authorization_amount] =>     
[shipping_discount_amount] => 0.0000     
[subtotal_incl_tax] => 25.0000     
[total_due] => 0.0000    
[weight] => 0.0000     
[customer_dob] =>     
[increment_id] => 000000013     
[applied_rule_ids] =>     
[base_currency_code] => EUR     
[customer_email] => 529894459@qq.com     
[customer_firstname] =>     
[customer_lastname] =>     
[customer_middlename] =>     
[customer_prefix] =>     
[customer_suffix] =>     
[customer_taxvat] =>     
[discount_description] =>     
[ext_customer_id] =>     
[ext_order_id] =>     
[global_currency_code] => EUR     
[hold_before_state] =>     
[hold_before_status] =>     
[order_currency_code] => EUR     
[original_increment_id] =>     
[relation_child_id] =>     
[relation_child_real_id] =>     
[relation_parent_id] =>     
[relation_parent_real_id] =>     
[remote_ip] => 52.192.86.54     
[shipping_method] => flatrate_flatrate     
[store_currency_code] => EUR     
[store_name] => Main Website Main Website Store     
[x_forwarded_for] =>     
[customer_note] =>     
[created_at] => 2018-08-07 12:12:48     
[updated_at] => 2018-08-07 12:50:00     
[total_item_count] => 1     
[customer_gender] =>     
[discount_tax_compensation_amount] => 0.0000     
[base_discount_tax_compensation_amount] => 0.0000     
[shipping_discount_tax_compensation_amount] => 0.0000     
[base_shipping_discount_tax_compensation_amnt] => 0.0000     
[discount_tax_compensation_invoiced] => 0.0000     
[base_discount_tax_compensation_invoiced] => 0.0000     
[discount_tax_compensation_refunded] =>     
[base_discount_tax_compensation_refunded] =>     
[shipping_incl_tax] => 5.0000     
[base_shipping_incl_tax] => 5.0000    
[coupon_rule_name] =>     
[gift_message_id] =>     
[paypal_ipn_customer_notified] => 0     
[order_comment] =>     
[allItems] => Array         (             
    [36] => Array                 (                     
      [item_id] => 36                     
      [order_id] => 13                     
      [parent_item_id] =>                     
      [quote_item_id] => 229                     
      [store_id] => 1                     
      [created_at] => 2018-08-07 12:12:48                     
      [updated_at] => 2018-08-07 12:50:00                     
      [product_id] => 38                     
      [product_type] => simple                     
      [product_options] => Array                         (                             
          [info_buyRequest] => Array                                 (                                     
            [uenc] => aHR0cDovL3RlZXRlZS5tZ3RkZXYyLmlnZ28uZmkvb3JpZ2FtaS1taW5pLWRvdmUtcGVuZGFudC1wZWFjaC5odG1s                                     
             => 38                                     
            [selected_configurable_option] =>                                     
            [related_product] =>                                     
            [qty] => 1                                 
            )                         
          )                     
          [weight] =>                     
          [is_virtual] => 0                     
          [sku] => ORIGAMI Mini Dove Pendant, Peach                     
          [name] => ORIGAMI Mini Dove Pendant, Peach                     
          [description] =>                     
          [applied_rule_ids] =>                     
          [additional_data] =>                     
          [is_qty_decimal] => 0                     
          [no_discount] => 0                     
          [qty_backordered] =>                     
          [qty_canceled] => 0.0000                     
          [qty_invoiced] => 1.0000                     
          [qty_ordered] => 1.0000                     
          [qty_refunded] => 0.0000                     
          [qty_shipped] => 0.0000                     
          [base_cost] =>                     
          [price] => 25.0000                     
          [base_price] => 25.0000                     
          [original_price] => 25.0000                     
          [base_original_price] => 25.0000                     
          [tax_percent] => 0.0000                     
          [tax_amount] => 0.0000                     
          [base_tax_amount] => 0.0000                     
          [tax_invoiced] => 0.0000                     
          [base_tax_invoiced] => 0.0000                     
          [discount_percent] => 0.0000                     
          [discount_amount] => 0.0000                     
          [base_discount_amount] => 0.0000                     
          [discount_invoiced] => 0.0000                     
          [base_discount_invoiced] => 0.0000                    
          [amount_refunded] => 0.0000                     
          [base_amount_refunded] => 0.0000                     
          [row_total] => 25.0000                     
          [base_row_total] => 25.0000                     
          [row_invoiced] => 25.0000                     
          [base_row_invoiced] => 25.0000                     
          [row_weight] => 0.0000                     
          [base_tax_before_discount] =>                     
          [tax_before_discount] =>                     
          [ext_order_item_id] =>                     
          [locked_do_invoice] =>                     
          [locked_do_ship] =>                     
          [price_incl_tax] => 25.0000                     
          [base_price_incl_tax] => 25.0000                     
          [row_total_incl_tax] => 25.0000                     
          [base_row_total_incl_tax] => 25.0000                     
          [discount_tax_compensation_amount] => 0.0000                     
          [base_discount_tax_compensation_amount] => 0.0000                     
          [discount_tax_compensation_invoiced] => 0.0000                     
          [base_discount_tax_compensation_invoiced] => 0.0000                     
          [discount_tax_compensation_refunded] =>                     
          [base_discount_tax_compensation_refunded] =>                     
          [tax_canceled] =>                     
          [discount_tax_compensation_canceled] =>                     
          [tax_refunded] =>                     
          [base_tax_refunded] =>                     
          [discount_refunded] =>                     
          [base_discount_refunded] =>                     
          [free_shipping] => 0                     
          [gift_message_id] =>                     
          [gift_message_available] =>                     
          [weee_tax_applied] => []                     
          [weee_tax_applied_amount] =>                     
          [weee_tax_applied_row_amount] =>                     
          [weee_tax_disposition] =>                     
          [weee_tax_row_disposition] =>                     
          [base_weee_tax_applied_amount] =>                     
          [base_weee_tax_applied_row_amnt] =>                     
          [base_weee_tax_disposition] =>                     
          [base_weee_tax_row_disposition] =>                     
           => Array                         (                             
              [entity_id] => 38                             
              [attribute_set_id] => 4                             
              [type_id] => simple                             
              [sku] => ORIGAMI Mini Dove Pendant, Peach                             
              [has_options] => 0                             
              [required_options] => 0                             
              [created_at] => 2018-02-02 02:43:17                             
              [updated_at] => 2018-02-02 02:43:17                             
              [name] => ORIGAMI Mini Dove Pendant, Peach                             
              [meta_title] => ORIGAMI Mini Dove Pendant, Peach                             
              [meta_description] => ORIGAMI Mini Dove Pendant, Peach                             
              [options_container] => container2                             
              [url_key] => origami-mini-dove-pendant-peach                             
              [gift_message_available] => 2                             
              [meta_keyword] => ORIGAMI Mini Dove Pendant, Peach                             
              [color] => 4                             
              [status] => 1                             
              [visibility] => 4                             
              [quantity_and_stock_status] => Array                                 (                                     
                  [is_in_stock] => 1                                     
                  [qty] => 9999                                 
              )                             
              [tax_class_id] => 5                             
              [is_yarn_product] => 0                             
              [price] => 25.0000                             
              [options] => Array                                 (                                 )                             
              [media_gallery] => Array                                 (                                     
                  [images] => Array                                         (                                         )                                     
                  [values] => Array                                         (                                         )                                 
              )                             
              [extension_attributes] => Array                                 (                                 )                             
              [tier_price] => Array                                 (                                 )                             
              [tier_price_changed] => 0                             
              [category_ids] => Array                                 (                                     
                  [0] => 3                                 
              )                             
              [is_salable] => 1                         
          )                 
      )         
  )     
  [billingAddress] => Array         (             
       [entity_id] => 25             
       [parent_id] => 13             
       [customer_address_id] =>             
       [quote_address_id] =>             
       [region_id] =>             
       [customer_id] =>             
       [fax] =>             
       [region] =>             
       [postcode] => 87100             
       [lastname] => Oy             
       [street] => Kettukalliontie 9             
       [city] => YLIVIESKA, KALAJOKI             
       [email] => 529894459@qq.com             
       [telephone] => 0443005696             
       [country_id] => FI             
       [firstname] => TJ-Kaihdin             
       [address_type] => billing             
       [prefix] =>             
       [middlename] =>             
       [suffix] =>             
       [company] =>             
       [vat_id] =>             
       [vat_is_valid] =>             
       [vat_request_id] =>             
       [vat_request_date] =>             
       [vat_request_success] =>         
   )     
   [shippingAddress] => Array         (             
       [entity_id] => 24             
       [parent_id] => 13             
       [customer_address_id] =>             
       [quote_address_id] =>             
       [region_id] =>             
       [customer_id] =>             
       [fax] =>             
       [region] =>             
       [postcode] => 87100             
       [lastname] => Oy             
       [street] => Kettukalliontie 9             
       [city] => YLIVIESKA, KALAJOKI             
       [email] => 529894459@qq.com             
       [telephone] => 0443005696             
       [country_id] => FI             
       [firstname] => TJ-Kaihdin             
       [address_type] => shipping             
       [prefix] =>             
       [middlename] =>             
       [suffix] =>             
       [company] =>             
       [vat_id] =>             
       [vat_is_valid] =>             
       [vat_request_id] =>             
       [vat_request_date] =>             
       [vat_request_success] =>         
   )     
   [paymentInfo] => Array         (             
       [entity_id] => 13             
       [parent_id] => 13             
       [base_shipping_captured] => 5.0000             
       [shipping_captured] => 5.0000             
       [amount_refunded] =>             
       [base_amount_paid] => 30.0000             
       [amount_canceled] =>             
       [base_amount_authorized] =>             
       [base_amount_paid_online] =>             
       [base_amount_refunded_online] =>             
       [base_shipping_amount] => 5.0000             
       [shipping_amount] => 5.0000             
       [amount_paid] => 30.0000             
       [amount_authorized] =>             
       [base_amount_ordered] => 30.0000             
       [base_shipping_refunded] =>             
       [shipping_refunded] =>             
       [base_amount_refunded] =>             
       [amount_ordered] => 30.0000             
       [base_amount_canceled] =>             
       [quote_payment_id] =>             
       [additional_data] =>             
       [cc_exp_month] =>             
       [cc_ss_start_year] =>             
       [echeck_bank_name] =>             
       [method] => checkmo             
       [cc_debug_request_body] =>             
       [cc_secure_verify] =>             
       [protection_eligibility] =>             
       [cc_approval] =>             
       [cc_last_4] =>             
       [cc_status_description] =>             
       [echeck_type] =>             
       [cc_debug_response_serialized] =>             
       [cc_ss_start_month] =>            
       [echeck_account_type] =>             
       [last_trans_id] =>             
       [cc_cid_status] =>             
       [cc_owner] =>             
       [cc_type] =>             
       [po_number] =>             
       [cc_exp_year] =>             
       [cc_status] =>             
       [echeck_routing_number] =>             
       [account_status] =>             
       [anet_trans_method] =>             
       [cc_debug_response_body] =>             
       [cc_ss_issue] =>             
       [echeck_account_name] =>             
       [cc_avs_status] =>             
       [cc_number_enc] =>             
       [cc_trans_id] =>             
       [address_status] =>             
       [additional_information] => Array                 (                     
           [method_title] => Check / Money order                 
       )         

       
) )

0