Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Modify Pruchase Order Payment Module
 
kiatng
Enthusiast
 
Total Posts:  875
Joined:  2008-09-03
Kuala Lumpur, Malaysia
 

I’m trying to add a Reference Number field just like the Purchase Order Number but I can’t figure out how to retrieve the number from the checkout page.  I created a BankTransfer module with some bank information and added a Reference Number field in the template form.phtml (similarly info.phtml):

<fieldset class="form-list">
    <
ul id="payment_form_<?php echo $this->getMethodCode(); ?>" style="display:none">
        <
li>
            <
div class="input-box">
                
<?php echo $this->__('Use these details for internet banking, direct deposit, or telegraphic transfer as payment.'); ?>
                
<br /><br />
                
<?php if ($this->getMethod()->getDetails1()): ?>
                    <?php 
echo $this->getMethod()->getDetails1(); ?><br />
                
<?php endif; ?>
                
<br />
                
<?php if ($this->getMethod()->getDetails2()): ?>
                    <?php 
echo $this->getMethod()->getDetails2(); ?><br />
                
<?php endif; ?>
                
<br />
                <
label for="ref_number"><?php echo $this->__('Reference Number'?></label><br />
                <
input type="text" id="ref_number" name="payment[ref_number]" title="<?php echo $this->__("Payment Method Reference Number") ?>" class="input-text" value="<?php echo $this->htmlEscape($this->getInfoData('ref_number')) ?>"/>
            </
div>
        </
li>
    </
ul>
</
fieldset>

And the code for the BankTransferMethod under Model:

<?php
class Cele_BankTransfer_Model_BankTransferMethod extends Mage_Payment_Model_Method_Abstract
{
    
protected $_code 'banktransfer';
    protected 
$_formBlockType 'banktransfer/form';
    protected 
$_infoBlockType 'banktransfer/info';

    public function 
getDetails1()
    
{
        
//return $this->getConfigData('details1');
        
return nl2br($this->getConfigData('details1'));
    
}
    
    
public function getDetails2()
    
{
        
return nl2br($this->getConfigData('details2'));
    
}
    
    
public function assignData($data)
    
{
        
if (!($data instanceof Varien_Object)) {
            $data 
= new Varien_Object($data);
        
}
        $info 
$this->getInfoInstance();
        
$info->setRefNumber($data->getRefNumber());
        
//$this->getInfoInstance()->setPoNumber($data->getPoNumber()); (this statement from Purchase Order Module will work)
        
return $this;
    
}

}
?>

I know very very little PHP and I could not figure out how the setPoNumber and getPoNumber work. However, if I replace all instances of refNumber and ref_number with PoNumber and po_number in the template (both front and backend), I can retrieve the number and get it to show in the backend order page.  I know I’m missing something, but I do not know what.

I found an entry po_number in the database under the table eav_attribute, so I duplicate this for ref_number but it doesn’t help. 

Can anyone tell me what I’m missing?

 
Magento Community Magento Community
Magento Community
Magento Community
 
freshwebs
Sr. Member
 
Total Posts:  153
Joined:  2008-05-27
Leicestershire, UK
 

Hi,
Any progress to report on this?
Thanks,
Eddie

 
Magento Community Magento Community
Magento Community
Magento Community
 
kiatng
Enthusiast
 
Total Posts:  875
Joined:  2008-09-03
Kuala Lumpur, Malaysia
 

In that project, I just reused the po_number attribute and it works. So, I leave it as that. But if you need to add more input fields to your custom payment method, you can follow the instructions provided here:

- http://www.magentocommerce.com/wiki/doc/installing_custom_attributes_with_your_module
- http://www.magentocommerce.com/wiki/how-to/customize_part_of_configuration
- http://www.magentocommerce.com/wiki/how_to_overload_a_controller
- http://www.magentocommerce.com/boards/viewthread/19344/

Also, one thing that I learned is the getter and setter methods of Varien Objects. I think all objects in Magento are descendants of this. Getter and setter means that you can set and get the properties (we call them attributes in Magento) of an object without defining the methods. You use camelcase to construct the getter and setter. As an example, for the ref_number attribute, we’ll first have to add it to the database, the files involved are etc/config.xml to define the DB connection, version, DB setup module and the attribute setup module such as sql/setup.php to instruct Magento to add the attribute to the DB. Once that is done, we can use setter and getter like these:

$this->setRefNumber('$_value')->save(); //$_value is some value
$_value $this->getRefNumber();

That was the thing I didn’t understand before and got stuck on.

 
Magento Community Magento Community
Magento Community
Magento Community
 
freshwebs
Sr. Member
 
Total Posts:  153
Joined:  2008-05-27
Leicestershire, UK
 

Hi,
Thank you for such a detailed and useful response - the bit about needing to add the attribute to the database is gold dust!

I will try this and let you know how I get on.

Cheers,
Eddie

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top