Magento 通过订单号获取订单所有信息

7天成为Magento系统架构师,现在开始学习Magento全栈开发!

《Magento2.X企业级开发实战》

//第一步:通过定单号获得Email

require_once("app/Mage.php");//先引用
$app = Mage::app('default');
$incrementID='C00012577'; 
$orders = Mage::getModel('sales/order')->getCollection();
$orders->addAttributeToFilter('increment_id',$incrementID); //其中 $incrementID为订单号
$orders->addAttributeToSelect('*');
$orders->load();
$alldata = $orders->getData();
$sales_order = Mage::getModel('sales/order')->load($alldata[0]['entity_id']);
$billingAddress=$sales_order->getBillingAddress();
$Email=$sales_order->getData('customer_email'); //客户的邮件
var_dump($Email);

//第二步 获取项目所有的数据

foreach ($sales_order->getAllItems() as $item) {
$option = $item->getProductOptions();
//print_r($option );
$qty = $item->getQtyOrdered();
if(count($option)>1){
if($version == '1.2.1.1'&& isset($option['attributes_info'][0]['value'])){
echo $size = $option['attributes_info'][0]['value'];
}
else{
echo $size = $option['options'][0]['value'];
}
}
else{
$size = "";
}
}

//第三步检查订单


$amount = $alldata[0]['base_discount_amount'];
$fee = $alldata[0]['base_fee_amount'];
$created_at = $alldata[0]['created_at'];
$shippingamount=$alldata[0]['base_shipping_amount'];
$grand_total=$alldata[0]['grand_total'];

$dv_oid = $alldata[0]['entity_id'];
if( $dv_oid=='' ) echo '定单号不存在';

if( $dv_oid && Mage::getSingleton( 'customer/session' )->isLoggedIn() ){
$dv_url = $this->getUrl('sales/order/view/').'order_id/'.$dv_oid.'/';
//die($dv_url);
echo '您已登录,正为您跳转..
'; echo 'redirect to '.$dv_url; echo ''; } $sales_order = Mage::getModel('sales/order')->load($alldata[0]['entity_id']); $billingAddress=$sales_order->getBillingAddress(); //print_r($billingAddress); $shipping=$sales_order->getShippingDescription();//运送方式 $order = Mage::getModel ( 'sales/order' )->loadByIncrementId ($incrementID);//支付方式 $pay=Mage::helper('payment')->getInfoBlock($order->getPayment())->toHtml(); $status = $sales_order->getStatus();//订单状态 $state = $sales_order->getState(); $Email=$sales_order->getData('customer_email'); //客户的邮件

//第四步获取客人的更多信息的方法

echo $name = $item->getName(); //获取订单产品名
echo $price = $item->getPrice();//获取价格
echo $address= $item->getShippingAddress();//获取地址
echo $sku= $item->getSku();//获取sku
echo $FirstName=$billingAddress->getFirstname();
echo $LastName=$billingAddress->getLastname();
echo $Email=$sales_order->getData('customer_email');
echo $Phone=$billingAddress->getTelephone();
echo $ZipCode=$billingAddress->getPostcode();
echo $company=$billingAddress->getCompany();
echo $Address=$billingAddress->getStreetFull();
echo $City=$billingAddress->getCity();
echo $State=$billingAddress->getRegion();
echo $Country=$billingAddress->getCountry();
echo $option = $item->getProductOptions(); //获取option属性
echo $qty =   $item->getQtyOrdered(); //获取订单产品数量
echo $item->getRowTotal();//获取total

Get order total from order id in Magento

Leave a reply

Getting order details from the order id, its an easy task in Magento.

If you have an order id in hand, call the below function for the order ojbect.

$order = Mage::getSingleton('sales/order')->loadByIncrementId($orderId);

Or you want to get the order details from the checkout session, you can use the below function.

$orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
$order = Mage::getSingleton('sales/order')->loadByIncrementId($orderId);

In above code lines the first line is fetching the order id from the checkout session.

To get some basic order detials use below code snippets

echo "Subtotal: ".$order->getSubtotal();
echo "Shipping Amount: ".$order->getShippingAmount();
echo "Discount: ".$order->getDiscountAmount();
echo "Tax Amt: ".$order->getTaxAmount();
echo "Grand Total".$order->getGrandTotal();
Getting all the products from order object


foreach($order->getAllVisibleItems() as $value) {
  echo $value->getName();
  echo $value->getSku();
  echo $value->getPrice();
  echo $value->getQtyOrdered();
}

To print all the order details use the below code,

print_r($order->debug(),true)
 

转载请注明:(●–●) Hello.My Weicot » Magento 通过订单号获取订单所有信息

文章来源于互联网:Magento 通过订单号获取订单所有信息

如无特殊说明或标注,任何个人或组织,复制、转载、采集本站内容请注明:
本文来源于:【Magento中文网】,并添加本文地址链接。
如未按上述操作复制或转载,本站有权追究法律责任。
若本站内容侵犯了原著者的合法权益,可联系我们进行处理。