显示在产品页面OpenCartv3中销售的单位

时间:2017-08-18 00:27:05

标签: php database opencart opencart-3

我试图在OpenCart v3的产品页面中显示每种产品的销售单位,但我一直收到以下错误

  

致命错误:未捕获错误:调用成员函数getUnitsSold()   在null中   /Applications/XAMPP/xamppfiles/htdocs/store/catalog/controller/product/product.php:157   堆栈跟踪:#0   /Applications/XAMPP/xamppfiles/htdocs/store/system/engine/action.php(79):   ControllerProductProduct-> index()#1   /Applications/XAMPP/xamppfiles/htdocs/store/catalog/controller/startup/router.php(25):   动作 - >执行(对象(注册表))#2   /Applications/XAMPP/xamppfiles/htdocs/store/system/engine/action.php(79):   ControllerStartupRouter-> index()#3   /Applications/XAMPP/xamppfiles/htdocs/store/system/engine/router.php(67):   动作 - >执行(对象(注册表))#4   /Applications/XAMPP/xamppfiles/htdocs/store/system/engine/router.php(56):   Router-> execute(Object(Action))#5   /Applications/XAMPP/xamppfiles/htdocs/store/system/framework.php(168):   Router-> dispatch(Object(Action),Object(Action))#6   /Applications/XAMPP/xamppfiles/htdocs/store/system/startup.php(104):   require_once(' / Applications / X ...')#7   /Applications/XAMPP/xamppfiles/htdocs/store/index.php(19):in   /Applications/XAMPP/xamppfiles/htdocs/store/catalog/controller/product/product.php   在第157行

到目前为止我所拥有的是

目录/模型/目录/ product.php

public function getUnitsSold($product_id) {
    $query = $this->db->query("SELECT SUM(op.quantity) AS total FROM `" . DB_PREFIX . "order_product` op LEFT JOIN `" . DB_PREFIX . "order` o ON (op.order_id = o.order_id) WHERE o.order_status_id > '0' AND op.product_id = '" . (int)$product_id . "'");
if ($query->row) {
        return $query->row['total'];
    } else {
        return FALSE;
    }
}

和目录/ controller / product / product.php

$data['text_units_sold'] = $this->language->get('text_units_sold');
$this->data['units_sold'] = $this->model_catalog_product->getUnitsSold($product_id);

任何人都可以发现问题和解决方案。

感谢。

1 个答案:

答案 0 :(得分:0)

我怀疑在你调用getUnitsSold的函数中,你没有做过

$this->load->model('catalog/product');