Post by OpenCart Addons » Fri Mar 21, 2014 12:36 am

I'm releasing this handy tool I've made which allows developers to support multiple layout selection within their modules.


How It Works

This mod makes two very simple changes. The first change is to check through all the module files for the line:

Code: Select all

$this->data['vqmod_mls'] = false;
If this line is found, then the mod automatically replaces it with:

Code: Select all

$this->data['vqmod_mls'] = true;
Next the mod does goes through every file under catalog/controller/common/ and searches for the line:

Code: Select all

$module['layout_id'] == $layout_id
If this line is found, the mod automatically replaces it with:

Code: Select all

((isset($module['layout_id']) && $module['layout_id'] == $layout_id) || (isset($module['layouts']) && in_array($layout_id, $module['layouts'])))
This is what allows OpenCart to accept an array as well as a single value when it comes to layouts. The original functionality of OpenCart is maintained so that support for extensions that do not utilize multiple layout selection will not be affected.


Developer's Guide To Use This Modification

To enable multiple layout selection in your module, follow the steps below:

1. Download the attached file package and add the VQMod file to your extension download package.

2. In your extension admin controller file (admin/controller/module/yourextension):

Find:

Code: Select all

$this->template
Add Before:

Code: Select all

$this->data['vqmod_mls'] = false;
$this->data['text_select_all'] = $this->language->get('text_select_all');
$this->data['text_unselect_all'] = $this->language->get('text_unselect_all');
3. In your extension admin template file (admin/view/template/module/yourextension):

Find:

Code: Select all

<select name="yourextension_module[<?php echo $module_row; ?>][layout_id]">
Add Before:

Code: Select all

<?php if ($vqmod_mls) { ?>
	<div class="scrollbox">		
		<?php $class = 'even'; ?>
		<?php foreach ($layouts as $layout) { ?>
			<?php $class = ($class == 'even' ? 'odd' : 'even'); ?>
			<div class="<?php echo $class; ?>">
				<?php if (!empty($data['layouts']) && in_array($layout['layout_id'], $data['layouts'])) { ?>
					<input type="checkbox" name="yourextension_module[<?php echo $module_row; ?>][layouts][]" value="<?php echo $layout['layout_id']; ?>" checked="checked" />
					<?php echo $layout['name']; ?>
				<?php } else { ?>
					<input type="checkbox" name="yourextension_module[<?php echo $module_row; ?>][layouts][]" value="<?php echo $layout['layout_id']; ?>" />
					<?php echo $layout['name']; ?>
				<?php } ?>
			</div>
		<?php } ?>
	</div>
	<a onclick="$(this).parent().find(':checkbox').attr('checked', true);"><?php echo $text_select_all; ?></a> / <a onclick="$(this).parent().find(':checkbox').attr('checked', false);"><?php echo $text_unselect_all; ?></a>
<?php } ?>
Find:

Code: Select all

<select name="yourextension_module[<?php echo $module_row; ?>][layout_id]">
Replace With:

Code: Select all

<select name="yourextension_module[<?php echo $module_row; ?>][layout_id]"<?php if ($vqmod_mls) { ?> style="display: none;"<?php } ?>>
Find:

Code: Select all

html += '<select name="yourextension_module[' + module_row + '][layout_id]">';
Add Before:

Code: Select all

<?php if ($vqmod_mls) { ?>
	html += '<div class="scrollbox">';
		<?php $class = 'even'; ?>
		<?php foreach ($layouts as $layout) { ?>
			<?php $class = ($class == 'even' ? 'odd' : 'even'); ?>
			html += '<div class="<?php echo $class; ?>"><input type="checkbox" name="yourextension_module[' + module_row + '][layouts][]" value="<?php echo $layout['layout_id']; ?>" checked="checked" /><?php echo $layout['name']; ?></div>';
		<?php } ?>
	html += '</div>';
	html += '<a onclick="$(this).parent().find(\':checkbox\').attr(\'checked\', true);"><?php echo $text_select_all; ?></a> / <a onclick="$(this).parent().find(\':checkbox\').attr(\'checked\', false);"><?php echo $text_unselect_all; ?></a>';
<?php } ?>
Find:

Code: Select all

html += '<select name="yourextension_module[' + module_row + '][layout_id]">';
Replace With:

Code: Select all

html += '<select name="yourextension_module[' + module_row + '][layout_id]"<?php if ($vqmod_mls) { ?> style="display: none;"<?php } ?>>';
3. That's it! The system will now work with multiple layout selection!

Note: The example above is generic and will need to be revised to suit your module.

Examples Of The Multiple Layout Selection Feature

<Images coming soon>

Support Request

If you're having difficulty implementing the required changes into your system, please feel free to reply to this topic and I'll do my best to walk you through the system and help you integrate this mod.

Cheers,
Joel.

Attachments

Download this package and include the VQMod file in your module download package.


Canada's Leading Expert In OpenCart Development & Certified OpenCart Development Partner Image


User avatar
Active Member

Posts

Joined
Thu Nov 24, 2011 10:51 am
Location - Canada

Post by lacilla » Mon Jun 02, 2014 10:20 pm

Hi,
your tool seems exactly what I was looking for. I have four modules on 5 layouts and it could be complicated to updated them all the time.

I tried to follow your guide but it seems not to work. I am working on local machine at the moment. Should I updated some files according to the github page? https://github.com/opencart/opencart/pull/1225/commits

Thanks

Newbie

Posts

Joined
Mon Jun 02, 2014 10:14 pm

Post by lacilla » Mon Jun 02, 2014 10:38 pm

Hi, I managed to apply the tool to a module, but I receive the following error:

mysite.com\catalog\view\theme\mytheme\development\libs\framework.php on line 559Notice: Undefined index: layout_id in mysite.com\catalog\view\theme\mytheme\development\libs\framework.php on line 559

The line 559 is the following:

Code: Select all

if ( ($module['layout_id'] == $layout_id || $module['layout_id'] == '99999' ) && in_array(trim($module['position']), $this->positions) && $module['status']) { 
In my extension panel, I see a checkbox list to select the layout, but I cannot save my selection.

Thanks

Newbie

Posts

Joined
Mon Jun 02, 2014 10:14 pm

Post by OpenCart Addons » Wed Jun 04, 2014 1:31 am

lacilla wrote:Hi, I managed to apply the tool to a module, but I receive the following error:

mysite.com\catalog\view\theme\mytheme\development\libs\framework.php on line 559Notice: Undefined index: layout_id in mysite.com\catalog\view\theme\mytheme\development\libs\framework.php on line 559

The line 559 is the following:

Code: Select all

if ( ($module['layout_id'] == $layout_id || $module['layout_id'] == '99999' ) && in_array(trim($module['position']), $this->positions) && $module['status']) { 
In my extension panel, I see a checkbox list to select the layout, but I cannot save my selection.

Thanks
Did you follow the step to maintain the layout_id field but just keep it hidden?

It looks like the file that is throwing an error is a custom controller. If you want, send me a copy of the file and I'll look at adding it to the vqmod file.

Cheers,
Joel.

Canada's Leading Expert In OpenCart Development & Certified OpenCart Development Partner Image


User avatar
Active Member

Posts

Joined
Thu Nov 24, 2011 10:51 am
Location - Canada

Post by lacilla » Fri Jun 06, 2014 11:47 pm

Hi,
I edited my files again. The error disappeared now. In the extension panel I see the menu with all of my layouts, I select the layouts, but none of them stays saved.

What happened?

Thanks

Newbie

Posts

Joined
Mon Jun 02, 2014 10:14 pm
Who is online

Users browsing this forum: No registered users and 6 guests