Greetings to you dear visitor on the pages of our site. In today's article, I want to describe the possibility of adding an opencart product category to which it is attached to the product card itself.
Many people use this option for a variety of cases, for example, when develop an online store title> a> I use the category output in the product card for seo promotion as an additional link.
Also in opencart by default, if you switch from a module to a product card, the bread crumbs are not displayed, for which I use this function to solve for you, I will describe only today a simple method of adding a category or categories to which the goods are attached to a product card.
In general, in order to add categories on the product page, we need to edit only two files:
catalog/controller/product/product.php and catalog/view/theme/Π²Π°Ρ_ΡΠ°Π±Π»ΠΎΠ½/template/product/product.tpl
Well, let's do it:
Open the product.php file and look for:
1 |
$this->load->model('catalog/product'); |
after which we need to add:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
$this->load->model('catalog/category'); $this->data['catprod'] = array(); $product_category = $this->model_catalog_product->getCategories($product_id); foreach ($product_category as $prodcat) { $category_info = $this->model_catalog_category->getCategory($prodcat['category_id']); if ($category_info) { $this->data['catprod'][] = array( 'name' => $category_info['name'], 'href' => $this->url->link('product/category', 'path=' . $category_info['category_id']) ); } } |
Next, open the product.tpl file of your active template and add the following in the right place:
1 |
<span>Categories: </span><?php foreach ($catprod as $catp) { ?> <a href="<?php echo $catp['href']; ?>"><?php echo $catp['name']; ?></a>|<?php } ?><br /> |
As I've already written, everyone uses this function at their own discretion, so you need to output wherever you need, for example, you can insert right after the model:
1 |
<span><?php echo $text_model; ?></span> <?php echo $model; ?><br /> |
That's actually all that needed to be done to ensure that the category of goods displayed in the card, it will be shown exactly those categories to which the goods are tied.
This design was done on opencart branches 1.5.5 ... but it will work on other branches.
Good luck!
No Comment
You can post first response comment.