1

I have created custom payment module in Magento for emi options.

But the issue is that when person place order, then in the invoice I can only see the payment method they used for place order, But cannot see emi option they have selected.

For example: this time it is showing me

Payment method:
xyz payment

But I also want add addition selected option like that:

Payment method
xyz payment
3 month emi

So, Please guide how can I use this in my payment module

2 Answers 2

2

In payment, to show extra information you will use the info block.

Step1:

Assign the info block in your custom payment model file

protected $_infoBlockType = 'payment/info_[custom_payment_name]';

Step 2:

Need to set emi options in $this->getInfoInstance(). Please refer the Mage_Payment_Model_Method_Purchaseorder file and function name assignData()

$this->getInfoInstance()->setAdditionalData([get emi option value]);

for ex:

$details['emi'] = 'xxxx';
$this->getInfoInstance()->setAdditionalData(serialize($details));

Step 3:

In Block folder create the payment info file extends info block, assign the payment info template file. Please refer default payment file(Purchaseorder), function name _construct() and add the additional data conversion refer below

protected function _construct()
{
    parent::_construct();
    $this->setTemplate('payment/info/[custompayment].phtml');
}

protected $_emi;

public function getEmi()
{
     if (is_null($this->_emi)) {
        $this->_convertAdditionalData();
     }
     return $this->_emi;
}

protected function _convertAdditionalData()
{
    $this->_emi = '';

    $details = @unserialize($this->getInfo()->getAdditionalData());        
    if (is_array($details)) {
         $this->_emi = isset($details['emi']) ? (string) $details['emi'] : '';
    }
    return $this;
}

Step 4:

Create phtml file design folder under current theme, app/design/fronted/[package]/[theme]/template/payment/info/[custom_payment_name].phtml

<?php  
echo ( if($this->getEmi()) ? $this->getEmi() : '');  
?>

Please check additional_data field in sales_flat_order_payment table for that last order, you can find the data details added.

Try this. Hope this help you

11
  • I have created Block/Info/Pay.php file, And created Class Class Namespace_Module_Block_Info_Pay { } So Please tell me if it is need to extend this class, then with which class I can extend this new which I have created
    – gopising
    Dec 1, 2014 at 9:50
  • You have to extend Mage_Payment_Block_Info class and assign the template file in constructor, you going to create in design template file. (Refer purchaseorder.php you will get idea)
    – Venkat
    Dec 1, 2014 at 9:56
  • If you used payment/info_pay then you have to create Pay.php file in Block folder, assign template file in constructor and create pay.phtml in current theme template folder, so your file path as app/design/frontend/[package]/[theme]/template/payment/info/pay.phtml
    – Venkat
    Dec 1, 2014 at 10:26
  • I did exactly as you mentioned. But it is returning nothing.. Blank
    – gopising
    Dec 1, 2014 at 10:30
  • Could you please share the code
    – Venkat
    Dec 1, 2014 at 10:32
0

@venkat, I have used this code in module

Namespace/Module/Model/Standard.php

class Namespace_Module_Model_Standard extends Mage_Payment_Model_Method_Abstract {

    protected $_infoBlockType = 'ebsemi/info_pay';

        public function assignData($data)
        {
            if (!($data instanceof Varien_Object)) {
                $data = new Varien_Object($data);
            }
        $this->getInfoInstance()->setEmi($data->getEmi());
        return $this;
        }
    }

Namespace/Module/Block/Info/Pay.php

class Namespace_Module_Block_Info_Pay extends Mage_Payment_Block_Info{

    protected function _construct()
    {
            parent::_construct();
        $this->setTemplate('payment/info/pay.phtml');
    }
}

app/design/fronted/[package]/[theme]/template/payment/info/pay.phtml

<?php  
echo ( if($this->getInfo()->getEmi()) ? ($this->getInfo()->getEmi()) : '');  
?>
6
  • I figure out issues in the above code. Please refer this link and update the latest code once you modified.
    – Venkat
    Dec 1, 2014 at 11:45
  • My code is as written as guided in this link you have shared. But still returning nothing..
    – gopising
    Dec 1, 2014 at 12:54
  • Please refer my code edited, additional data added in that. Please check and let me know
    – Venkat
    Dec 1, 2014 at 13:18
  • @Venkat, That worked thanks buddy. It not saved to database, So it could be added to invoice
    – gopising
    Dec 1, 2014 at 13:39
  • You checked additional_data in sales_flat_order_payment table for that last order id ?. Surely it have the data in the table.
    – Venkat
    Dec 1, 2014 at 13:49

Your Answer

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

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