简体   繁体   中英

Check module position in OpenCart 2.0

I was using following code for Check module position. So, It is working fine in OpenCart 1.5.6. When module Enabled in Content left & right panel so I want to hide javascript code in OpenCart

but, it is not working in Opencart 2.0

How can be achieved in Opencart 2.0?

in .tpl file

<?php if ($module['position'] == 'content_bottom' || $module['position'] == 'content_top') { ?>
//add your code Here
<?php } ?>

add in .php file

$this->data['module'] = $setting;

I have found simple solution. This is working like charm.

Step 1

in .tpl file. (You want to that module. featured.tpl etc...)

<?php if ($module['position'] == 'content_bottom' || $module['position'] == 'content_top') { ?>
//add your code Here
<?php } ?>

Step 2

add in .php file (You want to that module. featured.php etc...)

$data['module'] = $setting;


Step 3 (if, You are used OpenCart 2.0.0.0 version)

catalog/controller/common/{ content_top, content_bottom, content_right, content_left }.php,

Find the below code

if (isset($part[1]) && isset($setting[$part[1]])) {

and add the below code after

$setting[$part[1]]['position'] = basename(__FILE__, '.php');


Step 3 (if, You are used OpenCart 2.0.1.x. version)

catalog/controller/common/{ content_top, content_bottom, content_right, content_left }.php,

Find the below code

$setting_info = $this->model_extension_module->getModule($part[1]);

and add the below code after

$setting_info['position'] = basename(__FILE__, '.php');

OC 2.0 is a major update so lots of things working on OC 1.5.X might not work on OC 2.X

Eg OC 1.5.x we used to add layout to module now in OC 2.0 we add Modules to layout So In 1.5.x we used to find Module and it's associated positions, Now we find Positions and it's associated Modules.

Suppose you are working on \\catalog\\controller\\common\\content_top.php

After

$modules = $this->model_design_layout->getLayoutModules($layout_id, 'content_top');

Which fetches all the modules set on content_top of the particular layout

Add

$search_text = 'featured'; // name of the module you want to find
$matched_top = array_filter($modules, function($el) use ($search_text) {
        return ( strpos($el['code'], $search_text) !== false );
});

if(!empty($matched_top)){
    $data['truevalue'] = 1;
}

Now in content_top.tpl you can write script

if(isset($truevalue)){
//here goes script code
}

Similarly You can do the same for content_bottom as well

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM