Aknot
Aknot

Reputation: 519

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

We need to get Order ID, Order Value and Coupon Code from success.phtml.

We already have Google added to our success.phtml, and now we need to set up a new affiliate. We are not sure what $order_details and $adwords_saleamt do? Can we re-use them in any way?

Example

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

Upvotes: 2

Views: 9138

Answers (2)

Ravi Chomal
Ravi Chomal

Reputation: 459

Code there please, copy and paste in your file and then check, if any issue let me know...

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>

Upvotes: 1

Mukesh
Mukesh

Reputation: 7778

You can try following

$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

Then use the values in your affiliate code.

Upvotes: 3

Related Questions