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
Related
I'm new to moodle plugin development and am trying to create a plugin that displays a page to the admin where I can add my on php code.
In brief, what I want the plugin to do I have already achieved in a standard php file that I upload to the moodle root. From here you can call the file e.g. yourdomain.co.uk/moodlelocation/myfile.php and it will run as expected.
The problem with this is it isn't secure since anyone can load the myfile.php and in turn run the scripts on the page. It also means any one else using this script (it will be given away for free when complete) would need to FTP into their hosting and upload two php files to their moodle install.
Due to this, I thought a plugin (a very very basic plugin) may be the best solution. They could then load the page in the admin via the "site administration". e.g. site administration > Development > MyPlugin. I am assuming I could then also restrict the plugin's main page to admins only (??).
So to recap, I can create a php page that has my script all rocking and rolling BUT I need to make this into a plugin.
I did some reading and I think a "local" plugin was the easiest way to go (??).
I have managed to get the local plugin up and running using the below in local/webguides/inex.php :
<?php
// Standard config file and local library.
require_once(__DIR__ . '/../../config.php');
// Setting up the page.
$PAGE->set_context(context_system::instance());
$PAGE->set_pagelayout('standard');
$PAGE->set_title("webguides");
$PAGE->set_heading("webguides");
$PAGE->set_url(new moodle_url('/local/webguides/index.php'));
// Ouput the page header.
echo $OUTPUT->header();
echo 'MY php CODE here etc';
?>
This works fine but with two problems:
Anyone can access it via http://domain/local/webguides/index.php
There is no link to it in the site administration (so the user would need to type the URL in).
Can anyone shed any light how I would achieve the two steps above?
Thanks in advance
p.s. ideally I'd like to keep the plugin to as few files as possible so if the required code could be added to the local/webguides/index.php file it would be preferred.
You need to create a capability, then require that capability before displaying the page.
First, have a look at local/readme.txt - this gives an overview of the files needed for a local plugin.
Or read the documentation at https://docs.moodle.org/dev/Local_plugins
Also have a look at existing local plugins so you can see how they are created - https://moodle.org/plugins/?q=type:local
At a bare minimum, you need
local/webguides/db/access.php - this will have the capability
local/webguides/lang/en/local_webguides.php
local/webguides/version.php
Plus your index file
local/webguides/index.php
In the db/access.php file have something like
defined('MOODLE_INTERNAL') || die();
$capabilities = array(
'local/webguides:view' => array(
'captype' => 'read',
'contextlevel' => CONTEXT_SYSTEM,
'archetypes' => array(
),
),
);
You might also need 'riskbitmask' => RISK_XXX depending on if there are any risks in you code. Such as RISK_CONFIG, RISK_PERSONAL, etc.
In lang/en/local_webguides.php have something like
defined('MOODLE_INTERNAL') || die();
$string['pluginname'] = 'Webguides';
$string['webguides:view'] = 'Able to view webguids';
In version.php have something like
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2020051901; // The current plugin version (Date: YYYYMMDDXX)
$plugin->requires = 2015051109; // Requires this Moodle version.
$plugin->component = 'local_webguides'; // Full name of the plugin (used for diagnostics).
Replace 2015051109 with the version of Moodle you are using - this will be in version.php in the root folder.
Then in your index.php file use this near the top.
require_capability('local/webguides:view', context_system::instance());
So only users with that capability will have access to the page.
EDIT:
You can add a link via settings.php using something like
defined('MOODLE_INTERNAL') || die;
if ($hassiteconfig) {
$page = new admin_externalpage(
'local_webguides',
get_string('pluginname', 'local_webguides'),
new moodle_url('/local/webguides/index.php'),
'local/webguides:view'
);
$ADMIN->add('localplugins', $page);
}
Then in your index page ad this
require_once($CFG->libdir.'/adminlib.php');
and remove require_login() and require_capability() and replace with
admin_externalpage_setup('local_webguides');
I'm using the drupal FAQ module which sends an email to the admin including the authors username as hyperlink, defined via:
'creator' => theme('username', array('account' => user_load($node->uid), 'plain' => TRUE)),
http://cgit.drupalcode.org/faq_ask/tree/faq_ask.module?id=9f4fbb7859c8fc24977f5d67cd589685236e442d#n480
unfortunately it only links to /users/joeblock and thus missing the site url https://example.com which means it won't work in emails.
Joe Block
I already tried the module pathologic hoping it adds the site url but didn't help (perhaps because the rendered ahref includes a / infront of it).
Is it possible to modify the hyperlink just for this instance to insert the siteurl?
Update:
adding $variables['link_options']['absolute'] = true;into includes/theme.inc worked.
function theme_username($variables) {
if (isset($variables['link_path'])) {
// We have a link path, so we should generate a link using l().
// Additional classes may be added as array elements like
// $variables['link_options']['attributes']['class'][] = 'myclass';
$variables['link_options']['absolute'] = true;
$output = l($variables['name'] . $variables['extra'], $variables['link_path'], $variables['link_options']);
}
Yes, it's possible! the faq module uses the theme username. This theme is defined in includes/theme.inc function theme_username
In your custom theme you can implement the template_process_username hook and alter the $variables array.
The theme username uses the url function to create the url. This function accepts the absolute attribute to build an absolute url.
to create this function you can create a custom theme https://www.drupal.org/docs/7/theming/howto/create-a-new-custom-theme-with-css-alone and put the yourthemename_process_username function inside the template.php file of your custom theme.
Otherwise you can add the function in a custom module.
Let's do an example with a custom module (with the markus name) because is much more common to create a custom module than a custom theme.
Create the site/all/modules/custom/markus directory.
Inside this directory create the markus.module file with this content:
<?php
function markus_node_presave($node){
if( $node->type == 'faq' ){
drupal_static('markus_faq_node_save', true);
}
}
function markus_process_username( &$variables ){
if( drupal_static('markus_faq_node_save', false) ){
// alter the link_options only when you came from the ask module otherwise, without
// this if, all the username links in drupal will be absolute url.
// Actually this is not a problem but it may be overkilling
$variables['link_options']['absolute'] = true;
}
}
create the markus.info file inside the markus directory with this content:
name = markus
description = "my custom module"
core = 7.x
package = "markus"
Now from the admin menu enable your theme.
It's better to implement the markus_process_username function in a custom module and not to edit the includes/theme.inc file because in this way you can update drupal much more easly. The drupal core should never be edited :)
I've created a module for Joomla that fetches some data from a database and creates a table with it. I added JPagination to my module and I got the footer buttons to show and everything.
public function addPagination($params)
{
$count = $params->get("count");
$multiPage = $params->get("multiple_pages");
//Add controls for changing pages
if($multiPage)
{
jimport('joomla.html.pagination');
$limitStart = 0;
$pagination = new JPagination(count($this->vacanciesRows) , $limitStart, $count);
echo $pagination->getListFooter();
}
}
but when I click some of the pages (all except the first one) I'm getting error 404. I'm sure I've missed something but I have very little to none experience with Joomla. I'll include pastebins with my helper.php and my mod_xxx_xxx.php
A module can't have a pagination. It has no own URL. Only components have that. If you check the links your module creates, you'll notice that they are invalid. You can try to do Ajax magic but then you need a component providing the data.
In Joomla only components can react to incoming URLs directly.
In order to fix some 404s as reported by Webmaster tools, I need to add some custom URL rewrites (URL redirects) on a per-store basis to my multi-store Magento installation, but I am unable to do that: as soon as I select the "Custom" URL rewrite type from the top selector, a custom URL Rewrite edit form appears, but there are no stores selectable in "Store" dropdown list, and - since Store is a required field, Magento admin doesn't let me save the redirect.
Can anyone spread some light on this? My Magento version is 1.5.0.1, but if this is a bug, as I suspect, it might be present in other (even more recent) versions as well.
Thanks
This is a bug indeed. To fix this, apply the following patch or simply replace line 120 of your app/code/core/Mage/Adminhtml/Block/Urlrewrite/Edit/Form.php with these lines.
I would suggest you don't modify the "core" file directly, but create the same folder structure in app/code/local instead, copy the core file there and edit it. Files with the same path in "local" have higher priority and will be loaded instead of those in "core" by Magento, they are also more easy to spot and eventually remove, restoring default Magento functionality, if needed in future.
app/code/core/Mage/Adminhtml/Block/Urlrewrite/Edit/Form.php => app/code/local/Mage/Adminhtml/Block/Urlrewrite/Edit/Form.php
119a120,130
120: } else {
121: foreach ($stores as $i => $store) {
122: if (isset($store['value']) && $store['value']) {
123: $found = false;
124: foreach ($store['value'] as $_k => $_v) {
125: if (isset($_v['value']) && $_v['value']) {
126: array_push( $entityStores, $_v['value'] );
127: }
128: }
129: }
130: }
I have just developed my first Opencart (1.5.6) plugin using the hostjars starter files.
The Admin section is working beautifully, and all the Frontend code has been placed. However, for some reason the module is not showing the on the webpage, even though the position has been defined in the Admin.
Below is the Frontend Controller code for reference (FYI, No errors are thrown which makes me think that perhaps the Controller is not being called or something):
<?php class ControllerModulebevyspecials extends Controller {
protected function index($setting) {
//Load the language file
$this->language->load('module/bevy_specials');
//Load the models
$this->load->model('module/bevy_specials');
//Get the title from the language file
$this->data['heading_title'] = $this->language->get('heading_title');
//Retrieve Checkout Special Products
$products = $this->model_module_bevy_specials->getBevySpecials();
if(Count($products)>0){
foreach ($products as $product) {
$product_info = $this->model_catalog_product->getProduct($product['product_id']);
$this->data['title'] = $product['title'];
if (isset($product_info)) {
$this->data['products'][] = array(
'product_id' => $product_info['product_id'],
'name' => $product_info['name'],
'discount' => $product['discount']
);
}
}
}
else{
$this->data['noRecord'] = true;
}
//Choose which template to display this module with
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/bevy_specials.tpl')) {
$this->template = $this->config->get('config_template') . '/template/module/bevy_specials.tpl';
} else {
$this->template = 'default/template/module/bevy_specials.tpl';
}
//Render the page with the chosen template
$this->render();
} } ?>
Am I missing any specific code that displays the module on the webpage?
Opencart documentation is quite minimal when it comes to module development, and I've tried searching on web for a solution but couldn't find a definitive answer.
Any inputs will be greatly appreciated. Thanks in advance!
MORE INFO:
One issue found though.....in admin panel when i add 2 or more Layouts for the module (e.g added to "Column-Left" for Contact page and "Content-Top" for Account page), the Frontend then shows the following error:
Warning: Invalid argument supplied for foreach() in D:\xampp171\htdocs\opencart\catalog\controller\common\column_left.php on line 49
Issue Resolved
Since i used the hostjars start files, i had to amend the code abit and the issue got fixed.
1) In the Admin Controller of the module, i removed the section under the comment:
"//This code handles the situation where you have multiple instances of this module, for different layouts."
2) In the Admin View .tpl file, for the layout position , i had to properly format the few html tag's. For example: the <select name="my_module_<?php echo $module_row; ?>_layout_id"> was replaced with the proper format <select name="banner_module[<?php echo $module_row; ?>][layout_id]">...... This ensures that multiple Layouts can be saved in Admin control panel. (there will be 8 places in the .tpl file where this needs to be done)
3) Last but not the least, if you do Step 2 correctly, then the Layouts will be properly serialized and saved in the database's oc_settings Table (previously my layout was not being stored in serialized form).
Hope the above helps others too.
Thank you!