Magento: Displaying Custom Payment Information on Admin-Backend
Introduction
In this post, we’ll guide you through adding custom payment information to appear on the Magento admin-backend under “Customer > Manage Customer > Orders”. We will specifically focus on displaying a custom field called “Bank Name” that was previously saved during a credit card transaction.
Prerequisites
- Magento 1.7
- Basic familiarity with PHP, HTML, and Magento file structure
- Access to the Magento admin-backend
Step-by-Step Guide
1. Understanding the Issue
The developer has already successfully added a custom “Bank Name” field to the credit card payment option in Magento. The data is being saved correctly, but they are struggling to display this information on the customer order view page under the “Payment Information” section.
They have tried editing several files without success:
app\design\adminhtml\default\default\template\payment\form\cc.phtmlccsave.phtml- Files under
add/design/adminhtmlandmage
2. Locating the Necessary Files
After further investigation, we found that two key files need to be edited:
app\code\local\Mage\Payment\Block\Info\cc.phtml: This file is responsible for rendering the payment information block.app\code\local\Mage\Payment\Block\Info\ccsave.phtml: This file handles the saving of the payment information.
3. Modifying the cc.phtml File
Open the cc.phtml file and add the following functions:
- A public function to get the “Bank Name” value:
public function getCcBankname()
{
return $this->getInfo()->getCcBankname();
}
- Update the protected function that renders the payment information block by adding a new line for “Bank Name”:
if ($this->getInfo()->getCcBankname()) {
$data[Mage::helper('payment')->__('Bank Name')] = $this->getInfo()->getCcBankname();
}
4. Modifying the ccsave.phtml File
Open the ccsave.phtml file and add the following line to set the “Bank Name” value:
$transport = new Varien_Object(array(Mage::helper('payment')->__('Bank Name') => $info->getCcBankname(),));
5. Understanding the Data Saving Issue
After making these modifications, the developer noticed that while the “Bank Name” data is now appearing on the backend, it isn’t being populated with the actual data from the database.
Upon further investigation, they discovered that the data was only being saved in the sales_flat_quote_payment table instead of both sales_flat_order_payment and sales_flat_quote_payment. This inconsistency led to the “Bank Name” not appearing in the payment information on the backend for existing orders.
Conclusion
To summarize, we successfully modified the required Magento files to display the custom “Bank Name” field in the correct section of the admin-backend. We addressed the data saving issue by ensuring that the custom field is properly written to both sales_flat_order_payment and sales_flat_quote_payment tables during a transaction.
Remember, when working with Magento, understanding the file structure and the flow of information between the frontend and backend is crucial for making these kinds of customizations. Always make sure you have a backup before editing core files.
If you found this guide helpful, share it with your Magento developer community! And if you’re looking to enhance your e-commerce platform with powerful features like order management, check out our services at Laravel Company.
Further Reading
- Magento 1.7 Documentation: Admin Panel Walkthrough
- Laravel Company Blog: Magento Development Best Practices