Hello,
I was wondering if somebody could help me with listing all the categories which a certain product belongs to.
For example. The product "Apple Cinema 30"" in my page has been linked to 5 sub-categories under the main-category "Components". How can I on the product page list all the sub-categories which is linked to the product?
The desired output:
This product belongs to the following sub-categories: Mice and Trackballs, Monitors, Printers, Scanners, Web Cameras
I'm using 1.5.1.3
Any help is appreciated!
Regards,
Hello again,
I really didnt think I was going to pull this through. My first time I manipulate OpenCart in this fashion (way to advanced for me). Here is what I did:
Added in model/catalog/product.php:
Added in controller/product/product.php:
Added in product.tpl:
Result:
http://tonera.se/index.php?route=produc ... duct_id=42
"This product belongs to the following sub-categories: Monitors, Mice and Trackballs, Printers, Scanners, Web Cameras,"
This modifcation is useful when creating a Cartridge-site. "This toner also fits to:" and then the list of printer-models.
A printer model can have different cartridges connected to it, and also the cartridges can fit to many different printer models, so the best way, for the customer, was to put all the printer-models as categories. And then just connect the different products to the categories.
I really didnt think I was going to pull this through. My first time I manipulate OpenCart in this fashion (way to advanced for me). Here is what I did:
Added in model/catalog/product.php:
Code: Select all
public function getProductCategories($product_id) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_to_category pc, " . DB_PREFIX . "category_description cd WHERE pc.product_id = '" . (int)$product_id. "' AND cd.category_id = pc.category_id");
return $query->rows;
}
Code: Select all
$this->data['product_categories'] = array();
$results = $this->model_catalog_product->getProductCategories($this->request->get['product_id']);
foreach ($results as $result) {
$this->data['product_categories'][] = array(
'tag' => $result['name'],
'href' => $this->url->link('product/category', $url . '&path=' . $result['category_id'])
);
}
Code: Select all
<?php if ($product_categories) { ?>
<div class="test"><br /><b>Denna produkt passar även:</b>
<?php foreach ($product_categories as $product_category) { ?>
<?php if($product_category['tag'] != ''){?>
<a href="<?php echo $product_category['href']; ?>"><?php echo $product_category['tag']; ?></a>,
<?php }?>
<?php } ?>
<br /><br />
</div>
<?php } ?>
http://tonera.se/index.php?route=produc ... duct_id=42
"This product belongs to the following sub-categories: Monitors, Mice and Trackballs, Printers, Scanners, Web Cameras,"
This modifcation is useful when creating a Cartridge-site. "This toner also fits to:" and then the list of printer-models.
A printer model can have different cartridges connected to it, and also the cartridges can fit to many different printer models, so the best way, for the customer, was to put all the printer-models as categories. And then just connect the different products to the categories.
Who is online
Users browsing this forum: No registered users and 130 guests