Check if a user is logged in or not on product page using OpenCart 2.3.X - opencart

I'm using Opencart 2.3.0.2 and would liek to show or hide the product code based on if the user is logged in.
in product.tpl I have tried changing:
<li><?php echo $text_model; ?> <?php echo $model; ?></li>
to
<?php if ($logged) { ?>
<li><?php echo $text_model; ?> <?php echo $model; ?></li>
<?php } ?>
but I get an error message stating that logged is not defined in product.tpl
I have also editing controller/common/header.php to include the following in various places with no luck.
$data['logged'] = $this->customer->isLogged();
What am I doing wrong?
Thank you

You must declare logged in corresponding controller file. So you nee add $data['logged'] = $this->customer->isLogged();
to:
catalog/controller/product/product.php file.

Related

How do i get access to all front end pages on an opencart module?

Is there a way I can create an OpenCart module that has access to all the (front-end) pages of the store?
What I want is for the user to not have to “bind” this module to all the layouts in order for it to exist in all pages.
Basically I want to build a module that injects some js code to every page of the app and depending on some OpenCart hooks on the back-end to run some extra js code on front or some api requests on the back-end.
Thanks
I am not sure exactly what you are looking for by saying you want a module to have "access" to all the (front-end) pages of the store. Modules have to be placed in layouts, and layouts can be assigned to multiple pages.
Each layout can have elements that are assigned specifically to areas you can designate (and customize). For example, you might want to create a special place for your module in the common header. You would simply create the controller, language and view files in a folder of your own designation (in my example, I will use the common folder), and let's call these files "loadjs".
Pattern these after the common/header.php and .tpl files. Just be sure to change the class and file names in the controller file to match. So you would create a loadjs.php file in the common directory of the controller folder that contains the ControllerCommonLoadjs class, a loadjs.php file in the language/(your language)/common folder, and a loadjs.tpl file in the view/theme/(your theme name)/template/common folder.
Add a $data['loadjs'] = $this->load->controller('common/loadjs'); to your controller/common/header.php file and <?php echo $loadjs; ?> in your view/theme/(your theme name)/template/common/header.tpl file. You can now create your module.
However, to be able to add it to your layout you will need to make some changes to some admin files. Add $_['text_loadjs'] = 'Loadjs'; to your admin/language/(your language)/design/layout.php file and $data['text_loadjs'] = $this->language->get('text_loadjs'); to your admin/controller/design/layout.php file.
You will need to make a change to your admin/view/template/design/layout_form.tpl file as well. Look for the following code:
<option value="content_top" selected="selected"><?php echo $text_content_top; ?></option>
<?php } else { ?>
<option value="content_top"><?php echo $text_content_top; ?></option>
<?php } ?>
<?php if ($layout_module['position'] == 'content_bottom') { ?>
<option value="content_bottom" selected="selected"><?php echo $text_content_bottom; ?></option>
<?php } else { ?>
<option value="content_bottom"><?php echo $text_content_bottom; ?></option>
<?php } ?>
and add the following code just below that:
<?php if ($layout_module['position'] == 'loadjs') { ?>
<option value="loadjs" selected="selected"><?php echo $text_loadjs; ?></option>
<?php } else { ?>
<option value="loadjs"><?php echo $text_loadjs; ?></option>
<?php } ?>
Now, login to your OpenCart Dashboard and add your module to the loadjs position on your layout. And that should do it.

Change Image Size on Product Page in opencart 2.0.1.1

I have small problem with changing size of the product image only on product page.
I know that from admin I can change the size for all thumb pictures.
But how to make bigger images only on the product page and I am not talking about additional images section...
Can anyone explain to me where $thumb variable is defined as i made search in almost all php files but I cannot find $thumb declaration...????
In product.tpl
Code:
<div id="product">
<div class="a"><img src="<?php echo $thumb; ?>" title="<?php echo $heading_title; ?>" alt="<?php echo $heading_title; ?>"><br>
<?php echo $text_enlarge; ?></div>
Now in this bit taken from product.tpl I see that path for the image is taken from the variable called $thumb.
I want Opencart to:
Prepare for me medium sized image
Generate for it path that will be stored in $medium variable which I can call in this place and simply have the code like this:
Code:
<div id="product">
<div class="a"><img src="<?php echo $medium; ?>" title="<?php echo $heading_title; ?>" alt="<?php echo $heading_title; ?>"><br>
<?php echo $text_enlarge; ?></div>
Anyone please help...
Before you start work in opencart, You should have to understand the basic knowledge of opencart MVC-L (i.e. How opencart module works)
Here is the Tutorial
$thumb which is defined in product.tpl file is declared in its controller file ( catalog/product/product.php ) named $data['thumb'].
Maximum variables used in product.tpl file are defined in modules controller file.
To more information, Check the above shared tutorial.

