Magento支付模块未显示在前端

时间:2012-11-08 20:43:50

标签: magento magento-1.7

我已经为magento开发了一个支付模块,但是我无法在商店的前端,结账区域显示它。

我的配置文件就像

一样松散
<?xml version="1.0"?>
<config>
    <modules>
        <Atlanticsoft_Pay>
            <version>0.1.0</version>
        </Atlanticsoft_Pay>
    </modules>
    <frontend>
        <routers>
            <pay>
                <use>standard</use>
                <args>
                    <module>Atlanticsoft_Pay</module>
                    <frontName>pay</frontName>
                </args>
            </pay>
        </routers>
        <layout>
            <updates>
                <pay>
                    <file>pay.xml</file>
                </pay>
            </updates>
        </layout>
    </frontend>
    <global>
        <fieldsets>
             <sales_convert_quote_payment>
                <check_no>
                    <to_order_payment>*</to_order_payment>
                </check_no>
                <check_date>
                    <to_order_payment>*</to_order_payment>
                </check_date>
             </sales_convert_quote_payment>
        </fieldsets>
        <models>
            <pay>
                <class>Atlanticsoft_Pay_Model</class>
                <resourceModel>pay_mysql4</resourceModel>
            </pay>
            <pay_mysql4>
                <class>Atlanticsoft_Pay_Model_Mysql4</class>
                <entities>
                    <pay>
                        <table>pay</table>
                    </pay>
                </entities>
            </pay_mysql4>
        </models>
        <resources>
            <pay_setup>
                <setup>
                    <module>Atlanticsoft_Pay</module>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </pay_setup>
            <pay_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </pay_write>
            <pay_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </pay_read>
        </resources>
        <blocks>
            <pay>
                <class>Atlanticsoft_Pay_Block</class>
            </pay>
        </blocks>
        <helpers>
            <pay>
                <class>Atlanticsoft_Pay_Helper</class>
            </pay>
        </helpers>
    </global>
    <default>
        <payment>
            <pay>
                <active>1</active>
                <model>pay/pay</model>
                <order_status>processing</order_status>
                <title>Atlanticsoft Payment Method</title>
                <message>Seleccionando esta opcion esta autorizando a la tienda a hacer cargos semanales a su tarjeta para el pago de los productos.</message>
            </pay>
         </payment>
    </default>
</config>

但是找不到问题,在管理区域一切正常: 这是我的system.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
   <sections>
        <payment>
            <groups>
                <pay translate="label" module="pay">
                    <label>Atlanticsoft Payment Module</label>
                    <sort_order>670</sort_order>
                    <show_in_default>1</show_in_default>
                    <show_in_website>1</show_in_website>
                    <show_in_store>1</show_in_store>
                    <fields>
                        <active translate="label">
                            <label>Enabled</label>
                            <frontend_type>select</frontend_type>
                            <source_model>adminhtml/system_config_source_yesno</source_model>
                            <sort_order>1</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>0</show_in_store>
                        </active>
                        <gateway_url translate="label">
                           <label>Gateway URL</label>
                           <frontend_type>text</frontend_type>
                           <sort_order>3</sort_order>
                           <show_in_default>1</show_in_default>
                           <show_in_website>1</show_in_website>
                           <show_in_store>0</show_in_store>
                       </gateway_url>
                        <api_username translate="label">
                            <label>Username de comercio</label>
                            <frontend_type>text</frontend_type>
                            <sort_order>3</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>0</show_in_store>
                        </api_username>
                        <api_password translate="label">
                            <label>Clave de comercio</label>
                            <frontend_type>text</frontend_type>
                            <sort_order>3</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>0</show_in_store>
                        </api_password>

                        <order_status translate="label">
                            <label>Order status</label>
                            <frontend_type>select</frontend_type>
                            <source_model>adminhtml/system_config_source_order_status_processing</source_model>
                            <sort_order>2</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>0</show_in_store>
                        </order_status>
                        <title translate="label">
                            <label>Title</label>
                            <frontend_type>text</frontend_type>
                            <sort_order>3</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>0</show_in_store>
                        </title>
                        <api_code translate="label">
                            <label>Codigo de comercio</label>
                            <frontend_type>text</frontend_type>
                            <sort_order>4</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                        </api_code>
                    </fields>
                </pay>
            </groups>
        </payment>
    </sections>
</config>

添加了Pay.php代码

class Atlanticsoft_Pay_Model_Pay extends Mage_Payment_Model_Method_Cc
{
    protected $_code = 'pay';
    protected $_formBlockType = 'pay/form_pay';
    protected $_infoBlockType = 'pay/info_pay';

    //protected $_isGateway               = true;
    protected $_canAuthorize            = false;
    protected $_canCapture              = false;
    //protected $_canCapturePartial       = true;
    protected $_canRefund               = false;


    protected $_canSaveCc = false; //if made try, the actual credit card number and cvv code are stored in database.

    //protected $_canRefundInvoicePartial = true;
    //protected $_canVoid                 = true;
    //protected $_canUseInternal          = true;
    protected $_canUseCheckout          = true;
    //protected $_canUseForMultishipping  = true;
    //protected $_canFetchTransactionInfo = true;
    //protected $_canReviewPayment        = true;


    public function process($data){

        if($data['cancel'] == 1){
         $order->getPayment()
         ->setTransactionId(null)
         ->setParentTransactionId(time())
         ->void();
         $message = 'Unable to process Payment';
         $order->registerCancellation($message)->save();
        }
    }

    public function processBeforeRefund($invoice, $payment){
        return parent::processBeforeRefund($invoice, $payment);
    }
    public function refund(Varien_Object $payment, $amount){
        $order = $payment->getOrder();
        $result = $this->callApi($payment,$amount,'refund');
        if($result === false) {
            $errorCode = 'Invalid Data';
            $errorMsg = $this->_getHelper()->__('Error Processing the request');
            Mage::throwException($errorMsg);
        }
        return $this;

    }
    public function processCreditmemo($creditmemo, $payment){
        return parent::processCreditmemo($creditmemo, $payment);
    }


    public function getOrderPlaceRedirectUrl()
    {
        if((int)$this->_getOrderAmount() > 0){
            return Mage::getUrl('pay/index/index', array('_secure' => true));
        }else{
            return false;
        }
    }

    private function _getOrderAmount()
    {
        $info = $this->getInfoInstance();
        if ($this->_isPlacedOrder()) {
            return (double)$info->getOrder()->getQuoteBaseGrandTotal();
        } else {
            return (double)$info->getQuote()->getBaseGrandTotal();
        }
    }
    private function _isPlacedOrder()
    {
        $info = $this->getInfoInstance();
        if ($info instanceof Mage_Sales_Model_Quote_Payment) {
            return false;
        } elseif ($info instanceof Mage_Sales_Model_Order_Payment) {
            return true;
        }
    }

}

这里有任何帮助吗?

感谢。

1 个答案:

答案 0 :(得分:4)

我们需要查看您的Atlanticsoft_Pay_Model_Pay定义。假设它继承自Mage_Payment_Model_Method_Abstract,则受保护的$_canUseCheckout属性应设置为true,以便在前端结帐流程中使用。

此外,pay是一个不明智的类别组。更好的是atlanticsoft_pay