Convert Order to Quote and Load to Current Cart
@user1240207
Please use the below code. It will may help you.
Mage::getSingleton('checkout/session')->setQuoteId($_quote->getId());
Code convert an order to quote please used below:
$quote = Mage::getModel('sales/quote')->load($order->getQuoteId());
if ($quote->getId()) {
$quote->setIsActive(1)
//->setReservedOrderId(null)
->save();
Mage::getSingleton('checkout/session')
->replaceQuote($quote);
// ->unsLastRealOrderId();
}
Here the process:
Get Current quote
$currenQuoteId=Mage::getSingleton('checkout/session')->getQuoteId();
Convert Order to quote
$OrderQuote = Mage::getModel('sales/quote')->load($order->getQuoteId());
Active Quote
if ($OrderQuote>getId()) {
$OrderQuote>setIsActive(1)
//->setReservedOrderId(null)
->save();
}
Merge your current quote and order reverse Quote
if ($OrderQuote->getId() && $currenQuoteId != $OrderQuote->getId()) {
if ($currenQuoteId) {
$OrderQuote->merge(Mage::getSingleton('checkout/session')->getQuote())
->collectTotals()
->save();
}
set quote to checkout session
Mage::getSingleton('checkout/session')->setQuoteId($OrderQuote->getId());
if (Mage::getSingleton('checkout/session')->_quote) {
Mage::getSingleton('checkout/session')->delete();
}
Mage::getSingleton('checkout/session') = $OrderQuote;
} else {
Mage::getSingleton('checkout/session')->getQuote()->getBillingAddress();
Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress();
Mage::getSingleton('checkout/session')->getQuote()->setCustomer(Mage::getSingleton('customer/session')->getCustomer())
->setTotalsCollectedFlag(false)
->collectTotals()
->save();
}
The previous answer only works if the quote is still available in the DB. I ran into a situation where this was no longer the case, so this code doesn't work:
$quote = Mage::getModel('sales/quote')->load($order->getQuoteId());
$quote->getId() => This is empty, in fact the whole model is empty!
Instead, we can use the Mage_Sales_Model_Convert_Order
to convert an existing order back into a new quote using the toQuote(Mage_Sales_Model_Order $order)
method. It takes an order as input and outputs a new quote object.
You do need to call extra functions for converting the billing/shipping address, items, etc. For each object you will find a function in this class.