0

仅在首页的 CS-Cart 管理员中,我收到错误消息:

警告:在第 255 行的 app\controllers\backend\index.php 中为 foreach() 提供的参数无效

这个函数的代码是:

function fn_get_orders_taxes_subtotal($orders, $params)
{
    $subtotal = 0;

    if (!empty($orders)) {
        $_oids = array();
        foreach ($orders as $order) {
            if (in_array($order['status'], $params['paid_statuses'])) {
                $oids[] = $order['order_id'];
            }
        }

        if (empty($oids)) {
            return $subtotal;
        }

        $taxes = db_get_fields('SELECT data FROM ?:order_data WHERE order_id IN (?a) AND type = ?s', $oids, 'T');

        if (!empty($taxes)) {
            foreach ($taxes as $tax) {
                $tax = unserialize($tax);
                foreach ($tax as $id => $tax_data) {
                    $subtotal += !empty($tax_data['tax_subtotal']) ? $tax_data['tax_subtotal'] : 0;
                }
            }
        }
    }

    return $subtotal;
}

有问题的具体行是:

foreach ($tax as $id => $tax_data) {

有什么想法可能发生在这里吗?奇怪的是,这并没有显示是否打开了模板调试。

4

1 回答 1

0

通过打印您在该函数中的两个 foreach 变量是数组来检查,我的意思是您的 $taxes 得到了行并且 $tax 得到了正确的序列化数据,您可以通过使用 is_array() 嵌入 if 条件来忽略该错误,这是一个演示..

if (is_array($taxes)) {
    foreach ($taxes as $tax) {
        $tax = unserialize($tax);
       if(is_array($tax)){    
         foreach ($tax as $id => $tax_data) {
            $subtotal += !empty($tax_data['tax_subtotal']) ? $tax_data['tax_subtotal'] : 0;
         }
       }
    }
}
于 2014-03-18T10:29:41.930 回答