【问题标题】:Magento 1.8.0.0: Add custom payment method redirecting to a new pageMagento 1.8.0.0:添加自定义付款方式重定向到新页面
【发布时间】:2014-08-26 07:05:49
【问题描述】:

我在本地使用 magento 1.8.0.0 工作。我成功创建了自定义付款方式。该方法在结账时出现在“付款信息”的付款方式列表中。问题是当我选择它时,它会自动带一个信用卡表格,这不是我想要的。我想要的是选择它,一旦我点击“继续”按钮,我就会被重定向到另一个包含我自己的表单的 php 页面。

【问题讨论】:

  • 你想重定向到任何网关吗?
  • 或者在网站上的任何自定义表单页面上?
  • 嗨 MTM!我想重定向到网关。
  • 您会通过现场下单还是下单前重定向它们?
  • 我只有重定向到网关的代码,工作正常。问题是我不知道将它们放在 Magento 中的哪个位置,因此当有人选择我的自定义付款方式时,他/她会被重定向到该网关。谢谢。

标签: magento methods payment checkout redirect


【解决方案1】:

OP 的解决方案。

对于想要重定向到网关并希望网关重定向回控制器的操作方法的您,事情是这样的: 在文件app/code/local/Yourcompany/Yourmodule/Model/PaymentMethod.php 中,执行以下操作:

class Yourcompany_Yourmodule_Model_PaymentMethod extends Mage_Payment_Model_Method_Abstract{
protected $_code  = "yourmodule";
protected $_isGateway = true;
protected $_canAuthorize = true;
 protected function _getCheckout()  {
return Mage::getSingleton('checkout/session'); } 
public function getOrderPlaceRedirectUrl()  {  return Mage::getUrl(yourmodule/index/youraction', array('_secure' => true));  }}

return Mage::getUrl(yourmodule/index/youraction', array('_secure' => true)); 行中,“index”表示我的控制器php 文件名为IndexController.php。您可以根据需要更改名称。 在文件app/code/local/Yourcompany/Yourmodule/controllers/IndexController.php 中,您可以编写如下代码:

class Yourcompany_Yourmodule_IndexController extends Mage_Core_Controller_Front_Action{      
public function indexAction() { 
$this->loadLayout();
$block = $this->getLayout()->createBlock('Mage_Core_Block_Template','yourmodule',array('template' => 'yourmodule/redirect.phtml'));
$this->getLayout()->getBlock('content')->append($block);
$this->renderLayout(); }
/*In the response action, you may code like this*/
public function responseAction() {  
$status=$_REQUEST['param1'];
$orderNo=$_REQUEST['param2'];
if(somecondition)
{
/*update order status */    
$ordera = Mage::getModel('sales/order')->loadByIncrementId($orderNo);
$ordera->setState(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT, true)->save(); 
$this->_redirect("checkout/onepage/success");   
}
else
{
$this->_redirect("checkout/cart/");
} 
} } 

indexAction() 正在重定向到模板 redirect.phtml 文件。该文件将收集一些参数发送到网关(订单号、客户名称、总金额等)。你可以把那个 phtml 文件放在这里:

app/design/frontend/base/default/template/yourmodule/redirect.phtml

其内容可编码如下:

<?php 
$orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
$order = Mage::getSingleton('sales/order')->loadByIncrementId($orderId);
$order_amount=$order->getGrandTotal();
$customerData = Mage::getSingleton('customer/session')->getCustomer();
$customerAddressId = Mage::getSingleton('customer/session')->getCustomer()->getDefaultBilling(); //oder getDefaultShipping
$address = Mage::getModel('customer/address')->load($customerAddressId);
$customer_name=$address->getFirstname().' '.$address->getLastname();
$customer_email=$customerData->getEmail();
?>
<form name="myjs" method="post" action="http://yourgatewayaddreshere">
<input type="hidden" name="customername" value="<?php echo $customer_name; ?>">
<input type="hidden" name="customermail" value="<?php echo $customer_email; ?>">
<input type="hidden" name="TotalMoney" value="<?php echo $order_amount; ?>">
</form>
<script type="text/javascript">
document.myjs.submit();
</script>

【讨论】:

    猜你喜欢
    • 2013-09-04
    • 2011-06-29
    • 1970-01-01
    • 2019-09-11
    • 1970-01-01
    • 1970-01-01
    • 2014-05-13
    • 2013-12-13
    • 2012-05-13
    相关资源
    最近更新 更多