Post by OpenCarter121 » Sat Jan 16, 2016 12:22 am

Hi guys,

I'm currently creating / integrating my own theme. I'm aware it's a big 'no-no' to edit the content in the 'catalog/view/theme/default' folder and so I've created my own theme folder and have set it in the Admin area as the theme which should be used for the store front – so far, so good!

Now, I'm having a little difficulty bringing some dynamic content into my new theme. The header is working well and pulling in the logo I uploaded to the database via the Admin area, but I'm receiving an error in the footer when trying to display the logo there too:

"Notice: Undefined variable: logo in /catalog/view/theme/myTheme/template/common/footer.tpl"

I'm guessing this is something to do with the Controller files not supplying the information to the footer.tpl file.

So, my question is: What files am I 'allowed' to update and which files am I not? I wouldn't want to update any Controller files (or anything else) for them to be overwritten with the next OpenCart update!

Many thanks!

Newbie

Posts

Joined
Sat Jan 16, 2016 12:05 am

Post by OpenCarter121 » Mon Jan 18, 2016 4:40 am

Hi guys

Anyone know which files are updated when OC is updated?

Thanks

Newbie

Posts

Joined
Sat Jan 16, 2016 12:05 am

Post by artcore » Mon Jan 18, 2016 6:13 am

Definitely all files except the custom ones like themes and extensions.
Look in the catalog/controller/common/header.php and copy the code for $data['logo'] into the footer controller.
Better is to use OCMOD to apply your changes.

For the new upcoming OC it's below code but is similar(*) for older versions.

Code: Select all

if (is_file(DIR_IMAGE . $this->config->get('config_logo'))) {
			$data['logo'] = $server . 'image/' . $this->config->get('config_logo');
		} else {
			$data['logo'] = '';
		}
(*)Bare in mind that you would also need to update the OCMOD for the later versions as it's profoundly different from OC < 2.2
If you need an example for an OCMOD, let me know. It's really easy.

Attn: I no longer provide OpenCart extensions, nor future support - this includes forum posts.
Reason: OpenCart version 3+ ;D

Thanks!


User avatar
Active Member

Posts

Joined
Tue Jul 09, 2013 4:13 am
Location - The Netherlands

Post by OpenCarter121 » Mon Jan 18, 2016 5:20 pm

Hi Artcore

Thank you for your reply!

I copied the below code from the header and pasted it into the footer controller, but I'm worried future updates would delete this?

Code: Select all

		if (is_file(DIR_IMAGE . $this->config->get('config_logo'))) {
			$data['logo'] = $server . 'image/' . $this->config->get('config_logo');
		} else {
			$data['logo'] = '';
		}
Why is it better to use a OCMOD to make changes? An example would be very helpful.

Thank you!

Newbie

Posts

Joined
Sat Jan 16, 2016 12:05 am

Post by artcore » Mon Jan 18, 2016 6:17 pm

OCMOD or Opencart modification is a technique for changing core files by replacing them with a modified version.
It's heavily inspired by VQmod.
An ocmod file searches a string and replaces it with a modified version. It can also add code. It is installed using the extension installer and on refresh it creates a new file in the system/modification folder with the same folder structure as the core.
An upgrade of the shop will retain all changes on the premise that the search string is still there for starters ;D

It works great but EVENTually it might be replaced by the event system which can add to/alter the core with a hook system like Wordpress eg.

https://github.com/opencart/opencart/wi ... ion-System
https://github.com/vqmod/vqmod/wiki
https://github.com/opencart/opencart/wi ... s)-2.0.0.1

Unfortunately I find myself writing ocmods for every single opencart (sub)version which makes it kinda developer unfriendly.
I've written WP plugins for 3.6 that still work on 4.4 :choke:
But OC is still the best for its speed and ease of use!

I'll give you an example for the logo using ocmod later today.

Attn: I no longer provide OpenCart extensions, nor future support - this includes forum posts.
Reason: OpenCart version 3+ ;D

Thanks!


User avatar
Active Member

Posts

Joined
Tue Jul 09, 2013 4:13 am
Location - The Netherlands

Post by OpenCarter121 » Mon Jan 18, 2016 6:20 pm

Fantastic, thank you very much!

Newbie

Posts

Joined
Sat Jan 16, 2016 12:05 am

Post by artcore » Mon Jan 18, 2016 11:34 pm

Just as an example.

Tips:
  • Always search for one unique line and add/replace to your liking. You can specify which occurrence to use if there are multiple hits for the search. Use <search index="x"... where x is the nth occurrence starting from 0.
  • array $data keys are extracted, so $data['something'] is used as $something in the tpl.
  • You can upload this file directly to the system folder and it'll work. Handy for quick changes to the ocmod.
