I am trying to modify the success checkout page on magento
to add a javascript
snippet for tracking revenue. I have created my own plugin and I have been following this blogpost but whenever I do a successful checkout I get an empty page which doesn't load my custom success.phtml
file. I am attaching a screenshot for more details.
config.xml(app/code/local/ArchitVerma/MyModule/etc/config.xml
):
<?xml version="1.0"?>
<config>
<modules>
<ArchitVerma_MyModule>
<version>1.0.1</version>
</ArchitVerma_MyModule>
</modules>
<frontend>
<routers>
<mymodule>
<use>standard</use>
<args>
<module>ArchitVerma_MyModule</module>
<frontName>mymodule</frontName>
</args>
</mymodule>
</routers>
<layout>
<updates>
<mymodule>
<file>mymodule.xml</file>
</mymodule>
</updates>
</layout>
</frontend>
<global>
<blocks>
<mymodule>
<class>ArchitVerma_MyModule_Block</class>
</mymodule>
<checkout>
<rewrite>
<onepage_success>ArchitVerma_MyModule_Block_Onepage_Success</onepage_success>
</rewrite>
</checkout>
</blocks>
</global>
</config>
mymodule.xml(app/design/frontend/base/default/layout/mymodule.xml
):
<?xml version="1.0"?>
<layout version="0.1.0">
<checkout_onepage_success translate="label">
<label>One Page Checkout Success</label>
<reference name="root">
<action method="setTemplate"><template>page/2columns-right.phtml</template></action>
</reference>
<reference name="content">
<reference name="checkout.success">
<action method="setTemplate"><template>mymodule/success.phtml</template></action>
</reference>
</reference>
</checkout_onepage_success>
</layout>
success.phtml(app/design/frontend/base/default/template/mymodule/success.phtml
):
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE_AFL.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magento.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magento.com for more information.
*
* @category design
* @package base_default
* @copyright Copyright (c) 2006-2015 X.commerce, Inc. (http://www.magento.com)
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
*/
?>
<div class="page-title">
<h1><?php echo $this->__('Your order has been received.') ?></h1>
</div>
<?php echo $this->getMessagesBlock()->toHtml() ?>
<h2 class="sub-title"><?php echo $this->__('Thank you for your purchase!') ?></h2>
<?php if ($this->getOrderId()):?>
<?php if ($this->getCanViewOrder()) :?>
<p><?php echo $this->__('Your order # 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 # is: %s.', $this->escapeHtml($this->getOrderId())) ?></p>
<?php endif;?>
<p><?php echo $this->__('You will receive an order confirmation email with details of your order and a link to track its progress.') ?></p>
<?php if ($this->getCanViewOrder() && $this->getCanPrintOrder()) :?>
<p>
<?php echo $this->__('Click <a href="%s" onclick="this.target=\'_blank\'">here to print</a> a copy of your order confirmation.', $this->getPrintUrl()) ?>
<?php echo $this->getChildHtml() ?>
</p>
<?php endif;?>
<?php endif;?>
<?php if ($this->getAgreementRefId()): ?>
<p><?php echo $this->__('Your billing agreement # is: %s.', sprintf('<a href="%s">%s</a>', $this->escapeHtml($this->getAgreementUrl()), $this->escapeHtml($this->getAgreementRefId())))?></p>
<?php endif;?>
<?php if ($profiles = $this->getRecurringProfiles()):?>
<p><?php echo $this->__('Your recurring payment profiles:'); ?></p>
<ul class="disc">
<?php foreach($profiles as $profile):?>
<?php $profileIdHtml = ($this->getCanViewProfiles() ? sprintf('<a href="%s">%s</a>', $this->escapeHtml($this->getProfileUrl($profile)), $this->escapeHtml($this->getObjectData($profile, 'reference_id'))) : $this->escapeHtml($this->getObjectData($profile, 'reference_id')));?>
<li><?php echo $this->__('Payment profile # %s: "%s".', $profileIdHtml, $this->escapeHtml($this->getObjectData($profile, 'schedule_description')))?></li>
<?php endforeach;?>
</ul>
<?php endif;?>
<?php echo "<b>hello</b>"; ?>
<div class="buttons-set">
<button type="button" class="button" title="<?php echo $this->__('Continue Shopping') ?>" onclick="window.location='<?php echo $this->getUrl() ?>'"><span><span><?php echo $this->__('Continue Shopping') ?></span></span></button>
</div>
<script type="text/javascript">
var _vis_opt_revenue = <?php $order = Mage::getModel('sales/order')->loadByIncrementId($orderId); echo $order['base_grand_total'];?>;
window._vis_opt_queue = window._vis_opt_queue || [];
window._vis_opt_queue.push(function() {_vis_opt_revenue_conversion(_vis_opt_revenue);});
</script>
My module structure
- ArchitVerma
- MyModule
- Block
- Onepage
- Success.php
- etc
- config.xml
What am I missing here?
Best Answer
Replace your
app/design/frontend/base/default/layout/mymodule.xml
file with this code:Basically, when you are using
setTemplate
then no need to put it insidecontent
, you can just put it as standalone. However,<reference name=""
should match with the original magento name of that template file (check inside<checkout_onepage_success>
tag inlayout/checkout.xml
file).