Post by HAL 9000 » Wed Oct 15, 2008 3:32 am

I created a card module called "card".  I created "card.php & card.tpl" files in

-  language\english\extension\module
-  extension\module
-  template\kottu\module

I used "" in layout.tpl to display the module and I am getting the following message.


Notice: Undefined variable: card in /home/handy/www/kottu/catalog/template/kottu/layout.tpl on line 44

Any help is appreciated.


Bharat

New member

Posts

Joined
Thu Sep 11, 2008 8:53 pm

Post by Qphoria » Wed Oct 15, 2008 3:37 am

Hi bharat,

You need to create the variable for $card in the controller file, and pass that to the view using

$view->set('card', $variable);

The template (view) only knows about variables that have been passed to it from the controller files.

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by HAL 9000 » Wed Oct 15, 2008 4:56 am

Where do I create the variable in controller folder?

New member

Posts

Joined
Thu Sep 11, 2008 8:53 pm

Post by Qphoria » Wed Oct 15, 2008 5:02 am

sorry, you appear to be using extension/module/card.php. So you'd add it there following the format of other view->set examples from other modules.
What is "card" supposed to do?

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by HAL 9000 » Wed Oct 15, 2008 5:29 am

I moved paypal, master and visa card images from footer to the column on the left to create space for footer text.

I tried the following in "catalog/extension/module/card.php"  and it didn't work.


locator->get('config');
$language =& $this->locator->get('language');


if ($config->get('card_status')) {
$language->load('extension/module/card.php');

$view = $this->locator->create('template');

$view->set('card', $variable);

return $view->fetch('module/card.tpl');
}
}
}
?>

New member

Posts

Joined
Thu Sep 11, 2008 8:53 pm

Post by Qphoria » Wed Oct 15, 2008 8:36 am

Ok, extensions have a few extra steps.

First are you doing this in 1.0 or 0.7.x? 1.0 really isn't ready for development and it doesn't actually support modules since daniel hasn't added that back in. So just give me the OK and I will move this to the 0.x forum.

Back to the point, and assuming 0.7.x...

Step 1. To create a new module, you will need to create the follow file structures.
Front-end files:
- catalog/extension/module/xxx.php
- catalog/language/english/extension/module/xxx.php
- catalog/template/default/module/xxx.tpl
Back-end files:
- admin/controller/module_catalog_xxx.php
- admin/extension/module/xxx.php
- admin/language/english/controller/module_catalog_xxx.php
- admin/template/default/content/module_catalog_xxx.tpl
I would clone one of the simpler existing modules like "footer", and just modify the files for the new module.

Step 2. We will start with the front-end files first.
Edit catalog/extension/module/xxx.php. This is where the main controlling code goes. all the calculations, or data is handled here.

Using footer.php file as our example, you can see the only real code that is being done here is to pass a variable from the controller to the view called: text_powered_by. This variable is set with the content that is pulled from the language file referred to by a variable there with the same name. Change this to be code for what you want to do.
locator->get('config');
$language =& $this->locator->get('language');

if ($config->get('footer_status')) {
$language->load('extension/module/footer.php');

$view = $this->locator->create('template');

$view->set('text_powered_by', $language->get('text_powered_by'));

return $view->fetch('module/footer.tpl');
}
}
}
?>
Step 3. Now that you have your code, you need to add the supporting context to the language file.
Edit catalog/language/english/extension/module/xxx.php. Everywhere you call a reference to the language file, for example: $view->set('text_powered_by', $language->get('text_powered_by'));, you need to create a matching name in the language file with the message you want:

(from: catalog/language/english/extension/module/footer.php):
$_['text_powered_by'] = 'Powered by OpenCartCopyright © '.date('Y');
Notice the language file can support full html, a great place to handle the links and style.
Save the file and close it.

Step 4. In the main extension, you needed to create a $view->set for every variable you wanted the template to be able to display. Now you need to match those corresponding variable names in the template.
Edit catalog/template/default/module/xxx.tpl.
Examining the first part of our example: $view->set('text_powered_by', $language->get('text_powered_by'));

Now the view can use the variable $text_powered_by.

(from: catalog/template/default/module/footer.tpl):
This is where the majority of your html will go, using php tags to reference the preset view variables
Make the needed changes.
Save the file and close.

Step 5. Edit catalog/template/default/layout.tpl
Follow the existing structure for the other modules.
Add the following block where you want it:
Now we have our front-end files done. But we need to add it to the admin area for enable/disable control and add it to the database.

Step 6. First you will need to add it to the database via the admin panel. This is somewhat of a mundane process, as it would be best if the code could just read the directory and find the new files (planned for a future release). Take a look at the existing footer module in the admin area under "Extensions->Module". Click the "update" button (icon looks like a notepad) and click the 'data' tab. You should see the configuration settings that look something like this:

Code: Select all

Code: footer
Directory: module
Filename: footer.php
Controller: module_catalog_footer
Using that example. Go back to the main "Extensions->Modules" menu and click the "Insert" button at the top.
- Enter the name of the module
- enter the data information using the example from above.
- Save it.

Step 7. Edit the new admin/extension/module/xxx.php file and change all places you see "footer" with the new name. Unless you have some additional settings (advanced configurations only), this file is basically generic template.
Save & close.

Step 8. Edit admin/language/english/controller/module_catalog_xxx.php
Once again, change all places that say "footer" to the new name
Save & close.

Step 9. Edit admin/template/default/content/module_catalog_xxx.tpl
And again, change all places from "footer" to the new name.
Save & close.

Step 10. Finally, go back to the "Extensions->Module" page you should be back at the main modules screen again. Click the "wrench" or "spanner" icon, and enable the module.