Use product tags for meta keywords in Opencart 1.5.3.1

I'd like to use my product tags as meta keywords on every product page. Can anyone help me with this code?
Thaks
Below are some tips and they are general but give a direction of the different approaches to do this. Step 4 is a bit obvious. I am sorry but this not a module request forum, your question I think is fair so this direction set should get you in the right direction.
1 - Open catalog/view/theme/default/product/product.tpl
And do a find and replace with the header echo:
<?php
$getKeysandReplace=$header;
$getKeysandReplace=str_replace("<meta name=", "");
?>
Understand? Or use a regex to delete the Meta Keyword and Meta Description from the $header string and replace them with your own on the product.tpl - just grab the tags echo in the below code.
<?php if ($tags) { ?>
<div class="tags"><b><?php echo $text_tags; ?></b>
<?php for ($i = 0; $i < count($tags); $i++) { ?>
<?php if ($i < (count($tags) - 1)) { ?>
<?php echo $tags[$i]['tag']; ?>,
<?php } else { ?>
<?php echo $tags[$i]['tag']; ?>
<?php } ?>
<?php } ?>
</div>
<?php } ?>
2 - You can edit header.tpl and do a IF($GET or if page is product type page then display this Meta Tag or display the normal tags.
3 - You can do an SQL crob job that copies the product tags, and places them as product keywords in your database everyday.
4 - Make sure staff copy and paste the tags as keywords to in the admin panel - stating the obvious

how to display a message on cart and checkout page for particular category product?

lets say i have a category "test" and its product "t1". IF i add this product to cart, it must show some message "my custom message". Also on checkout page, how can i do the same on payment step. i.e check if it is from category test then display this message ?
what i tried so far on cart page is this before form on cart.phtml:
$_catCollection = $this->getItem()->getProduct()->getCategoryCollection();
foreach ($_catCollection as $_category) {
// do stuff with your Mage_Catalog_Model_Category
print_r($_category);
}
?>
But getting this
Fatal error: Call to a member function getProduct() on a non-object
Set up an attribute for each product that will contain your special message.
Then you can maybe do something along the lines of:
<?php foreach ($this->getItems() as $item) : ?>
<?php if ($item->getSpecialMessage) : ?>
<?php echo $item->getSpecialMessage ?>
<?php endif ?>
<?php endforeach; ?>

Add Date and Author to node.tpl.php

In the code below I'd like to show the created date, author and have them be linked but nothing for they do not show. I believe I need to be doing $node-> rather that row, haven't figured out the exact code. Or what if anything I need to change under Views in my Drupal 6 installation. Thanks in advance!
<?php if($node->type == 'blog'): ?>
<div class="blog-page">
<div class="title-post">
<div class="top-image">
<?php print $node->field_image[0]['view'] ?>
</div><!--TOP-IMAGE-->
<p>Posted on ?php $row['created'] ?>, by
<?php print $row['name'] ?></p>
</div>
<div class="content-page">
<?php print $node->content['body']['#value'] ?>
</div>
</div>
<?php else: ?>
<?php print $content ?>
<?php endif ?>
Drupal has a node object with tons of related information in it. Basically if you ever need to use information from it like author, date, title, etc, you can easily determine the code by printing the node object.
echo '<pre>';
print_r($node);
echo '</pre>';
lets say it outputted something like this for simplicity's sake:
stdClass {
nid = 3
content = stdClass {
raw = " ... "
clean = " ... "
}
}
To output those bits of information in your template, you'd write in the following way.
for a field with no subclass:
<?php print $node->nid ?>
for a field with a subclass:
<?php print $node->content['raw'] ?>
Does that make sense? after you get that down, you literally can figure out anything when programming drupal templates.
so, if you wanted to construct a url, you'd just chain it up:
<?php
$nid = $node->nid;
$uri = "some/path".$nid;
print $uri;
?>