在首页的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) {
这里有什么想法可能会发生什么?奇怪的是,这并没有显示模板调试是否已打开。
答案 0 :(得分:0)
通过打印检查你的两个foreach变量在该函数中是数组,我的意思是你的$ tax得到了行和$ 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;
}
}
}
}