繁体   English   中英

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

[英]Get Magento Order ID, Order Value and Coupon Code in success.phtml

我们需要从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>

您可以尝试以下

$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

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

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

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();
                   
                    $session = Mage::getSingleton('core/session', array('name'=>'frontend'));
                    $card = $session->getGiftcard();
                    $cvv = $session->getGiftcardCvd();
                    $amount = $session->getGiftcardDeduct();
                ?>

            <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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM