【问题标题】:Magento - Issue creating a new payment method moduleMagento - 创建新付款方式模块的问题
【发布时间】:2015-01-12 01:44:55
【问题描述】:

我正在使用 Magento 1.9.0.1

我正在开发一个添加额外付款方式的自定义扩展程序。 一切似乎都适用于扩展程序 - 付款方式显示正确,但当我尝试选择我的自定义方式“下订单”时出现此错误。

这是我得到的错误:

处理您的请求时出错

出于安全原因,默认情况下禁用异常打印。

错误日志记录号:321152034690

报告如下:

a:5:{i:0;s:150:"Cannot send headers; headers already sent in /home/sportsdi/public_html/beta/app/code/local/Myname/Mygateway/controllers/PaymentController.php, line 1";i:1;s:1061:"#0 /home/sportsdi/public_html/beta/lib/Zend/Controller/Response/Abstract.php(115): Zend_Controller_Response_Abstract->canSendHeaders(true)
#1 /home/sportsdi/public_html/beta/app/code/core/Mage/Core/Model/App.php(1246): Zend_Controller_Response_Abstract->setHeader('Content-Type', 'text/html; char...')
#2 /home/sportsdi/public_html/beta/app/code/core/Mage/Core/Controller/Varien/Front.php(80): Mage_Core_Model_App->getResponse()
#3 /home/sportsdi/public_html/beta/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(202): Mage_Core_Controller_Varien_Front->getResponse()
#4 /home/sportsdi/public_html/beta/app/code/core/Mage/Core/Controller/Varien/Front.php(172): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#5 /home/sportsdi/public_html/beta/app/code/core/Mage/Core/Model/App.php(354): Mage_Core_Controller_Varien_Front->dispatch()
#6 /home/sportsdi/public_html/beta/app/Mage.php(684): Mage_Core_Model_App->run(Array)
#7 /home/sportsdi/public_html/beta/index.php(87): Mage::run('', 'store')
#8 {main}";s:3:"url";s:28:"/mygateway/payment/redirect/";s:11:"script_name";s:10:"/index.php";s:4:"skin";s:7:"default";}

这是我得到的所有内容:/home/sportsdi/public_html/beta/app/code/local/Myname/Mygateway/controllers/PaymentController.php:

<?php
class Myname_Mygateway_PaymentController extends Mage_Core_Controller_Front_Action {
    // The redirect action is triggered when someone places an order
    public function redirectAction() {
        $this->loadLayout();
        $block = $this->getLayout()->createBlock('Mage_Core_Block_Template','mygateway',array('template' => 'mygateway/redirect.phtml'));
        $this->getLayout()->getBlock('content')->append($block);
        $this->renderLayout();
    }

    // The response action is triggered when your gateway sends back a response after processing the customer's payment
    public function responseAction() {
        if($this->getRequest()->isPost()) {

            /*
            /* Your gateway's code to make sure the reponse you
            /* just got is from the gatway and not from some weirdo.
            /* This generally has some checksum or other checks,
            /* and is provided by the gateway.
            /* For now, we assume that the gateway's response is valid
            */

            $validated = true;
            $orderId = '123'; // Generally sent by gateway

            if($validated) {
                // Payment was successful, so update the order's state, send order email and move to the success page
                $order = Mage::getModel('sales/order');
                $order->loadByIncrementId($orderId);
                $order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true, 'Gateway has authorized the payment.');

                $order->sendNewOrderEmail();
                $order->setEmailSent(true);

                $order->save();

                Mage::getSingleton('checkout/session')->unsQuoteId();

                Mage_Core_Controller_Varien_Action::_redirect('checkout/onepage/success', array('_secure'=>true));
            }
            else {
                // There is a problem in the response we got
                $this->cancelAction();
                Mage_Core_Controller_Varien_Action::_redirect('checkout/onepage/failure', array('_secure'=>true));
            }
        }
        else
            Mage_Core_Controller_Varien_Action::_redirect('');
    }

    // The cancel action is triggered when an order is to be cancelled
    public function cancelAction() {
        if (Mage::getSingleton('checkout/session')->getLastRealOrderId()) {
            $order = Mage::getModel('sales/order')->loadByIncrementId(Mage::getSingleton('checkout/session')->getLastRealOrderId());
            if($order->getId()) {
                // Flag the order as 'cancelled' and save it
                $order->cancel()->setState(Mage_Sales_Model_Order::STATE_CANCELED, true, 'Gateway has declined the payment.')->save();
            }
        }
    }
}

你能帮我找出问题并解决它吗?

提前致谢!

【问题讨论】:

  • 您好,尝试在该模块中搜索“echo”语句并对其进行评论,然后尝试下订单。

标签: php magento


【解决方案1】:

如果您的模块中有任何 echo 语句,那么也会出现此错误,如果找到,请在您的模块 echo 中查找,然后将其删除。

【讨论】:

    【解决方案2】:

    除非您打开输出缓冲,否则使用“echo”语句会导致这种情况。如果还想看回显的结果,放上一行,

    ob_start();
    

    相关文件的顶部将为您提供所需的结果。

    更多信息:http://php.net/manual/en/function.ob-start.php

    【讨论】:

      猜你喜欢
      • 2015-02-27
      • 2014-11-09
      • 1970-01-01
      • 2012-03-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-02
      • 2018-09-16
      • 1970-01-01
      相关资源
      最近更新 更多