开发者

Magento - Programmatically reorder

I am currently making a module that requires me to take an order object and make it reorder itself.. thus, creating a new order in the backend with the exact same items and credentials.

This is the code that i have thus far… it doesn’t seem to reorder the item or create and add another backend order.

$personsOrder = Mage::getModel(’sales/order’);
$personsOrder->loadByIncrementId($order[’model_order_id’]);

$order_model = Mage::getSingleton(’adminhtml/sales_order_create’);
$personsOrder->setReordered(true);

$order_model->initFromOrder($personsOrder);

/*
$order_model->save();

$order_model->place();
$order_model->sendNewOrderEmail();
*/

Any help is great开发者_高级运维ly appreciated!!


$orderId= $YOUR_ORDER_NUMBER;
$personsOrder = Mage::getModel('sales/order')->load($orderId);
$order_model = Mage::getSingleton('adminhtml/sales_order_create');
$personsOrder->setReordered(true);
$order_model->initFromOrder($personsOrder);
$order_model->createOrder();


My first thought is that you should be using $order->getIncrementId() on line 2 rather than $order['model_order_id'], but I'm not sure where you're getting $order from in the first place. Have you checked that $order['model_order_id'] is actually returning a valid increment ID? I don't see model_order_id as a field in the database anywhere...

I'd be suggesting that you getting your IDE and XDebug working so that you can inspect the objects as you work with them and understand what's going on.

Cheers, JD


If the order that you have placed the first time around is also created through coding and not from store front then you need to make sure that you have added an entry in the sales_flat_quote_item table. Otherwise that order cannot be reordered. So make sure it's not the case with your order creation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