我正在使用Magento 1.9.x,我想通过引用创建订单,我可以这样做:
private function createOrder()
{
$orderId = $session->getTransactionId();
$quote = $this->_getCheckout()->getQuote();
$quote->setReservedOrderId($orderId);
$quote->collectTotals()->getPayment()->setMethod($this->_getPaymentMethod());
$quoteId = $quote->getId();
$service = Mage::getModel('sales/service_quote', $quote);
$service->submitAll();
$order = $service->getOrder();
$order->setStatus('complete');
$order->save();
$checkoutSession = Mage::getSingleton('checkout/type_onepage')->getCheckout();
$checkoutSession->setLastSuccessQuoteId($quoteId);
$checkoutSession->setLastQuoteId($quoteId);
$checkoutSession->setLastOrderId($order->getIncrementId());
}
protected function _getCheckout()
{
return Mage::getSingleton('checkout/session');
}
protected function _getPaymentMethod()
{
return $this->_getCheckout()->getQuote()->getPayment()->getMethod();
}
但我的问题是成功页面。当我重写成功页面时就像是 this
未显示订单ID或打印详细信息,如this
我该如何解决?
谢谢 编辑:
我想创建自定义付款方式。如果客户选择我的方法,我会删除“下订单”按钮,并在订单审核时创建iframe。
应用\设计\前端\基\默认\布局\ mymodule.xml
<?xml version="1.0"?>
<layout version="0.1.0">
<checkout_onepage_review>
<reference name="checkout.onepage.review.button">
<action method="setTemplate">
<template helper="mymodule/data/getReviewButtonTemplate">
<name>mymodule/onepage/iframe.phtml</name>
<block>checkout.onepage.review.button</block>
</template>
</action>
</reference>
</checkout_onepage_review>
</layout>
应用\代码\本地\ MyCompany的\ Mymodule中\助手\ data.php
<?php
class Mycompany_Mymodules_Helper_Data extends Mage_Core_Helper_Abstract
{
public function getHostedUrl()
{
//get iframe url from soap
}
public function GetHostedPaymentProcessStatusResult()
{
//check from soap responce is correct
}
public function getReviewButtonTemplate($name, $block)
{
$paymentcode = $this->_getPaymentMethod();
if ($paymentcode == 'mymodule')
return $name;
if ($blockObject = Mage::getSingleton('core/layout')->getBlock($block))
return $blockObject->getTemplate();
return '';
}
public function getConfigData($configName)
{
return Mage::getStoreConfig('payment/mymodule/' . $configName, Mage::app()->getStore());
}
protected function _getCheckout()
{
return Mage::getSingleton('checkout/session');
}
protected function _getPaymentMethod()
{
return $this->_getCheckout()->getQuote()->getPayment()->getMethod();
}
}
在iframe中完成付款,并使用一些参数调用mymodule responce页面。
应用\代码\本地\ MyCompany的\ Mymodule中\控制器\ PaymentController.php
<?php
class Mycompany_Mymodule_PaymentController extends Mage_Core_Controller_Front_Action
{
public function responseAction()
{
$session = Mage::getSingleton('core/session');
$transactionId = $_GET['TransactionId'];
$orderId = $session->getTransactionId();
$mymoduleTransId = $_GET['MymoduleTransId'];
$helper = Mage::helper('mymodule');
if ($_GET['Result'] == 'PaymentOk' && $transactionId == $orderId) {
$quote = Mage::getSingleton('checkout/session')->getQuote();
$result = $helper->getHostedPaymentProcessStatus($transactionId, $mymoduleTransId);
if ($result) {
$result = $result->GetHostedPaymentProcessStatusResult;
$resultCode = $result->ResultCode;
if ($resultCode === "Success") {
$quote->setReservedOrderId($orderId);
$quoteId = $quote->getId();
$quote->collectTotals()->getPayment()->setMethod($this->_getPaymentMethod());
$service = Mage::getModel('sales/service_quote', $quote);
$service->submitAll();
$order = $service->getOrder();
$order->setStatus(Mage::helper('mymodule')->getConfigData('after_pay_status'));
$order->save();
$checkoutSession = Mage::getSingleton('checkout/type_onepage')->getCheckout();
$checkoutSession->setLastSuccessQuoteId($quoteId);
$checkoutSession->setLastQuoteId($quoteId);
$checkoutSession->setLastOrderId($order->getIncrementId());
$this->_clearQuote($quoteId);
$returnUrl = Mage::getUrl('checkout/onepage/success', array('_secure' => true));
} else
$returnUrl = Mage::getUrl('checkout/onepage/failure', array('_secure' => true));
} else {
$returnUrl = Mage::getUrl('checkout/onepage/failure', array('_secure' => true));
}
echo '<script> window.top.location.href = "' . $returnUrl . '";</script>';
}
}
protected function _getCheckout()
{
return Mage::getSingleton('checkout/session');
}
protected function _getPaymentMethod()
{
return $this->_getCheckout()->getQuote()->getPayment()->getMethod();
}
protected function _clearQuote($quoteID)
{
$quote = Mage::getModel("sales/quote")->load($quoteID);
$quote->setIsActive(0)->save();
$quote->delete();
$quote->save();
$cart = Mage::getSingleton('checkout/cart');
$quoteItems = Mage::getSingleton('checkout/session')
->getQuote()
->getItemsCollection();
foreach ($quoteItems as $item) {
$cart->removeItem($item->getId());
}
$cart->save();
}
}
答案 0 :(得分:0)
最好的方法(实际上我相信这是magento使用的方式)是将订单ID传递给会话。为此,请使用Mage::getSingleton('core/session')->setIncrementId($order->getIncrementId());
。
然后在成功页面上使用Mage::getSingleton('core/session')->getIncrementId($order->getIncrementId());
来检索订单的增量ID。