我试图在 OpenCart v3 的产品页面中显示每个产品的销售单位,但我不断收到以下错误
致命错误:未捕获错误:在 /Applications/XAMPP/xamppfiles/htdocs/store/catalog/controller/product/product.php:157 中调用成员函数 getUnitsSold() on null 堆栈跟踪:#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): Action- >execute(Object(Registry)) #2 /Applications/XAMPP/xamppfiles/htdocs/store/system/engine/action.php(79): ControllerStartupRouter->index() #3 /Applications/XAMPP/xamppfiles/htdocs/store /system/engine/router.php(67): Action->execute(Object(Registry)) #4 /Applications/XAMPP/xamppfiles/htdocs/store/system/engine/router.php(56): Router->execute (对象(动作))#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):在第 157 行的 /Applications/XAMPP/xamppfiles/htdocs/store/catalog/controller/product/product.php
到目前为止我所拥有的是
目录/模型/目录/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;
}
}
并在目录/控制器/产品/product.php
$data['text_units_sold'] = $this->language->get('text_units_sold');
$this->data['units_sold'] = $this->model_catalog_product->getUnitsSold($product_id);
任何人都可以发现问题所在和解决方案。
谢谢。