简体   繁体   中英

Add custom field to Saved Credit Card payment method in Magento

I need to add a custom field to the saved credit card payment method in Magento called 'parcelas', it will be one select with 1 to x options. I've been searching how to do this but I really didn't found some way to get the data from the form, store into database and get it in the backend. Does anyone knows how to do so?

After some research I've found what I needed. This method works with Magento 1.7.0.2.

1 - Create a local copy of Ccsave module.

2 - Add into app/code/local/Mage/Ccsave/etc/config.xml, between *config -> global -> fieldsets -> sales_convert_quote_payment*

<cc_parcelas><to_order_payment>*</to_order_payment></cc_parcelas>

And to *config -> global -> fieldsets -> sales_convert_order_payment*

<cc_parcelas><to_quote_payment>*</to_quote_payment></cc_parcelas>

3 - In app/code/local/Mage/Ccsave/Block/Payment/Info/Ccsave.php, add this code to function *_prepareSpecificInformation*

if ($info->getCcParcelas()) {
    $transport->addData(array(
     Mage::helper('payment')->__('Número de Parcelas') => $info->getCcParcelas(),
    ));
}

4 - In app/code/local/Mage/Ccsave/Model/Payment/Info.php, add this code to function getData

$this->_data['cc_parcelas'] = $this->getCcParcelas();

5 - Add the input field to form in app/design/frontend/YOURTHEME/default/template/payment/form/ccsave.phtml just before ul end

<li>
    <label for="<?php echo $_code ?>_cc_parcelas" class="required"><em>*</em>Número de Parcelas</label>
    <div class="input-box">
        <div class="v-fix">
            <select title="Número de Parcelas" class="input-text cvv required-entry validate-cc-cvn" id="<?php echo $_code ?>_cc_parcelas" name="payment[cc_parcelas]">
                <?php for($i=1; $i<=$this->getParcelas()->getParcelas(); $i++): ?>
                    <option value="<?php echo $i; ?>"><?php echo $i; ?></option>
                <?php endfor; ?>
            </select>
        </div>
    </div>
</li>

In step 5 I've called from another module how many 'parcelas' I want. You may find your own way to do it, if you have a static number of 'parcelas' just change $this->getParcelas()->getParcelas() to the number you want.

6 - Add a 'cc_parcelas' column to your database on tables sales_flat_order_payment and sales_flat_quote_payment

Now you may be able to get the number of 'parcelas' on your Ccsave module or just add another kind of custom field. Please let me know if there's anything wrong or not working well in this process.

Use an Install script

$installer = new Mage_Sales_Model_Mysql4_Setup('core_setup');
$installer->startSetup();
$installer->addAttribute(
    'order_payment',
    'cc_parcelas',
    array(
        'type' => 'varchar',
        'grid' => true
    )
);
$installer->endSetup();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM