magento根据订单号(order_id)获取详细订单信息
时间:2016-01-16 17:46来源: 作者: 点击:次
实现magento根据订单号(order_id)获取详细订单信息的代码:style type=text/css.orderStatusTable {border:1px solid #CCCCCC;font-size:11px;}.orderStatusTable td {padding:8px;}.currentStatus {font-size: 11px;background-color: #e
实现magento根据订单号(order_id)获取详细订单信息的代码:
<style type="text/css">
.orderStatusTable {
border:1px solid #CCCCCC;
font-size:11px;
}
.orderStatusTable td {
padding:8px;
}
.currentStatus {
font-size: 11px;
background-color: #eee;
padding: 10px;
margin: 0 0 15px 0;
line-height: 15px;
border: 1px solid #ccc;
color: #333;
}
.currentStatus span {
font-size: 14px;
line-height: 23px;
color: #000;
}
.alert{
color: #E10707;
}
.tablewarp {
clear: both;
width: 900px;
line-height: 180%;
}
</style>
<script type="text/javascript">
function test() {
var s1 = document.getElementById("order_id").value;
var s3=s1.split('-');
var s4=s3[1];
//WidthCheck(s4,3);
//var s5=strlen(s4);
//alert(s4);
if (s1 == "") {
alert("请输入您的订单号码");
return false;
}
else if(s1.length<12)
{
alert("请输入正确的订单号");
return false;
}
else if(s4=='' || s4.length!=3 || !isNaN(s4))
{
alert("请输入正确的订单号");
//jQuery("#s4").html(s4);
return false;
}
}
function strlen(str){
var len = 0;
for (var i=0; i<str.length; i++) {
var c = str.charCodeAt(i);
//单字节加1
if ((c >= 0x0001 && c <= 0x007e) || (0xff60<=c && c<=0xff9f)) {
len++;
}
else {
len+=2;
}
}
return len;
}
function WidthCheck(s, n){
var w = 0;
for (var i=0; i<s.length; i++) {
var c = s.charCodeAt(i);
//单字节加1
if ((c >= 0x0001 && c <= 0x007e) || (0xff60<=c && c<=0xff9f)) {
w++;
}
else {
w+=2;
}
}
if (w < n) {
alert("请输入正确的订单号");
return false;
}
return true;
}
</script>
<div>
</div>
<?php
if(empty($_GET['email_address'])||empty($_GET['order_id'])){
echo "<h1 class = 'alert'><p>请输入您的订单号码查看订单状态!</p></h1>";
}
?>
<?php if(empty($_GET['order_id'])): ?>
<form name="" action="" method="get" onsubmit="return test()">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td><strong>订单号:</strong></td>
<td><input type="text" name="order_id" id="order_id" value="<?php echo (isset($_GET['order_id'])) ? $_GET['order_id'] : ''; ?>" /></td>
<td>* 必填</td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="submit" value="Submit" /></td>
</tr>
</table>
</form>
<div></div>
<?php endif; ?>
<?php
require_once 'app/Mage.php';
Mage::app('default');
if(isset($_REQUEST['order_id'])) {
//echo "true";
$incrementID =$_REQUEST['order_id'];
$incrementID=explode('-',$incrementID);
$incrementID=$incrementID[0];
$orders = Mage::getModel('sales/order')->getCollection();
//print_r($orders);
$orders->addAttributeToFilter('increment_id', $incrementID); //其中 $incrementID为订单号
$orders->addAttributeToSelect('*');
$orders->load();
$alldata = $orders->getData();
//print_r($alldata);die();
$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().'<br/>';
//支付方式
$order = Mage::getModel ( 'sales/order' )->loadByIncrementId ($incrementID);
'支付方式'.$pay=Mage::helper('payment')->getInfoBlock($order->getPayment())->toHtml().'<br/>';
//订单状态
'订单状态'.$status = $sales_order->getStatus().'<br/>';
$state = $sales_order->getState().'<br/>';
$Email=$sales_order->getData('customer_email'); //客户的邮件
foreach ($sales_order->getAllItems() as $item) {
$option = $item->getProductOptions();
//print_r($option );
//die;
$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 = "";
}
'产品:'.$name = $item->getName().'<br/>'; //获取订单产品名
'价格'.$price = $item->getPrice().'<br/>';
'Address'.$address= $item->getShippingAddress().'<br/>';
$sku= $item->getSku();
}
$FirstName=$billingAddress->getFirstname();
$LastName=$billingAddress->getLastname();
$Email=$sales_order->getData('customer_email');
$Phone=$billingAddress->getTelephone();
$ZipCode=$billingAddress->getPostcode();
$company=$billingAddress->getCompany();
$Address=$billingAddress->getStreetFull();
$City=$billingAddress->getCity();
$State=$billingAddress->getRegion();
$Country=$billingAddress->getCountry();
$adress_info .= $Email."<br/>".$FirstName."<br/>".$LastName."<br/>".$company."<br/>".$Address."<br/>".$City."<br/>".$State."
<br/>".$ZipCode."<br/>".$Country."~".$Phone;
$adress_info.'<br/>';
echo '<a href="http://www.123.com/repay/order/id/'.$dv_oid.' " style="color:red">重新支付</a>';
}
?>
(责任编辑:好模板) |
------分隔线----------------------------