PupStar Posted January 18, 2015 Share Posted January 18, 2015 This brief guide is for anyone who wants to make their own content module. The code below shows how to make a 'Call to Action' module as inspired by the template made by Gary http://www.template.me.uk/responsive-saul/index.php This particular call to action module displays a checkout message in the header when there are products in the shopping cart prompting the user to finish their order. Step 1. Create a file in catalog/includes/modules/content/header called cm_header_call_to_checkout.php and add the following code to it: <?php /* $Id$ osCommerce, Open Source E-Commerce Solutions http://www.oscommerce.com Copyright (c) 2014 osCommerce Released under the GNU General Public License */ class cm_header_call_to_checkout { var $code; var $group; var $title; var $description; var $sort_order; var $enabled = false; function cm_header_call_to_checkout() { $this->code = get_class($this); $this->group = basename(dirname(__FILE__)); $this->title = MODULE_CONTENT_HEADER_CALL_TO_CHECKOUT_TITLE; $this->description = MODULE_CONTENT_HEADER_CALL_TO_CHECKOUT_DESCRIPTION; if ( defined('MODULE_CONTENT_HEADER_CALL_TO_CHECKOUT_STATUS') ) { $this->sort_order = MODULE_CONTENT_HEADER_CALL_TO_CHECKOUT_SORT_ORDER; $this->enabled = (MODULE_CONTENT_HEADER_CALL_TO_CHECKOUT_STATUS == 'True'); } } function execute() { global $PHP_SELF, $cart, $currencies, $HTTP_GET_VARS, $request_type, $currency, $oscTemplate; $content_width = MODULE_CONTENT_HEADER_CALL_TO_CHECKOUT_CONTENT_WIDTH; if ($cart->count_contents() > 0) { $call_to_checkout .= '<div class="alert alert-danger text-center call_to_checkout" role="alert">' . sprintf(TEXT_CALL_TO_CHECKOUT, $cart->count_contents()) . ' ' . tep_draw_button(IMAGE_BUTTON_CALL_TO_CHECKOUT, 'fa fa-thumbs-o-up fa-lg', tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'), 'primary', NULL, 'btn-success') . '</div>'; }else{ } ob_start(); include(DIR_WS_MODULES . 'content/' . $this->group . '/templates/call_to_checkout.php'); $template = ob_get_clean(); $oscTemplate->addContent($template, $this->group); } function isEnabled() { return $this->enabled; } function check() { return defined('MODULE_CONTENT_HEADER_CALL_TO_CHECKOUT_STATUS'); } function install() { tep_db_query("insert into configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable Call to checkout Module', 'MODULE_CONTENT_HEADER_CALL_TO_CHECKOUT_STATUS', 'True', 'Do you want to enable the call to checkout Box content module?', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())"); tep_db_query("insert into configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Content Width', 'MODULE_CONTENT_HEADER_CALL_TO_CHECKOUT_CONTENT_WIDTH', '4', 'What width container should the content be shown in?', '6', '1', 'tep_cfg_select_option(array(\'12\', \'11\', \'10\', \'9\', \'8\', \'7\', \'6\', \'5\', \'4\', \'3\', \'2\', \'1\'), ', now())"); tep_db_query("insert into configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_CONTENT_HEADER_CALL_TO_CHECKOUT_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', now())"); } function remove() { tep_db_query("delete from configuration where configuration_key in ('" . implode("', '", $this->keys()) . "')"); } function keys() { return array('MODULE_CONTENT_HEADER_CALL_TO_CHECKOUT_STATUS', 'MODULE_CONTENT_HEADER_CALL_TO_CHECKOUT_CONTENT_WIDTH', 'MODULE_CONTENT_HEADER_CALL_TO_CHECKOUT_SORT_ORDER'); } } Step 2. Create a file in catalog/includes/modules/content/header/templates called call_to_checkout.php and add the following code to it: <div class="header col-sm-<?php echo $content_width; ?>"> <?php echo $call_to_checkout; ?> </div> Step 3. Create a file in catalog/includes/languages/english/modules/content/header called cm_header_call_to_checkout.php and add the following code to it: <?php /* $Id$ osCommerce, Open Source E-Commerce Solutions http://www.oscommerce.com Copyright (c) 2014 osCommerce Released under the GNU General Public License */ define('MODULE_CONTENT_HEADER_CALL_TO_CHECKOUT_TITLE', 'Call to Checkout'); define('MODULE_CONTENT_HEADER_CALL_TO_CHECKOUT_DESCRIPTION', 'Adds a call to checkout action into the Header Area of your site.'); Step 4. Add the following to catalog/includes/languages/english.php define('TEXT_CALL_TO_CHECKOUT', '<i class="fa fa-flag fa-lg"></i> You have %s item(s) in your shopping basket, click to proceed through the checkout'); Then all you need to do is go to your admin and install the module, select the width and the sort order Hopefully this will give people ideas on how to create further content modules. Mark Link to comment Share on other sites More sharing options...
♥Tsimi Posted January 19, 2015 Share Posted January 19, 2015 Very nice Mark! I would like to see a tutorial with a bit more complicate function. Something that uses a database query and javascript/jquery and php. I have a hard time to get my head around that... :wacko: Link to comment Share on other sites More sharing options...
burt Posted January 19, 2015 Share Posted January 19, 2015 Excellent @@PupStar awesome to see new code coming out in modules :) 1 small tip (not just for modules but for everywhere in osc): tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL') to tep_href_link('checkout_shipping.php', '', 'SSL') Link to comment Share on other sites More sharing options...
Dan Cole Posted January 19, 2015 Share Posted January 19, 2015 1 small tip (not just for modules but for everywhere in osc): @@burt is this because filenames.php is on the way out or for another reason? Dan Need help? See this thread and provide the information requested. Is your version of osC up to date? You'll find the latest osC community version (CE Phoenix) here. Link to comment Share on other sites More sharing options...
♥Gyakutsuki Posted January 19, 2015 Share Posted January 19, 2015 Dan, the next release, I think, delete the FILENAME constant also for your script : $call_to_checkout .= is $call_to_checkout = + Regards ----------------------------------------- Loïc Contact me by skype for business Contact me @gyakutsuki for an answer on the forum Link to comment Share on other sites More sharing options...
burt Posted January 19, 2015 Share Posted January 19, 2015 We're deprecating two files: /includes/database_tables.php /includes/filenames.php This change makes things more flexible in certain situations, less flexible in others. Overall, for ease of installing addons. It's time (for everyone) to get used to writing their links as so: tep_href_link('conditions.php') Link to comment Share on other sites More sharing options...
burt Posted January 19, 2015 Share Posted January 19, 2015 In Step 4, you could add that text to the same file as Step 3...give it a go ? I'm also wondering how this would look/react as a hook file rather than a CM file. Less flexible I think, less code also. I'll see if I can recreate it. Link to comment Share on other sites More sharing options...
♥Gyakutsuki Posted January 19, 2015 Share Posted January 19, 2015 I think the hook cannot be desactivated and cannot use also to display until checkout_shipping for example. I think also the hook can be call in module to activate and deactivate ? no ? Regards ----------------------------------------- Loïc Contact me by skype for business Contact me @gyakutsuki for an answer on the forum Link to comment Share on other sites More sharing options...
PupStar Posted January 19, 2015 Author Share Posted January 19, 2015 In Step 4, you could add that text to the same file as Step 3...give it a go ? @@burt done and done :thumbsup: Also I noticed I missed a line out of Step 3 define('IMAGE_BUTTON_CALL_TO_CHECKOUT', 'Checkout now'); Link to comment Share on other sites More sharing options...
vampirehunter Posted January 23, 2015 Share Posted January 23, 2015 Hi, ive managed to follow the steps above, but im not sure how to load a small javascript piece of code if making a module? Im coding the Bootstrap carousel into a module, and need to code the following somewhere so that it can show up on the index page footer. and editing that so that it will use the field which can be controlled from admin. <script>' . '$(\'.carousel\').carousel({ interval: ' . ( int ) MODULE_FRONT_PAGE_BANNER_ROTATOR_FADE_TIME . ' })' . "\n" . '</script>'; Link to comment Share on other sites More sharing options...
vampirehunter Posted January 24, 2015 Share Posted January 24, 2015 @@burt done and done :thumbsup: Also I noticed I missed a line out of Step 3 define('IMAGE_BUTTON_CALL_TO_CHECKOUT', 'Checkout now'); Hi, is there any advice on how to add javascript to be outputted? Im using this code as part of a module, and it doesn't seem to output anything. I understand in template bottom, there is code which will output anything sent to $footer_script, but can't get this code below to work. Not sure if im messing something up! if ($PHP_SELF == 'index.php' && $cPath == '') { // Set the Javascript to go in the header $footer_script = '<script>' . '$(\'.carousel\').carousel({ interval: ' . ( int ) MODULE_FRONT_PAGE_BANNER_ROTATOR_FADE_TIME . ' })' . "\n" . '</script>'; $oscTemplate->addBlock($footer_script, 'footer_script'); Link to comment Share on other sites More sharing options...
vampirehunter Posted January 24, 2015 Share Posted January 24, 2015 Nevermind, i got it fixed. it should be footer_scripts not footer_script. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.