是否可以在管理产品页面上按ID定义类别?
我们的想法是按ID(先前已注册)而不是按名称捕获类别。 我发现这些代码需要更改,负责该功能:
admin/model/catalog/product.php
public function getProductCategories($product_id) {
$product_category_data = array();
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_to_category WHERE product_id = '" . (int)$product_id . "'");
foreach ($query->rows as $result) {
$product_category_data[] = $result['category_id'];
}
return $product_category_data;
}
admin/controller/catalog/product.php
// Categories
$this->load->model('catalog/category');
if (isset($this->request->post['product_category'])) {
$categories = $this->request->post['category_id'];
} elseif (isset($this->request->get['product_id'])) {
$categories = $this->model_catalog_product->getProductCategories($this->request->get['product_id']);
} else {
$categories = array();
}
$this->data['product_categories'] = array();
foreach ($categories as $category_id) {
$category_info = $this->model_catalog_category->getCategory($category_id);
if ($category_info) {
$this->data['product_categories'][] = array(
'category_id' => $category_info['category_id'],
'name' => ($category_info['path'] ? $category_info['path'] . ' > ' : '') . $category_info['name']
);
}
}
admin/view/template/catalog/product_form.tpl
<tr>
<td><?php echo $entry_category; ?></td>
<td><input type="text" name="category" value="" /></td>
</tr>
<tr>
<td> </td>
<td><div id="product-category" class="scrollbox">
<?php $class = 'odd'; ?>
<?php foreach ($product_categories as $product_category) { ?>
<?php $class = ($class == 'even' ? 'odd' : 'even'); ?>
<div id="product-category<?php echo $product_category['category_id']; ?>" class="<?php echo $class; ?>"><?php echo $product_category['name']; ?><img src="view/image/delete.png" alt="" />
<input type="hidden" name="product_category[]" value="<?php echo $product_category['category_id']; ?>" />
</div>
<?php } ?>
</div></td>
</tr>
问题在于我不擅长使用php而且我不知道改变哪些方式来获得结果。 感谢您的帮助或想法!
答案 0 :(得分:0)
if (!empty($data['filter_name'])) {
$sql .= " AND cp.category_id LIKE '" . $this->db->escape($data['filter_name']) . "%'";
admin / model / catalog / category.php中的第211行
我找到了我的问题的解决方案,但它并没有解决我的问题。 感谢大家的帮助!