我正在创建一个脚本,以在Magento中以编程方式添加订单。我需要帮助来更改注解历史记录中条目的日期(报价、发票、发货等)。我可以操作订单本身的日期(setCreatedAt),并且与订单创建相关的一些注解是正确的(例如“Sep 29,2008 8 8:59:25 AM|待定客户通知不适用”),但我使用addStatusHistoryComment时无法更改评论的日期...
下面是我的代码片段:
try {
if(!$order->canInvoice()) {
Mage::throwException(Mage::helper('core')->__('Cannot create an invoice.'));
}
$invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
if (!$invoice->getTotalQty()) {
Mage::throwException(Mage::helper('core')->__('Cannot create an invoice without products.'));
}
$invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_OFFLINE);
$invoice->setCreatedAt('2008-09-23 13:05:20');
$invoice->register();
$invoice->getOrder()->setCustomerNoteNotify(true);
$invoice->getOrder()->setIsInProcess(true);
$transactionSave = Mage::getModel('core/resource_transaction')
->addObject($invoice)
- >addObject($invoice->getOrder());
$transactionSave->save();
//END Handle Invoice
//START Handle Shipment
$shipment = $order->prepareShipment();
$shipment->setCreatedAt('2008-09-23 14:20:10');
$shipment->register();
$order->setIsInProcess(true);
$order->addStatusHistoryComment('Shipping message goes here...', true);
$shipment->setEmailSent(true);
$transactionSave = Mage::getModel('core/resource_transaction')
->addObject($shipment)
->addObject($shipment->getOrder())
->save();
$track = Mage::getModel('sales/order_shipment_track')
->setShipment($shipment)
->setData('title', 'Some tracking no.')
->setData('number', '111222333444')
->setData('carrier_code', 'fedex') //custom, fedex, ups, usps, dhl
->setData('order_id', $shipment->getData('order_id'))
->save();
//END Handle Shipment
}
catch (Mage_Core_Exception $ex) {
echo "Problem creating order invoice and/or shipment: ".$ex."\n";
}
先谢了。
2条答案
按热度按时间6bc51xsx1#
如果我没理解错你的问题,你只需要这样做:
$comments
现在包含所有状态历史注解的集合,您可以使用任何类型的条件循环访问它们。vfh0ocws2#
这是未经测试的,但应该可以工作:
您需要创建一个基于
addStatusHistoryComment
的新方法:/app/code/core/Mage/Sales/Model/Order.php
显然,您要么需要重写此方法,要么需要重构代码来完成相同的操作。