Guys I want to share with you one small revision for opencart namely how to make so that the product card displayed the number of views of this product, perhaps someone will be interested, since some customers sometimes want a blob .
And so in order to display the number of views in the product card, we need to change only a few lines in the product controller and also in the product template itself.
The "viewed" viewer function was originally built into the basic assembly of opencart, we'll just bring it to our template, and so let's go ....
First of all, we open the goods inspector: File catalog/controller/product/product.php
In it we search for a line:
1 |
$this->data['points'] = $product_info['points']; |
After which we add:
1 |
$this->data['viewed'] = $product_info['viewed']; |
Further in the same place we search for a line:
1 |
$this->data['text_reward'] = $this->language->get('text_reward'); |
After it, add a line that is responsible for outputting the language from the language file namely the word "Views:"
1 |
$this->data['text_viewed'] = $this->language->get('text_viewed'); |
All with the controller finished, we proceed to the language fileΒ catalog/language/russian/product/product.php
In it we add:
1 |
$_['text_viewed'] = 'Views:'; |
In any place afterΒ <?php I added for example after:
1 |
$_['text_points'] = 'Price in bonus points:'; |
All the same thing we do with other languages if they are present in the store.
I finished the language, now open the file of your themeΒ catalog/view/theme/default/template/product/product.tpl
And in the place convenient for you we add the code:
1 2 3 |
<?php if ($viewed) { ?> <span class="viewsproduct"><?php echo $text_viewed; ?></span> <?php echo $viewed; ?><br /> <?php } ?> |
For example after:
1 |
<span><?php echo $text_stock; ?></span> <?php echo $stock; ?><br /> |
That's basically all, now in the product card you will see the number of views of this product.
Well, and a little bun, for example, if you want to replace the word "views" with an example of a picture in the form of a glazier well, or something else ...
For this you need from the code added in the template:
1 |
<span class="viewsproduct"><?php echo $text_viewed; ?></span> <?php echo $viewed; ?><br /> |
Remove the output of the word itself and remove it:
1 |
<?php echo $text_viewed; ?> |
After you add a set of styles to the style file for your theme:
1 2 3 4 5 6 7 8 9 |
.viewsproduct{ background: url(../image/views-icon.png) no-repeat scroll 0 0 rgba(0, 0, 0, 0); display: inline-table; height: 15px; margin-right: 0; position: relative; width: 22px; top: 4px; } |
Well, of course for each of the templates you may have to customize the styles for yourself, but still you have the basic view, well, do not forget to upload the picture of the eye in the image folder of your template. You can download the eye of Β hereΒ
That's basically all I wanted to write, now you have a beautiful glazik in the opencart product card near which you will see how many times this product was viewed ...
Good luck!
No Comment
You can post first response comment.