1

I am creating a reorder functionality in magento. It is creating with same info of order but showing the grand total double. Last order subtotal price $10 and shipping $5 so grand total is $15 but in new reorder it is giving 25$ Below is the code for reodering process.

$order = Mage::getModel('sales/order')->load($order_id);
        $order->setReordered(true);
         $newQuote = new Mage_Sales_Model_Quote();
        $newQuote->setStoreId($order->getStoreId());
        $newQuote->assignCustomer(Mage::getModel('customer/customer')->load($order->getCustomerId()));
        $newQuote->setUseOldShippingMethod(true);
        $model = Mage::getSingleton('adminhtml/sales_order_create');
        $model->setQuote($newQuote);
        $reorder = $model->initFromOrder($order);
        $reorder->getQuote()->getShippingAddress()
             ->setShippingMethod($order->getShippingMethod())
             ->setCollectShippingRates(true)
            ->collectShippingRates()
             ->collectTotals()
            ->save();
        $reorder->createOrder();
1
  • I am having same issue.Found any answer then please share details. Commented Oct 11, 2015 at 3:08

1 Answer 1

0

I found some piece of code for this and want to share.May be help someone

 $orderId = 121; // Order Id not increment ID

Mage::unregister('rule_data');
Mage::getSingleton('adminhtml/session_quote')->clear();

$order = Mage::getModel('sales/order')->load($orderId);
$incId = $order->getIncrementId();

$newQuote = new Mage_Sales_Model_Quote();
$newQuote->setStoreId($order->getStoreId());
Mage::getSingleton('adminhtml/sales_order_create')->setQuote($newQuote);

$order_model = Mage::getSingleton('adminhtml/sales_order_create');
$order_model->getSession()->clear();

try {
    $order->setReordered(true);
    Mage::getSingleton('adminhtml/session_quote')->setUseOldShippingMethod(true);

    $reorder = new Varien_Object();
    $reorder = $order_model->initFromOrder($order);
    $newOrder = $reorder->createOrder();

    $reOrderId = $newOrder->getId();
    $reOrderIncId = $newOrder->getIncrementId();
    print_r("Order is Reorders To New Order #{$reOrderIncId} Successfully");
} catch (Exception $e) {
    Mage::log("Reorder Error : {$e->getMessage()}",null,"order.log");
}
$reorder->getSession()->clear();
Mage::unregister('rule_data');
Mage::getSingleton('adminhtml/session_quote')->clear();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.