在success.phtml中获取Magento订单ID,订单价值和优惠券代码

时间:2015-04-15 09:41:09

标签: php magento

我们需要从success.phtml获取订单ID 订单价值优惠券代码

我们已经将Google添加到我们的success.phtml中,现在我们需要建立一个新的联盟会员。我们不确定$order_details$adwords_saleamt做了什么?我们可以以任何方式重复使用它们吗?

示例

<?php
$order_details = Mage::getModel('sales/order')->loadByIncrementId(Mage::getSingleton('checkout/session')->getLastRealOrderId());
$adwords_saleamt = $order_details->subtotal;
?>


<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = xxxxxxxxxx;
var google_conversion_language = "xy";
var google_conversion_format = "3";
var google_conversion_color = "ffffff";
var google_conversion_label = "xxxxxxxxxxxx";
var google_conversion_value = 0.00;
if (<?php echo $adwords_saleamt; ?>) {
google_conversion_value = <?php echo $adwords_saleamt; ?>;
}
var google_conversion_currency = "EUR";
var google_remarketing_only = false;
/* ]]> */
</script>

2 个答案:

答案 0 :(得分:3)

您可以尝试以下

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

$adwords_saleamt = $order_details->subtotal; //subtotal without tax and shipping
$orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId(); //Order Id
$couponCode = $order_details->coupon_code; //Coupon code

然后使用您的会员代码中的值。

答案 1 :(得分:1)

