Jump to content

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

Share this post


Link to post
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.


For a new install or if your store isn't mobile-friendly, get the community-supported responsive osCommerce (Phoenix).

here: https://github.com/gburton/Responsive-osCommerce/releases

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

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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


For a new install or if your store isn't mobile-friendly, get the community-supported responsive osCommerce (Phoenix).

here: https://github.com/gburton/Responsive-osCommerce/releases

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

Share this post


Link to post
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

 

Share this post


Link to post
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

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×