5

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;
Community
  • 1
  • 1
HDP
  • 3,003
  • 2
  • 28
  • 50
  • Unfortunately, in OC 2.0 this can be no longer achieved without a huge core code modification. Basically you would need to pass over a position for which the module is being instantiated to the module's constructor and then use this value in your module accordingly. – shadyyx Dec 22 '14 at 14:04

2 Answers2

1

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');
HDP
  • 3,003
  • 2
  • 28
  • 50
0

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

Ramesh
  • 1,324
  • 1
  • 12
  • 18
  • Thanks for answer. Please read this question. Maybe, You can clearly understand. what I want to achieve. can you possible same thing(small code) achieved in Opencart 2.0? http://stackoverflow.com/questions/23675545/when-module-enabled-in-content-left-right-panel-so-i-want-to-hide-javascript-c – HDP Dec 22 '14 at 05:02