Now you should have a working module!
Last edited by Qphoria on Wed Oct 22, 2008 1:57 am, edited 1 time in total.

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by randomfactor » Wed Oct 15, 2008 10:25 am

Dang, Q.  Your post sure would look good in the "How to write extensions" section of the OpenCart developer's wiki...

... if there was an OpenCart developer's wiki.

New member

Posts

Joined
Mon Jul 07, 2008 1:43 am


Post by Qphoria » Wed Oct 15, 2008 11:18 am

[me=Qphoria]taps on nose..  ;D[/me]
that's in progress

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by HAL 9000 » Thu Oct 16, 2008 12:26 am

Qphoria,

Thak you for the detailed reply. Busy at work today. I will implement it today night and will let you know. I am using 0.7.x. I accidentally posted it in 1.0.. Thanks again


Bharat

New member

Posts

Joined
Thu Sep 11, 2008 8:53 pm

Post by HAL 9000 » Wed Oct 22, 2008 1:46 am

Hello Qphoria,

I tried everything you posted step by step 4 times. I had to reinstall opencart everytime as I am getting the following message.

_________________

Fatal error: Class 'Modulecard' not found in /home/handy/www/kottu/library/cart/module.php on line 18
_________________

In Step 1 -

In the front-end files list you mentioned: "- catalog/language/english/extension/module/xxx.tpl
"
. But there are not TPL files in that folder. There are only PHP files. So I copied "footer.php". file and renamed it to "card.php".

For others, I copied the appropriate footer file and renamed.

In Step 6 -

I used the following to create a module

Code: card
Directory: module
Filename: card.php
Controller: module_catalog_card

When I refreshed the page after creating the module, I got the following error message.

Fatal error: Class 'Modulecard' not found in /home/handy/www/kottu/library/cart/module.php on line 18


Step 7 -

No new file was created in "admin/extension/module/"

There was no wrench icon but there was a + sign in the extensions->modules of admin menu. When I clicked on it I got the follwoing error message.

Permission Denied!
You do not have permission to access this page, please refer to your system administrator.


Am I doing anything wrong?

New member

Posts

Joined
Thu Sep 11, 2008 8:53 pm

Post by Qphoria » Wed Oct 22, 2008 1:56 am

bharat wrote: In Step 1 -

In the front-end files list you mentioned: "- catalog/language/english/extension/module/xxx.tpl
"
. But there are not TPL files in that folder. There are only PHP files. So I copied "footer.php". file and renamed it to "card.php".

For others, I copied the appropriate footer file and renamed.
Sorry, typo. But you figured it out. (I fixed in in my post now)
bharat wrote: In Step 6 -
Step 7 -
Sorry, forgot to add that to the file structure from step 1. You should copy the
admin/extension/module/footer.php
to
admin/extension/module/xxx.php

bharat wrote: Permission Denied!
You do not have permission to access this page, please refer to your system administrator.
This problem is gone in 0.7.9 but you need to also allow access to the new files you created in the Admin->Configuration->UserGroups area for Top Administrators

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by HAL 9000 » Wed Oct 22, 2008 2:19 am

Thank you. I will try it in an hour or so.

New member

Posts

Joined
Thu Sep 11, 2008 8:53 pm

Post by HAL 9000 » Thu Oct 23, 2008 2:56 am

I am still getting the same error message:

Fatal error: Class 'Modulecard' not found in /home/handy/www/kottu/library/cart/module.php on line 18

after step 6.

Is it possible to make the module show up only in certain pages and hide in others?

New member

Posts

Joined
Thu Sep 11, 2008 8:53 pm

Post by bruce » Thu Oct 23, 2008 10:06 am

Firstly, check library\application\controller.php to make sure that the execute() function has the following line... exactly

Code: Select all

			 $controller = 'Controller' . preg_replace('/[^a-zA-Z0-9]/', NULL, $action['class']);
Secondly, check that the first line of catalog\extension\module\card.php is

Code: Select all

class ModuleCard extends Controller {
Finally, if you have a look at the suggestions I have made to implement the Featured/Specials contribution then you will see one way to control what modules are displayed from any controller.

Active Member

Posts

Joined
Wed Dec 12, 2007 2:26 pm

Post by Qphoria » Thu Oct 23, 2008 11:22 am

bruce wrote: Secondly, check that the first line of catalog\extension\module\card.php is

Code: Select all

class ModuleCard extends Controller {
Ah yea.. that would be a very important step that I missed in my tutorial..  :-\ :-X

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by perlgerl » Sat Nov 01, 2008 8:42 am

bharat - Did you solve your problems?  How?

I followed the instructions for a new module "student" and got the same result ( v0.7.8 )
- The new Student Module appears on the extensions page WITH a plus sign but WITHOUT the spanner
- When I try to install, I get the "Permission Denied!" message
- Under Admin > Configuration > Users > User Group > Top Administrator, the new module DOES NOT appear
- The rest of Administration appears to be functioning properly.

If I navigate to the shop/ I get a syntax error from catalog/extension/module/student.php.  The student.php code doesn't generate any errors in my editor.  Is that what's preventing the module from displaying for Administration? .... Or is that my next problem to solve?  :-)

Newbie

Posts

Joined
Tue Aug 05, 2008 12:37 am

Post by perlgerl » Sat Nov 01, 2008 8:28 pm

I solved my own problem.

The syntax error was not related to the problem.

The problem was caused by not creating the following file:
admin/controller/module_catalog_student.php

It looks like this step is missing from the instructions .... in the wiki!

Newbie

Posts

Joined
Tue Aug 05, 2008 12:37 am

Post by Qphoria » Sat Nov 01, 2008 10:12 pm

perlgerl wrote:
It looks like this step is missing from the instructions .... in the wiki!
Umm... it's in step 1

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am
Who is online

Users browsing this forum: No registered users and 73 guests