The modified file lives in /system/modification/catalog/controller/common/footer.php and can be changed here too before applying it to the ocmod. Remember that REFRESHing in admin deletes/rebuilds the modification cache so all changes made directly to these files are lost.

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<modification>
 <name>Logo in Footer</name>
 <code>unique-code-1</code>
 <version>1.0</version>
 <author>your name</author>
 <link>http://www.yourdomain.com</link>

 <!--prepare data-->
 <file path="catalog/controller/common/footer.php">
  <operation>
   <search><![CDATA[$this->load->language('common/footer');]]></search>
   <add position="after"><![CDATA[
    if ($this->request->server['HTTPS']) {
     $server = $this->config->get('config_ssl');
    } else {
     $server = $this->config->get('config_url');
    }
    if (is_file(DIR_IMAGE . $this->config->get('config_logo'))) {
     $data['logo'] = $server . 'image/' . $this->config->get('config_logo');
    } else {
     $data['logo'] = '';
    }]]></add>
  </operation>
 </file>

 <!--use data-->
 <file path="catalog/view/theme/*/template/common/footer.tpl">
  <operation>
   <search><![CDATA[<p><?php echo $powered; ?></p>]]></search>
   <add position="after"><![CDATA[<div class="pull-right"><img src="<?php echo $logo; ?>" alt="logo" title="store name"></div>]]></add>
  </operation>
 </file>

</modification>

Attn: I no longer provide OpenCart extensions, nor future support - this includes forum posts.
Reason: OpenCart version 3+ ;D

Thanks!


User avatar
Active Member

Posts

Joined
Tue Jul 09, 2013 4:13 am
Location - The Netherlands

Post by OpenCarter121 » Tue Jan 19, 2016 12:12 am

That's great, thank you!

Newbie

Posts

Joined
Sat Jan 16, 2016 12:05 am

Post by OpenCarter121 » Tue Jan 19, 2016 12:52 am

I'd also like to create additional positions in OpenCart, so I'm following an online tutorial. The tutorial says I should create a new file in the ‘catalog/controller/common/’ folder. If I create a new file, would this not be deleted when OpenCart's updated?

Thank you

Newbie

Posts

Joined
Sat Jan 16, 2016 12:05 am

Post by artcore » Tue Jan 19, 2016 2:57 am

No it'll stay, no files are deleted during an upgrade. If it'll still work after is the question :)

Attn: I no longer provide OpenCart extensions, nor future support - this includes forum posts.
Reason: OpenCart version 3+ ;D

Thanks!


User avatar
Active Member

Posts

Joined
Tue Jul 09, 2013 4:13 am
Location - The Netherlands

Post by OpenCarter121 » Tue Jan 19, 2016 6:42 am

Ahh so it replaces files it's aware of and not overwrites the folders.

Thank you

Newbie

Posts

Joined
Sat Jan 16, 2016 12:05 am

Post by cyclops12 » Wed Jan 20, 2016 4:36 am

artcore wrote:Just as an example.

Tips:
  • Always search for one unique line and add/replace to your liking. You can specify which occurrence to use if there are multiple hits for the search. Use <search index="x"... where x is the nth occurrence starting from 0.
Hiya artcore,
How would you make multiple changes in one file
For example:
In catalog/controller/module/category.php you have the following code listed twice

Code: Select all

'name' => $child['name'] ,......more code...
How would you make changes to both instances

thanks in advance and sorry to hijack the thread

Expert Member

Posts

Joined
Sun Sep 27, 2015 1:10 am

Post by artcore » Wed Jan 20, 2016 5:43 am

Hey cyclops,

It's related so fine by me :)
If you want all occurences to be changed leave out the index on the search tag, otherwise use index="0,3" for example to change the first and fourth.

Attn: I no longer provide OpenCart extensions, nor future support - this includes forum posts.
Reason: OpenCart version 3+ ;D

Thanks!


User avatar
Active Member

Posts

Joined
Tue Jul 09, 2013 4:13 am
Location - The Netherlands

Post by OSWorX » Wed Jan 20, 2016 5:45 am

Very easy, e.g.:

Code: Select all

<file path="catalog/controller/product/search.php">
		<operation info="Your description">
			<search index="0">
				<![CDATA[
					foreach ($results as $result) {
				]]>
			</search>
			<add  position="before">
				<![CDATA[
			$your_new_code here ...
				]]>
			</add>
	    </operation>
	    <operation info="Infotext 2">
			<search index="0">
				<![CDATA[
					$data['products'][] = array(
				]]>
			</search>
			<add position="after">
				<![CDATA[
					'my_new_var' => $this->url->link( 'product/product', 'product_id=' . $result['product_id'] . $url ),
				]]>
			</add>
	    </operation>
    </file>
and if you have multiple instances of the same search, use something like:

Code: Select all

<search index="1,3">
means you will have 4 times the same line, but want only replace/add/etc. the second and forth (counting starts at 0).

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Administrator

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria
Who is online

Users browsing this forum: No registered users and 11 guests