Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Creating a new content module


HubertZ

Recommended Posts

hi,

 

i'm using a fresh installed v2.3.4

 

Now i want to add some text (under the navbar) through a module (editable via admin)

This is what i tried:

<?php
// includes/modules/content/foo/foo.php

class foo {
    var $code;
    var $group;
    var $title;
    var $description;
    var $sort_order;
    var $enabled = false;
    
    function foo() {
	$this->code = get_class($this);
	$this->group = basename(dirname(__FILE__));
	
	$this->title = MODULE_FOO_TITLE;
	$this->description = MODULE_FOO_DESCRIPTION;
	
	if ( defined('MODULE_FOO_STATUS') ) {
	    $this->sort_order = MODULE_FOO_SORT_ORDER;
	    $this->enabled = (MODULE_FOO_STATUS == 'True');
	}
    }
    
    function prepare() {
	global $oscTemplate;
	/* whats this for */
    }
    
    function build() {
	global $oscTemplate;
	
	$output = 'where am i built: '. MODULE_FOO_TEXT;
	
	$oscTemplate->addContent($output, $this->group);
    }
    
    function execute() {
	global  $oscTemplate;
	$output = 'where am i executed: '. MODULE_FOO_TEXT;
	$oscTemplate->addBlock($output, $this->group);
    }
    
    function isEnabled() {
	return $this->enabled;
    }
    
    function check() {
	return defined('MODULE_FOO_STATUS');
    }
    
    function install() {
	tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('foo Module', 'MODULE_FOO_STATUS', 'True', 'Enable foo?', '6', '', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
	tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_FOO_SORT_ORDER', '1500', 'Sort order halt.', '6', '', now())");
	tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Text', 'MODULE_FOO_TEXT', 'buy this it\'s good', 'Enter text', '6', '8', now())");
    }
    
    function remove() {    
	tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
    }
    
    function keys() {
	return array('MODULE_FOO_STATUS', 'MODULE_FOO_SORT_ORDER', 'MODULE_FOO_TEXT');
    }
	    
}
?>

then

<?php
// includes/languages/english/modules/content/foo/foo.php

define('MODULE_FOO_TITLE', 'foo title');
define('MODULE_FOO_DESCRIPTION', 'foo descr');

?>

I can enable/disable this as admin in 'content, foo' edit and save text, but i don't see the text nowhere in the index.php page (source) when i reload it afterwards.

 

What am i missing?

I 'stole' that code from some example modules i downloaded, as i didn't find any docs on this topic...

 

ciao,

HubertZ

 

Link to comment
Share on other sites

@HebertZ

 

This test foo module will be called by the

$this->group = basename(dirname(__FILE__));

So depending which folder you dropped this cm into, it will be launched.   Tsimi comments above would require you to create a folder 'foo' in the content folder under modules.

 

As you want this under the navbar, it would be best suited for the header folder.

 

Also, looking at your code, I am not sure which module you copied this from; however, the functions prepare or build are not required to accomplish what you require.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...