Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Order of modules processing


Recommended Posts

Hi all,

I am writing a system where, unfortunately, one module depends on another one being already present.

My issue concerns order in which modules are being processed in buildBlocks() function of osc_template class.

From what I see, class just reads configuration table, gets TEMPLATE_BLOCK_GROUPS value and expands it. TEMPLATE_BLOCK_GROUPS contains list of module groups built in alphabetical order. Currently, it contains something like "boxes;header_tags;mygroup". This means boxes modules will be processed first. I want mygroup ones to be processed.

At the moment my box module has something like $output .= $oscTemplate->getContent('mygroup') as my box shows dynamic content from "mygroup".  So, code breaks at this point.

I see few options and I don't like any of them:

1. Change order of modules in configuration table

2. Rename "mygroup" into something that will get it in front.

3. Complicate the code by making "mygroup" a standalone group and add additional processing just for this group. Messy.

4. I can not find a way to rewrite my code to avoid dependency. I tried few different ways.

 

Can someone think of a nicer way of getting around my problem?

Thanks,

Rudolf

Link to comment
Share on other sites

Not easy to be helpful in the abstract but the obvious answer is to put it all in the same module.

Contact me for work on updating existing stores - whether to Phoenix or the new osC when it's released.

Looking for a payment or shipping module? Maybe I've already done it.

Working on generalising bespoke solutions for Quickbooks integration, Easify integration and pay4later (DEKO) integration at 2.3.x

Link to comment
Share on other sites

@BrockleyJohn

I though of it, but having everything in same module makes things messy.

System I implemented is a multi-search facility where each search "dimension" is in its own separate configurable module. This makes it really easy to install/remove/configure modules.

But they are being displayed in one container "Refine Search" Box, which builds its dynamic content at run time.

I guess, one option is to remove my search modules from template and have my own processing outside of osc_template. This way core code will stay unchanged.

I really like how it all fitted nicely with existing design, except for order of processing. Oh, well. Back to programming.

Rudolf

Link to comment
Share on other sites

I changed my modules not to be part of template and wrote a small function that loads my modules. Made it part of my box.

Turned out simpler than I initially thought, so all is good.

Rudolf

Link to comment
Share on other sites

Sounds to me like the right approach - the template loads your container and the container loads its contents.

Contact me for work on updating existing stores - whether to Phoenix or the new osC when it's released.

Looking for a payment or shipping module? Maybe I've already done it.

Working on generalising bespoke solutions for Quickbooks integration, Easify integration and pay4later (DEKO) integration at 2.3.x

Link to comment
Share on other sites

Hello,

I needed for some of my add ons like wholesale lite that the module ("store" in that case) is loaded in first place of all modules. So I included the following script in my module which changes the order of the modules. It is placed within the "install" function below the configuration db queries.

      if ( defined('TEMPLATE_BLOCK_GROUPS') ) {
      	// If store is not the first item on the list
        if( substr( TEMPLATE_BLOCK_GROUPS, 0, 11 ) != 'store' ) {
        	// Remove store from wherever it is in the list
        	$template_block_groups = str_replace( ';store', '', TEMPLATE_BLOCK_GROUPS );
        	// And add store back onto the front of the list
        	$template_block_groups = 'store;' . $template_block_groups;
        	$sql_data_array = array( 'configuration_value' => $template_block_groups );
        	// Update the database with the fixed string
        	tep_db_perform( 'configuration', $sql_data_array, 'update', "configuration_key = 'TEMPLATE_BLOCK_GROUPS'" );
        } // if( substr
      } // end if defined TEMPLATE_BLOCK_GROUPS

 

Link to comment
Share on other sites

@raiwa

I just went through pretty much same scenario. I though about doing what you do, but this is not right.

I would suggest not to add "store" to the template list (set var $template_integration = false; in constructor if your module in admin section).

Now, it will NOT be a part of your TEMPLATE_BLOCK_GROUPS and will NOT be loaded, so you have to do it manually. (do go into database and edit TEMPLATE_BLOCK_GROUPS to remove "store" from there)

Take a look at how includes/modules/boxes/bm_products_social_bookmarks.php is implemented (execute() function) -- you can pretty much copy the code.

This way you will add all your "store" modules when you need them without playing with existing database entries.

Rudolf

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...