Opencart在模型中找不到自定义方法

时间:2016-05-19 19:50:48

标签: php opencart opencart2.x opencart-module

我在模型php中创建了一个名为“getProductbySku”的自定义方法。

/admin/model/catalog/product.php

public function getProductbySku($sku) {
        $query = $this->db->query("select id from " . DB_PREFIX . "product where sku = '".$sku."'");
        if($query->num_rows){
            return $query->row['product_id'];
        }else{
            return false;
        }
    }

/admin/controller/module/syncproduct.php

$this->load->model("catalog/product");
print_r(get_class_methods($this->model_catalog_product));
$product_id = $this->model_catalog_product->getProductbySku($row['sku']);
                if($product_id){
...

我无法调用我的方法。

致命错误:在第204行的public_html / admin / controller / module / syncproduct.php中调用未定义的方法ModelCatalogProduct :: getProductbySku()

Array
(
    [0] => addProduct
    [1] => editProduct
    [2] => copyProduct
    [3] => deleteProduct
    [4] => getProduct
    [5] => getProducts
    [6] => getProductsByCategoryId
    [7] => getProductDescriptions
    [8] => getProductCategories
    [9] => getProductFilters
    [10] => getProductAttributes
    [11] => getProductOptions
    [12] => getProductOptionValue
    [13] => getProductImages
    [14] => getProductDiscounts
    [15] => getProductSpecials
    [16] => getProductRewards
    [17] => getProductDownloads
    [18] => getProductStores
    [19] => getProductLayouts
    [20] => getProductRelated
    [21] => getRecurrings
    [22] => getTotalProducts
    [23] => getTotalProductsByTaxClassId
    [24] => getTotalProductsByStockStatusId
    [25] => getTotalProductsByWeightClassId
    [26] => getTotalProductsByLengthClassId
    [27] => getTotalProductsByDownloadId
    [28] => getTotalProductsByManufacturerId
    [29] => getTotalProductsByAttributeId
    [30] => getTotalProductsByOptionId
    [31] => getTotalProductsByProfileId
    [32] => getTotalProductsByLayoutId
    [33] => __construct
    [34] => __get
    [35] => __set
)

所以,我将“echo $ file”添加到/system/engine/loader.php

public function model($model, $data = array()) {
    // $this->event->trigger('pre.model.' . str_replace('/', '.', (string)$model), $data);
    $model = str_replace('../', '', (string)$model);
    $file = DIR_APPLICATION . 'model/' . $model . '.php';
    echo $file;
...

没有变化...... Opencart版本是2.1.0.1

1 个答案:

答案 0 :(得分:0)

此文件是覆盖目录/产品型号 system / modification / admin / model / catalog / product.php