Sometimes there is a situation where we have to reorder previously purchased products into customer accounts for continuous delivery of products or services. At that time you can reorder from Magento admin as well as from client checkout page which might take a long time but there is also another way to do reorder programmatically using a simple piece of code.
Generally, In Magento store, default there is two-way a reorder can be created.
- Frontend reorder creation which can be generally done using client checkout page.
- Backend reorder creation which can be generally done using Magento admin “Reorder” option which takes a less time in comparison to Frontend order creation but still it takes a time to make a selection of different choice while creating order.
But another 3rd way to make this process faster is to reorder programmatically in Magento using this code which helps you to save time and simplifying reorder creation process just by using order ID.
You just need to create a separate PHP file, upload it on a server, change order ID and run it, that’s it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
<!--?php error_reporting(E_ALL | E_STRICT); $mageFilename = 'app/Mage.php'; require_once $mageFilename; Mage::setIsDeveloperMode(true); umask(0); Mage::app(); try { $arrParams = 2; //Order id if($arrParams) { $order = Mage::getModel('sales/order')->load($arrParams); if (!$order->getId()) { Mage::getSingleton('adminhtml/session')->addError('Invalid order id'.$orderId); echo 'Order Not Found'; exit; } else { $quoteId = $order->getQuoteId(); $storeId = $order->getStoreId(); $quote = Mage::getModel("sales/quote") ->setStoreId($storeId) ->load($quoteId); $quote->collectTotals(); $service = Mage::getModel('sales/service_quote', $quote); $service->submitAll(); $order = $service->getOrder(); if ($order) { try { $order->sendNewOrderEmail(); } catch (Exception $e) { print_r($e->getMessage()); } } $order->save(); echo 'New Order '.$order->getIncrementId().' Create Successfully'; } } } catch(Exeption $e) { echo $e->getMessage(); } ?--> |
This code will help you to create a single reorder but to create multiple reorder you can use loop along with it.
Hope this code helped you to easily reorder in Magento programmatically. you can even use & customize this code according to your need for reorder creation.
Let me know in a comment section if you any ideas, suggestion or having an issue in implementing this code.I’ll be glad to help you!
Happy Reordering !
Hi,
Nice article, any idea how to do this in Magento 2?
Also what about the payment details? will it take the previous payment information or how does it process the payment?
Thanks
Rukshan
Hi,
Nice article, any idea how to do this in Magento 2?
Also what about the payment details? will it take the previous payment information or how does it process the payment?
Thanks
Rukshan