2

I need to generate invoice pdf in checkout page. Payment method Bank Transfer for Indian Customer. Any Idea about it?

Success page:- /app/design/frontend/themes/default/template/checkout/success.phtml:-

<div >
<h1><?php #echo $this->__('Your order will be delivered over email shortly.') ?></h1>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('success_page')->toHtml() ?></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() ?>
    <a href="<?php echo $this->getUrl('invoice/index/print', array('invoice_id' => $_invoice->getId())); ?>">Download Pdf</a>
</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;?><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> 
2
  • Do you mean after order placed? Aug 6, 2018 at 7:25
  • Yes, After order placed using bank payment. Aug 6, 2018 at 7:27

1 Answer 1

2

You need to create observer on order placed and then need to put one condition for your payment method and create the invoice accordingly through code.

Please see the below link which does exactly the same which you want. You only need to get invoice pdf.

https://www.atwix.com/magento/auto-invoice-and-custom-order-status-upon-checkout/

Updated for PDF generation:

Update you config.xml like below:

app/code/community/Atwix/Orderhook/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Atwix_Orderhook>
            <version>1.0</version>
        </Atwix_Orderhook>
    </modules>
    <!-- Added by Sukumar -->
    <frontend>
       <routers>
          <invoice_print>
              <use>standard</use>
              <args>
                 <module>Atwix_Orderhook</module>
                 <frontName>invoice</frontName>
              </args>
           </invoice_print>
       </routers>
    </frontend>
    <!-- Added by Sukumar -->
    <global>
        <models>            
            <orderhook>
                <class>Atwix_Orderhook_Model</class>
            </orderhook>
        </models>
        <events>
            <sales_order_place_after>
                <observers>
                    <auto_invoice_order>
                        <type>singleton</type>
                        <class>Atwix_Orderhook_Model_Observer</class>
                        <method>implementOrderStatus</method>
                    </auto_invoice_order>
                </observers>
            </sales_order_place_after>
        </events>
    </global>
</config>

Create IndexController.php at below path:

app/code/community/Atwix/Orderhook/controllers/IndexController.php

<?php
class Atwix_Orderhook_IndexController extends Mage_Core_Controller_Front_Action
{
  public function printAction()
    {
        if ($invoiceId = $this->getRequest()->getParam('invoice_id')) {
            if ($invoice = Mage::getModel('sales/order_invoice')->load($invoiceId)) {
                $pdf = Mage::getModel('sales/order_pdf_invoice')->getPdf(array($invoice));
            $this->_prepareDownloadResponse('invoice'.Mage::getSingleton('core/date')->date('Y-m-d_H-i-s').
                '.pdf', $pdf->render(), 'application/pdf');
            }
        }
        else {
            $this->_forward('noRoute');
        }
    }
}

And add the below code for download PDF whereever you want:

<a href="<?php echo $this->getUrl('invoice/index/print', array('invoice_id' => $_invoice->getId())); ?>">Download Pdf</a>

Put the below code to your success.phtml

<?php $order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId()); ?>
<?php $invoiceCollection = $order->getInvoiceCollection(); ?>
<?php foreach($invoiceCollection as $invoice): ?>
    <a href="<?php echo $this->getUrl('invoice/index/print', array('invoice_id' => $invoice->getId())); ?>">Download Pdf</a>
<?php endforeach; ?>
17
  • I tried above link. Get Invoice Mail. But, I Need Invoice PDF Generate button in Checkout page( Order Review). Aug 6, 2018 at 10:02
  • Check my updated answer. Aug 6, 2018 at 11:07
  • <a href="<?php echo $this->getUrl('invoice/index/print', array('invoice_id' => $_invoice->getId())); ?>">Download Pdf</a> I tried place the button Download Pdf button In Success page . There not visible download option button. Aug 6, 2018 at 13:28
  • Can you post you success page phtml content here in you question? Aug 6, 2018 at 13:29
  • I Posed My Success page Code. Aug 6, 2018 at 13:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.