Reputation: 210
When a customer reorders I need to include a reference to the original order ID on the new order. I can see how to add an attribute for this in sales_flat_order
and sales_flat_quote
(I think!), but I can't see how to hook into the reorder.
The reorder is quite simple and is done in app\code\core\Mage\Sales\Controller\Abstract.php->reorderAction
. It simply copies order items to the cart and then opens the cart. But how can I hook into this to add an orderId crossreference?
I can probably just copy this to local and edit it (correct?) but that's not a smart way of doing it because I've then taken everything done in Abstract.php and made a local copy of it.
I guess I could also create a custom module that does the reorder and point the "reorder" link to my custom module. But again, that's a bit hacky and I'd prefer to hook into the process if possible.
Thanks.
Upvotes: 0
Views: 3668
Reputation: 803
You can hook into the controller_action_predispatch_sales_order_reorder
event and then get the order id parameter on the observer
$oldOrderId=Mage::app()->getRequest()->getParam('order_id');
Create a new column for the quote and order table on a sql installer
$installer = new Mage_Sales_Model_Resource_Setup('core_setup');
$options = array(
'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
);
$installer->addAttribute('quote', 'old_order_id', $options);
$installer->addAttribute('order', 'old_order_id', $options);
$installer->endSetup();
then save the parameter order_id to the quote object on the observer
Mage::getSingleton('checkout/session')->getQuote()->setOldOrderId($oldOrderId)->save();
and create a fieldset on your config.xml to transfer the value of that attribute to the order object
<global>
<fieldsets>
<sales_convert_quote>
<old_order_id>
<to_order>*</to_order>
</old_order_id>
</fieldsets>
</global>
There might be some experimentation involved, but you get the idea.
Upvotes: 5