I am using Magento 1.9.x and I would like to create an order via quote and I can do that like this:
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();
}
But my problem is the success page. When I redirect to the success page just appear like this
Not appear order id or print detail like this
How can I fix it?
Thank you Edit:
I want to create a custom payment method. If the customer choose my method I delete the "Place Order" button and I create iframe at order review.
app\design\frontend\base\default\layout\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>
app\code\local\Mycompany\Mymodule\Helper\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 response 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();
}
}
Payment is complete at in iframe and calls my module response page with some parameters.
app\code\local\Mycompany\Mymodule\controllers\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();
}
}