I have a requirement where an order needs to be created from an existing order i.e Re-order feature of magento but programatically. A cron job dispatches a reorder event based on certain conditions. The below code looks up the order-id and creates a new order successfully. However, the new order picks the updated price of the product whereas I need it to be the same as the previous order. How can I modify it to set pricing from the last order?

$order = Mage::getModel('sales/order')->loadByIncrementId($lastOrderId);
$order_model = Mage::getSingleton('adminhtml/sales_order_create');
try {

    $reorder = $order_model->initFromOrder($order);
    $newOrder = $reorder->createOrder();
    $newOrderId = $newOrder->getIncrementId();
} catch (Exception $e) {
    Mage::log('Renewal for Profile #'.$profileId.': '.$e, null, 'prosub-debug.log');

I guess you should iterate all items of both orders and adjust the prices of each one. (take in account the row_total and the discounts applied to the original order)

If you want to display the difference you can leave the price and apply a discount, otherwise just copy all price related fields:

  • price
  • base_price
  • original_price
  • base_original_price

This should be enough.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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