【发布时间】: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