我正在将 opencart 用于 Web 项目,并向所有名为 unit
的产品添加自定义字段。我在 oc_product
表中创建了一个名为 unit
的列。我可以通过添加 data['unit'] = Product_info['unit']
并通过查询获取它来访问 Product.php 页面上的产品单位,但我想在购物车上访问它.php 页面。我不确定购物车从思想中得到的产品是从哪里来的。所以我不知道到底在哪里添加代码来获取单位。在controller/common/cart.php
中有这样的代码块:
$data['products'][] = array(
'product_id'=> $product['product_id'],
'key' => $product['key'],
'thumb' => $image,
//THIS
'unit' => $product['unit'],
'name' => $product['name'],
'model' => $product['model'],
'option' => $option_data,
'recurring' => ($product['recurring'] ? $product['recurring']['name'] : ''),
'quantity' => $product['quantity'],
'price' => $price,
'total' => $total,
'href' => $this->url->link('product/product', 'product_id=' . $product['product_id'])
);
如果您查看上面的代码,请右键单击注释“THIS”,我添加了一行来获取单位。添加该代码不会给我单位,我知道它不会,因为我没有查询它,但我不知道在哪里添加查询。如果我将 $product['unit'] 替换为像“12”这样的简单字符串,我就可以访问购物车页面上的 12。所以问题是我应该编辑哪个查询才能将商品显示在购物车页面上?
最佳答案
我能够弄清楚。转到行 242
int /system/library/cart.php
并在数组中添加以下行
'unit' => $product_query->row['unit']
关于php - 如何在opencart中获取cart.php中的附加产品信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36751592/