1
votes

First i should say i couldn't login into OC Support forum somehow, hope get solution here.

Trying to show Product Viewes in Product Page, I googled and found out how can to get another data from OC database and show it up on Product Page, so here is:

controller - product.php:

$data['viewed'] = $product_info['viewed'];

template - product.php;

<?php echo $viewed; ?>

but get error:

Undefined variable: viewed in

/homepages/5/xxxxxx/htdocs/xxxxx/catalog/view/theme/xxxxx/template/product/product.tpl

According to this Post i did right way, but i don't know why got get this error? any idea?

here is part of template code:

<h1><?php echo $heading_title; ?></h1>
<?php echo $viewed; ?>
<ul class="list-unstyled product-info">
<li><b><?php echo $text_stock; ?></b> <span class="Stock"><?php echo $stock; ?></span></li>
<li><b><?php echo $text_model; ?></b> <span class="Model"><?php echo $model; ?></span></li>
<?php if ($manufacturer) { ?>
<li><b><?php echo $text_manufacturer; ?></b> <a href="<?php echo $manufacturers; ?>"><?php echo $manufacturer; ?></a></li>
<?php } ?>
<li><b><?php echo $text_category; ?></b> <span>
<?php if( $categories ): ?>
<?php foreach( $categories as $category ): ?>
<a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a><span class="Comma"> ، </span>
<?php endforeach; ?>
<?php endif; ?>
</span></li>
<?php if ($reward) { ?>
<li><b><?php echo $text_reward; ?></b> <span class="reward-points"><i class="fa fa-plus" aria-hidden="true"></i> <?php echo $reward; ?></span></li>
<?php } ?>
</ul>
1
That would be the right way to do it normally. I do not get why your echoing $thumb in your template but your asking about an error that your controller is not seeing a "viewed" key. Have you passed $data to the template? Did you maybe declare $data['viewed'] after outputting the template? Have you tried using echo $viewed;?Yolo
sorry, anwer edited, i removed all that codes and write example here and it was my mistake, yes i tried to echo viewed, not thumb. @YoloPedram
well seems all correct. can you post the part where you output your template?Yolo
The controller is not the problem @pedram. "viewed" is declared fine and has to show up if you really added the line in your template file defined in config_template.Yolo
I added to product.tpl, it should work anywhere within that file.Lucas Krupinski

1 Answers

2
votes

If you're getting that error the only possible explanation is that the variable is not defined, which logically leads me to the conclusion that the file you edited is not the same controller that's calling your template. This can happen if you are using any OCMOD which has an unchanged version of product.php in the cache, since OCMOD doesn't know about changes you've made until you do a refresh. Do you have any OCMOD installed? Have you tried refreshing the OCMOD cache since you made the change?