簡體   English   中英

Magento 1.8.0.0:添加重定向到新頁面的自定義付款方式

[英]Magento 1.8.0.0: Add custom payment method redirecting to a new page

我在本地使用magento 1.8.0.0。 我成功創建了一種自定義付款方式。 該方法在結帳時顯示在“付款信息”中的付款方法列表中。 問題是,當我選擇它時,它會自動帶來一張信用卡表格,這不是我想要的。 我想要選擇它,然后單擊“繼續”按鈕,我將重定向到另一個包含我自己的表單的php頁面。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM