0

我开始从事一个使用 OpenCart 的项目。尝试添加新选项时,我遇到了一个奇怪的问题。

我在后端创建了两个文本选项并将它们分配给一个产品。它有效。问题是,选项未在前端正确加载。它们显示正常,但是当我输出所有应该存在的变量(特别是 product_option_id)时,它们为 NULL。之前我什至没有注意到这个问题,但是我需要 product_option_id 对代码进行一些修改。

当我通过 print_f 输出页面上的选项时,我得到了这个:

[0] => Array
    (
        [product_option_id] => 
        [calc_group_id] => 0
        [description] => ####
        [option_id] => 469
        [name] => ####
        [type] => text
        [option_value] => 
        [required] => 0
    )

[1] => Array
    (
        [product_option_id] =>
        [calc_group_id] => 0
        [description] => ####
        [option_id] => 468
        [name] => ####
        [type] => text
        [option_value] => 
        [required] => 0
    )

我将问题缩小到 OpenCart 中的产品模型 (catalog/model/catalog/product.php)

这行:

    $product_option_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option po LEFT JOIN `" . DB_PREFIX . "option` o ON (po.option_id = o.option_id) LEFT JOIN " . DB_PREFIX . "option_description od ON (o.option_id = od.option_id) WHERE po.product_id = '" . (int)$product_id . "' AND od.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY o.sort_order");

我尝试了这个 SQL 语句,它也返回了它必须返回的内容,即 product_option_id。我不知道出了什么问题,如果在 phpmyadmin 中测试,SQL 语句会返回正确的值,但上面的代码行没有(我输出了 $product_option_query->$rows 和一些值,比如 product_option_id 是空的)。

我怀疑我以错误的方式创建了选项。还是有这种可能?有趣的是,其他一些选项(选择类型选项)甚至我创建的选项(如果设置为选择类型)确实返回所有值,包括 product_option_id。

4

1 回答 1

2

False alarm, thanks anyways.

The problem wasn't opencart, the problem was the guy working on this project before me. He changed the line I had problems with in a vqmod script. Needless to say, his sql statement didn't work, cause the result were two product_option_ids, one with the actual result and one which was empty.

This will be a lesson to me. If you take over a project, always double check the work that was done before.

于 2012-11-06T14:24:18.270 回答