微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Opencart 3.0.3.7 尝试访问 bool 类型值的数组偏移量

如何解决Opencart 3.0.3.7 尝试访问 bool 类型值的数组偏移量

我在 PHP 7.4 上运行 Opencart 3.0.3.7 并且我收到此消息错误日志:

PHP Notice: Trying to access array offset on value of type bool in /home/site/public_html/catalog/model/extension/module/so_filter_shop_by.PHP on line 313

PHP Notice: Trying to access array offset on value of type bool in /home/site/public_html/catalog/model/extension/module/so_filter_shop_by.PHP on line 314

代码是:

    foreach($query->rows as $result)
    {
        $data = $this->model_catalog_product->getProduct($result['product_id']);
        $price = $this->tax->calculate($data['price'],$data['tax_class_id'],$this->config->get('config_tax'));
        if ((float)$data['special']) {
            $price = $this->tax->calculate($data['special'],$this->config->get('config_tax'));
        }

        $price = $this->currency->format($price,$this->session->data['currency']);
        if ($this->language->get('decimal_point') == ',') {
            $price = trim(str_replace(',','.',$price));
        }
        else {
            $price = trim(str_replace(','',$price));
        }
        $price = trim(str_replace($currencies,$price));
        
        $data['price_soFilter'] = $price;

        $product_data[] = $data;
    }
    return $product_data;
}

谁能提出解决错误解决方案。

解决方法

您必须检查 $price NOT NULL 是否尝试这样的操作:

if(is_null($price))
  {
   $price = '';
  } else {
   $price = $this->tax->calculate($data['price'],$data['tax_class_id'],$this->config->get('config_tax'));
  }
,

你可以试试:

if(!empty($price)) {
   $price = $this->tax->calculate((float)$data['price'],$this->config->get('config_tax'));
} else {
   $price = '';
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。