如何以编程方式在magento中的订单历史评论中添加自定义日期?

时间:2014-12-24 08:20:09

标签: magento magento-1.8

我正在使用自定义日期更新/插入新评论,但评论正在添加当前日期和时间而不是自定义日期, 使用此代码

$new_date='2010-01-01';
$order->setData('created_at',$new_date);
$order->addStatusToHistory($order->getStatus(), 'This comment is programatically added', false);
$order->save();

如何添加此自定义日期?有没有办法实现此目的..

1 个答案:

答案 0 :(得分:3)

你可以这样做:

$history = Mage::getModel('sales/order_status_history')
    ->setStatus($order->getStatus())
    ->setComment('My Comment!')
    ->setEntityName(Mage_Sales_Model_Order::HISTORY_ENTITY_NAME)
    ->setIsCustomerNotified(false)
    ->setCreatedAt(date('Y-m-d H:i:s', time() - 60*60*24));

$order->addStatusHistory($history);
$order->save();

请注意,在数据库中保存时间时无需计算时区偏移量。 Magento希望时间为UTC,并已使用date_default_timezone_set('UTC');设置默认时区,因此我们可以使用time()函数。 Magento将根据System > Configuration > General > Locale Options

中的配置在前端/管理员显示值之前动态计算时间偏差
相关问题