简体   繁体   English

与自定义报告Magento中的时区差异

[英]difference with timezone in Custom Report Magento

I am creating a custom report in Magento. 我正在Magento中创建自定义报告。 My server is located in the US and my shop is Brazilian. 我的服务器位于美国,我的店铺是巴西人。 It turns out that buying schedules are saved in the American schedule, ie 3hours more than in Brazil. 事实证明,购买时间表保存在美国时间表中,即比巴西多3小时。 And that gives a difference in the report results. 这给报告结果带来了不同。

Imagine the following situation: A customer makes a purchase on 30/06 at 10:00 PM (time of Brazil), in the database, this purchase comes as day 01/07 at 01:00 AM. 想象一下以下情况:客户在30/06下午10:00(巴西时间)进行购买,在数据库中,此购买时间为01/07上午01:00。

How do you pick the order creation time (GMT USA) and turn clockwise from Brazil? 您如何选择订单创建时间(GMT USA)并从巴西顺时针转动?

Today, I'm using that. 今天,我正在使用它。

      $to="";
$from="";
$show_order_statuses = 0;
$orserstatus = "";

$result_order = 0;

if(!empty($_REQUEST['from']) && !empty($_REQUEST['to'])){

    $orders_row = array();
    date_default_timezone_set('America/Sao_Paulo'); //define o timezone como Sãp Paulo  
    $filter_type = $_REQUEST['filter_type'];
    $from = $_REQUEST['from'];
    $to = $_REQUEST['to'];      
    $from_date = date('Y-m-d' . ' 00:00:00', strtotime($from));
    $to_date = date('Y-m-d' . ' 23:59:59', strtotime($to));


    $filter_model  = ($filter_type == 'shipping_date')
        ? 'sales/order_shipment_collection'
        : 'sales/order_collection';

    if($_REQUEST['show_order_statuses']>0){
        $orserstatus = $_REQUEST['order_statuses'];
        $_orderCollections = Mage::getResourceModel($filter_model);
            $_orderCollections->addAttributeToSelect('*');
            $_orderCollections->addFieldToFilter('created_at', array('from'=>$from_date, 'to'=>$to_date));
            if($filter_type == 'order_date'){
                $_orderCollections->addFieldToFilter('status', $orserstatus);
            }                
            $_orderCollections->setOrder('created_at', 'desc');
            $_orderCollections->load();
    }else{
        $_orderCollections = Mage::getResourceModel($filter_model)
            ->addAttributeToSelect('*')
            ->addFieldToFilter('created_at', array('from'=>$from_date, 'to'=>$to_date))
            ->setOrder('created_at', 'desc')
            ->load();
    }

Anyone who can help, thank you 有人可以提供帮助,谢谢

You should always use Magento's core date function to account for timezones. 您应该始终使用Magento的核心日期函数来计算时区。

So instead of: 所以代替:

$from_date = date( 'Y-m-d' . ' 00:00:00', strtotime( $from ) );

Use: 采用:

$from_date = Mage::getModel( 'core/date' )->date( 'Y-m-d 00:00:00', strtotime( $from ) );

This will give you the date based on the timezone you have set in your store's configuration in the admin. 这将根据您在管理中的商店配置中设置的时区为您提供日期。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM