问题
hi i want to customize the feature module that as category is set through admin display the relevant product instead of featured module
when ever i select the category it displays category products what will be the code of controller which get category n give products array to that category
below is the view code of category select input
<td><select name="category_id">
<?php foreach($categories as $category) { ?>
<option value="<?php echo $category['category_id'];?>"><?php echo $category['name'];?></option>
<?php } ?>
</select>
回答1:
$categories = $this->model_catalog_product->getProductCategories(
$this->request->get['product_id']);
foreach($categories as $category_id) {
// do something
}
Add the getProductCategories
function into 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;
}
来源:https://stackoverflow.com/questions/18967116/get-category-products-by-category-id-in-opencart