我通过soap api获取数据不会显示为groupwise

时间:2014-02-10 06:07:02

标签: php magento soap

我有这个SOAP API代码

$getstatus="complete";
$thedate = date("Y-m-d", strtotime("6 month ago"));
$thesearch =array(array('updated_at'=>array('from'=>"$thedate"),   'status'=>array('eq'=>$getstatus)));
$totolsale = $soap->call($session_id, 'sales_order.list', $thesearch);

 if( is_array( $totolsale ) && !empty( $totolsale )) { 

// For every time there's a entry in the array we wish to run a loop
foreach( $totolsale as $sales ) 
{
 echo "<tr>";
       echo "<td style=\"color:#FF0000;\">".date('Y-m-d',strtotime($sales['created_at']))."</td>";
       echo "<td style=\"color:#FF0000;\">".$sales['base_grand_total']."</td>";
     echo "</tr>";

   }
 }

 //// Result is as follow/////

    Date        Qty     Amount      
    2013-12-12  1.00    109.0000    
    2013-12-13  1.00    109.0000    
    2013-12-14  2.00    150.0000    
    2013-12-16  1.00    109.0000    
    2013-12-16  1.00    109.0000    
    2013-12-18  1.00    109.0000    
    2014-01-25  1.00    109.0000    

这是所有订单列表日期老虎钳,但我想显示每个日期组老虎钳的总销售额。像2013-12-16它有两个记录,但我想在一行中显示这个日期的总销售额而不是列表。

1 个答案:

答案 0 :(得分:0)

在之前的7天内获得了以下解决方案

  $truecats = array();
foreach ($totolsale as $sales) {
 if (!isset($truecats[date('Y-m-d',strtotime($sales['created_at']))])) {
    $truecats[date('Y-m-d',strtotime($sales['created_at']))] = array();
}
$truecats[date('Y-m-d',strtotime($sales['created_at']))][] =  $sales['base_grand_total'];
}



foreach ($truecats as $dates => $values) 
{
        $totdailysale=0;

 /// if day is empty then take it as 

        for($i=1;$i<=7;$i++)
        {


            $datenow=date ('Y-m-d', strtotime ( '-'.$i. 'day' . $date ) ); 

            if($dates==$datenow)
            {
           echo "<tr><td>$dates</td>";

           foreach ($values as $val) 
           {
               $totdailysale+=$val;
             // echo "<td>$totdailysale</td></tr>";
           }
            echo "<td>$totdailysale</td></tr>";
        }
        else
        {
          echo "<tr><td>$datenow</td><td>0</td></tr>";  

        }




    }
    }