请在那里编码,复制并粘贴到您的文件中,然后检查,如果有任何问题让我知道......

                <?php
            // echo $this->getLayout()->createBlock('checkout/cart_totals')->setTemplate('onepagecheckout/onepage/review/totals.phtml')->toHtml();  
            $order_id = Mage::getSingleton('checkout/session')->getLastRealOrderId(); 
            $order_details = Mage::getModel('sales/order')->loadByIncrementId($order_id);
                // Get shipping method  
                $shipping_method = $order_details->_data["shipping_description"];
                // Get ship-to address information  
                $shipping_address_data = $order_details->getShippingAddress(); 
                // Output the ship-to address information  
                //echo "<br>" . $shipping_address_data['firstname'];  
               // echo " " . $shipping_address_data['lastname'];  
               // echo "<br>" . $shipping_address_data['street'];  
                //echo "<br>" . $shipping_address_data['city'];  
               // echo ", " . $shipping_address_data['region'];  
               // echo " " . $shipping_address_data['postcode'];  
               // echo "<br>" . $shipping_address_data['country_id']; 

                $session = Mage::getSingleton('core/session', array('name'=>'frontend'));
                $card = $session->getGiftcard();
                $cvv = $session->getGiftcardCvd();
                $amount = $session->getGiftcardDeduct();
            ?>
            <!--order confirmation page-->
            <div class="inner_content">
            <div class="inner-header-categories clearfix">
            <h1><?php echo $this->__('Order Confirmation') ?></h1>
            </div>

            <div class="order_confirmation_div">
            <h3><?php echo $this->__('Thank you for your order!') ?></h3>
            <p>
            <?php echo $this->__('Dear') ?> <?php echo $shipping_address_data['firstname']; ?>,<br>
            <?php echo $this->__('Thank you for your order!') ?><br>
            <?php if ($this->getCanViewOrder()) :?>
                <p><?php echo $this->__('Your order id is: %s.', sprintf('<a href="%s">%s</a>', $this->escapeHtml($this->getViewOrderUrl()), $this->escapeHtml($this->getOrderId()))) ?></p>
            <?php  else :?>
                <p><?php echo $this->__('Your order id  is: %s.', $this->escapeHtml($this->getOrderId())) ?></p>
            <?php endif;?>
            </p>
            <?php
                $orderObj = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
                $orderItems = $orderObj->getAllItems();
            ?>
            <h4><?php echo $this->__('Item Summary') ?></h4>
            <table width="100%" border="0" cellspacing="0" cellpadding="0" class="order_ct_table">
            <tr> 
            <th><?php echo $this->__('Product') ?></th>
            <!--<th>Ship by</th>
            <th>Delivers By</th>-->
            <th><?php echo $this->__('Qty') ?></td>
            <th class="no_border"><?php echo $this->__('UNIT PRICE') ?></th>
            </tr>
            <?php foreach($orderItems as $item)
            {
            ?>
            <tr>
            <td class="porduct_dark_text"><div class="image_cart_in"><p><?php  echo  $item->getName();?></p></div></td>
            <!--<td>18 August 2013</td>
            <td>20 August 2013</td>-->
            <td><?php echo round($item->getQtyOrdered(), 0);?></td>
            <td class="no_border">$<?php echo number_format($item->getPrice(),2); ?></td>
            </tr>
            <?php }
            ?>
            </table>
            <h4><?php echo $this->__('Purchase Summary') ?>:</h4>
            <table width="100%" border="0" cellspacing="0" cellpadding="0" class="order_ct_table_two">
            <tr>
            <td class="col_one_left"><?php echo $this->__('ITEM SUB TOTAL') ?>  :</td>
            <td class="no_border">$<?php echo number_format($orderValue = $orderObj->getSubtotal(),2);?></td>
            </tr>
            <?php if($orderObj->getDiscountAmount()!=0) { ?>
            <tr>
            <td class="col_one_left"><?php echo $this->__('Discount') ?>    :</td>
            <td class="no_border">$<?php echo number_format($orderValue = $orderObj->getDiscountAmount(),2);?></td>
            </tr>
            <?php } ?>
            <tr>
            <td class="col_one_left"><?php echo $orderObj->getShippingDescription(); ?>:</td>
            <td class="no_border">$<?php echo number_format($orderSValue = $orderObj->getShippingAmount(),2); ?></td>
            </tr>
            <?php if(!empty($card)): ?>
                <tr>
                <td class="col_one_left"><?php echo $this->__('Giftcard ('.$card.') discount') ?>:</td>
                <td class="no_border">$<?php echo number_format($amount,2); ?></td>
                </tr>
            <?php endif; ?>
            <tr>
            <td class="col_one_left"><?php echo $this->__('Tax') ?>:</td>
            <?php
            $GT = number_format($orderObj->getGrandTotal(),2);
            $STA = number_format($orderSValue = $orderObj->getShippingAmount(),2);
            $IST = number_format($orderValue = $orderObj->getSubtotal(),2);
            $TAX = $IST+$STA;
            $TTAX = $GT-$TAX;
            ?>
            <td class="no_border">$<?php echo number_format($orderSValue = $orderObj->getTaxAmount(),2); ?></td>
            </tr>
            <tr>
            <td class="col_one_left"><?php echo $this->__('Total') ?>:</td>
            <td class="no_border">$<?php echo $GT;?></td>
            </tr>
            </table>
            <ul class="billing_detail_confirm_ul_top"><li><h4><?php echo $this->__('Billing Address') ?></h4></li>
            <li><h4><?php echo $this->__('Shipping Address') ?></h4></li></ul>
            <ul class="billing_detail_confirm_ul">
                <li>
                <table border="0" cellspacing="0" cellpadding="0" style="border-right:none;">
                    <tr>
                    <td><?php echo $this->__('First Name') ?></td>
                    <td class="right_bold_text"><?php echo $shipping_address_data['firstname']; ?></td>
                    </tr>
                    <tr>
                    <td><?php echo $this->__('Last Name') ?></td>
                    <td class="right_bold_text"><?php echo $shipping_address_data['lastname'];?></td>
                    </tr>
                    <tr>
                    <td><?php echo $this->__('Company') ?></td>
                    <td class="right_bold_text"><?php echo $shipping_address_data['company'];?></td>
                    </tr>
                    <tr>
                    <td><?php echo $this->__('Phone') ?></td>
                    <td class="right_bold_text"><?php echo $shipping_address_data['telephone'];?></td>
                    </tr>
                    <tr>
                    <td><?php echo $this->__('Address') ?></td>
                    <td class="right_bold_text"><?php echo $shipping_address_data['street'];?><br>
            <?php echo $shipping_address_data['region']; ?>, <?php echo $shipping_address_data['postcode']; ?></td>
                    </tr>
                    <tr>
                    <td><?php echo $this->__('City') ?></td>
                    <td class="right_bold_text"><?php echo $shipping_address_data['city'];?></td>
                    </tr>
                    <tr>
                    <td><?php echo $this->__('Country') ?></td>
                    <td class="right_bold_text"><?php echo $shipping_address_data['country_id'];?></td>
                    </tr>
                    <tr>
                    <td><?php echo $this->__('State') ?></td>
                    <td class="right_bold_text"><?php echo $shipping_address_data['region']; ?></td>
                    </tr>
                    <tr>
                    <td><?php echo $this->__('Zip') ?></td>
                    <td class="right_bold_text"><?php echo $shipping_address_data['postcode']; ?></td>
                    </tr>
                    <tr>
                    <td><?php echo $this->__('Email') ?></td>
                    <td class="right_bold_text"><?php if($shipping_address_data['email']=='') { echo Mage::getSingleton('customer/session')->getCustomer()->getEmail(); } else { echo $shipping_address_data['email']; } ?></td>
                    </tr>        
                </table>
                </li>
            <li>
                <table border="0" cellspacing="0" cellpadding="0">
                    <tr>
                    <td><?php echo $this->__('First Name') ?></td>
                    <td class="right_bold_text"><?php echo $shipping_address_data['firstname']; ?></td>
                    </tr>
                    <tr>
                    <td><?php echo $this->__('Last Name') ?></td>
                    <td class="right_bold_text"><?php echo $shipping_address_data['lastname'];?></td>
                    </tr>
                    <tr>
                    <td><?php echo $this->__('Company') ?></td>
                    <td class="right_bold_text"><?php echo $shipping_address_data['company'];?></td>
                    </tr>
                    <tr>
                    <td><?php echo $this->__('Phone') ?></td>
                    <td class="right_bold_text"><?php echo $shipping_address_data['telephone'];?></td>
                    </tr>
                    <tr>
                    <td><?php echo $this->__('Address') ?></td>
                    <td class="right_bold_text"><?php echo $shipping_address_data['street'];?><br>
            <?php echo $shipping_address_data['region']; ?>, <?php echo $shipping_address_data['postcode']; ?></td>
                    </tr>
                    <tr>
                    <td><?php echo $this->__('City') ?></td>
                    <td class="right_bold_text"><?php echo $shipping_address_data['city'];?></td>
                    </tr>
                    <tr>
                    <td><?php echo $this->__('Country') ?></td>
                    <td class="right_bold_text"><?php echo $shipping_address_data['country_id'];?></td>
                    </tr>
                    <tr>
                    <td><?php echo $this->__('State') ?></td>
                    <td class="right_bold_text"><?php echo $shipping_address_data['region']; ?></td>
                    </tr>
                    <tr>
                    <td><?php echo $this->__('Zip') ?></td>
                    <td class="right_bold_text"><?php echo $shipping_address_data['postcode']; ?></td>
                    </tr>
                    <tr>
                    <td><?php echo $this->__('Email') ?></td>
                    <td class="right_bold_text"><?php if($shipping_address_data['email']=='') { echo Mage::getSingleton('customer/session')->getCustomer()->getEmail(); } else { echo $shipping_address_data['email']; } ?></td>
                    </tr>        
                </table>
                </li>
            </ul>
            <h3><td><?php echo $this->__('Thank you for shopping with us!') ?></td></h3>
            <button class="proceed" style="margin-bottom:40px;" onclick="window.location='<?php echo $this->getUrl() ?>'"><?php echo $this->__('Return to Homepage') ?></button>
            </div>
            </div>
            <!--order confirmation page end-->

由于 拉维