将自定义字段添加到Magento中已保存的信用卡付款方式中


Add custom field to Saved Credit Card payment method in Magento

我需要在Magento中保存的信用卡支付方法中添加一个名为"parcelas"的自定义字段,它将是一个带有1到x个选项的选择。我一直在寻找如何做到这一点,但我真的没有找到从表单中获取数据、存储到数据库并在后台获取数据的方法。有人知道怎么做吗?

经过一些研究,我找到了我需要的东西。此方法适用于Magento 1.7.0.2。

1-创建Ccsave模块的本地副本。

2-添加到app/code/local/Mage/Ccsave/etc/config.xml中,位于*config->global->fieldsets->sales_overt_quote_payment*之间

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

和*config->global->fieldsets->sales_overt_order_payment*

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

3-在app/code/local/Mage/Ccsave/Block/Payment/Info/Ccsave.php中,将此代码添加到函数*_prepareSpecificInformation*

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

4-在app/code/local/Mage/Ccsave/Model/Payment/Info.php中,将此代码添加到函数getData

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

5-在ul结束之前,将输入字段添加到app/design/frontend/YOURTHEME/default/template/payment/form/ccsave.phtml中的表单中

<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>

在步骤5中,我从另一个模块调用了我想要的"parcela"数量。如果你有一个"parcelas"的静态数字,你可以找到自己的方法,只需将$this->getParcelas()->getParcelas()更改为你想要的数字。

6-在表sales_flat_order_payment和sales_flat_quote_payment 上向数据库添加"cc_parcelas"列

现在,您可以在Ccsave模块上获取"parcelas"的数量,或者只添加另一种自定义字段。请告诉我在这个过程中是否有什么问题或工作不好。

使用安装脚本

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