【问题标题】:Magento and BST Timezone issueMagento 和 BST 时区问题
【发布时间】:2014-06-09 15:49:56
【问题描述】:

我在 CentOS 的 LEMP 堆栈之上运行 Magento 商店,我正在尝试使用订单的created_at 日期时间从网站将订单导入我们的 CRM(以便我们可以执行增量更新)。

服务器的时区是 Europe/London,据说我的 php-fpm 池配置(用于我的站点)也是相同的:

php_admin_value[date.timezone] = Europe/London

我创建了一个订单,它正确显示了订单的创建时间,例如:

但是,如果我在数据库中查看此订单,created_at 设置为提前一小时(让我相信 BST 时区设置无效):

这是否意味着 Magento 不支持 BST?还是我们的magento设置不正确?还是我需要解决方法(即检测是否开启夏令时,然后添加/删除小时等...)?


更新

这就是我实现give me all the orders since my last sync 功能的方式,下面代码中的$API_Data 指的是来自服务器的上次同步:

private function GetNewOrderIncrementIds($API_Data = '')
{
    // Init
    $now = new DateTime();

    // Set Timezone to Europe/London (From Config)
    $now->setTimezone(new DateTimeZone(Mage::getStoreConfig('mymodule_config/system_config/default_timezone')));

    // Generate Date & Time
    $fromDate = $API_Data;
    $toDate   = $now->format('Y-m-d H:i:s');

    // Load Straight Order Sync Config
    $sos_enabled  = ((int)Mage::getStoreConfig('mymodule_config/order_sync/straight_order_sync_enabled'));
    $sos_storeid  = (int)Mage::getStoreConfig('mymodule_config/order_sync/straight_order_sync_storeid');
    $sos_shipping = Mage::getStoreConfig('mymodule_config/order_sync/straight_order_sync_shippingmethod');

    // Load Order Collection
    $order_collection = Mage::getModel('sales/order')
        ->getCollection()
        ->addAttributeToFilter('created_at', array(
            'from' => $fromDate,
            'to' => $toDate
        ));

    // Build Order Increment Id List
    $new_orders = array();
    foreach ($order_collection as $order)
    {
        // Check If This Order Is Straight Order Sync
        $doSOS = ($sos_enabled &&
                  (int)$order->getStoreId() == $sos_storeid &&
                  $order->getShippingMethod() == $sos_shipping);

        // Append Order
        $new_orders[] = array(
            'OrderNumber' => $order->getIncrementId(),
            'DoSOS'       => $doSOS
        );
    }
    $order_collection = null;

    // Finished
    $this->API_Response(false, '', json_encode(array(
        'LastSync'  => $toDate,
        'NewOrders' => $new_orders
    )));
}

【问题讨论】:

  • 我会说它运行良好。 BST 是 UTC+1,所以 16:19:31 BST 是 15:19:31 UTC。数据库值采用 UTC 是很好的。否则,during the fall-back transition 的值将不明确。
  • 我更新了我的问题,显示了我的代码。我需要它通过我的代码工作,所以我不会错过任何订单。

标签: php magento datetime timezone


【解决方案1】:

Magento 设置脚本的时间相对于服务器时间,转换为 UTC。因此,每个 Magento 存储(数据库方面)都与 UTC 同步。阅读更多@Guide through Magento’s timezones

保存 created_at 日期使用

Mage::getSingleton('core/date')->gmtDate()

要检索 created_at 存储日期使用

Mage::helper('core')->formatDate($this->getCreatedAtStoreDate(), $format, true);

参见/app/code/core/Mage/Core/Block/Abstract.php

获取订单日期

foreach ($order_collection as $order)
    {
       ...
       $created_at = Mage::helper('core')->formatDate($order->getCreatedAt(), 'medium', true);

【讨论】:

  • 您好,感谢您的回复。我用代码更新了我的问题,显示了我如何尝试使用created_at 加载上次同步的订单(增量更新)。我如何或在哪里使用这个getCreatedAtStoreDate,以便我始终使用正确的日期和时间来保持我的订单同步?
  • 假设要导出订单创建的当地时间,那么$created_at = Mage::helper('core')->formatDate($order->getCreatedAt(), 'medium', true);
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-28
  • 1970-01-01
  • 1970-01-01
  • 2023-03-09
  • 2018-03-30
  • 2010-11-23
相关资源
最近更新 更多