//第一步:通过定单号获得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 '您已登录,正为您跳转..<br>'; echo 'redirect to '.$dv_url; echo '<script type="text/javascript">location.href="'.$dv_url.'";</script>'; } $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)