douyong2531 2015-07-09 12:57
浏览 80
已采纳

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

I am creating a custom report in 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. 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.

How do you pick the order creation time (GMT USA) and turn clockwise from Brazil?

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

  • 写回答

1条回答 默认 最新

  • doujiong9915 2015-07-13 05:05
    关注

    You should always use Magento's core date function to account for timezones.

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?