Opencart custom module not showing in frontend - php

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!

Related

drupal username hyperlink missing site url - ahref from user_load($node->uid)

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 :)

Problems using Joomlas JPagination class. Error 404 page not found

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.

PHP Multisite Wordpress, need 2 functions to work without breaking website

I'm completely new and not a programmer, I'm just experimenting with the functions.php file (in a child theme) to see if I can get a function to work.
My goal: I am using a multisite wordpress setup for a website on models. When admin creates a profile for each model, their name is used on SITE 1 for their unique url AND SITE 2 to say 'welcome model name'
SITE 1: public site for everyone to see
SITE 2: private models only site to view and update personal details
On SITE 1, I have a complete list of all the models on a page for the public to browse through. Each model has their own unique profile URL that contains their first and last name. E.g. http://www.domain.com/models/samantha-rebecca
On SITE 2, when the models log in to the site, I need the homepage to show 2 name uses. One is their display name using a shortcode so I can say 'Welcome Samantha Rebecca' (which I have got working using this code).
/* username in page content using [current_user] shortcode */
function custom_shortcode_func() {
ob_start();
$current_user = wp_get_current_user();
echo $current_user->display_name;
$output = ob_get_clean();
return $output;
}
add_shortcode('current_user', 'custom_shortcode_func');
The other is for a button on the same private page they can press to go straight to their 'public' profile page. This is what I need help with please.
In an ideal world, I would like to take their first and last name (all profiles are admin created only) and put a dash in between so I can use http://www.domain.com/models/[url_user] for which I did try and use the following:
/* username in url using [url_user] shortcode */
function custom_shortcode_func() {
ob_start();
$current_user = wp_get_current_user();
echo $current_user->user_firstname . '-' . $current_user->user_lastname;
$output = ob_get_clean();
return $output;
}
add_shortcode('url_user', 'custom_shortcode_func');
But I can't seem to get them to both work at the same time in the functions file without an error coming up such as this
Fatal error: Cannot redeclare custom_shortcode_func() (previously declared in /home/domain/public_html/wp-content/themes/child-theme/functions.php:47) in /home/domain/public_html/wp-content/themes/child-theme/functions.php on line 65
Please can someone help me get this to work as one efficient function. Thank you.
i got your issue is in both short code you have used same function name please change your second function name like below code.
/* username in url using [url_user] shortcode */
function custom_shortcode_func_url_username() {
ob_start();
$current_user = wp_get_current_user();
$output = $current_user->user_firstname . '-' . $current_user->user_lastname;
return $output;
}
add_shortcode('url_user', 'custom_shortcode_func_url_username');
change your second function name like above code your problem will solved. you are getting error because for both shortcode your function name is same. function name should be unique. same name multiple time is not allowed.
more about used define function name rules. More about used define functions

Ob start: Some of the data is lost

Here parts data for lost in file system/engine/controller.php.
if (file_exists(DIR_TEMPLATE . $this->template)) {
extract($this->data);
/* Here found header.tpl, media.tpl(my module),
column_left.tpl(this show my module), column_right.tpl,
language.tpl, footer.tpl */
ob_start();
/* Here found header.tpl, language.tpl, footer.tpl */
require(DIR_TEMPLATE . $this->template);
$this->output = ob_get_contents();
ob_end_clean();
}
Why might this be? I use a Opencart framework, which you can add new modules. Made module can be found in the controller/common/column_left.php
Appendix 3 hours later:
I guess that this is due to the structure of Opencart Development. I imported across this problem is raised in a page that is different from OpenCart layout structure.
Opencart front-page layout is of such
product/category = category.php file in the directory controller/product.
I have here, this kind of layout:
line/page/path = in file controller/line/page.php, this method called "path".
Is one of the more detailed information about the structure of OpenCart is a problem with that? And if because of what editing brings the problem is ignored? OpenCart original code is easy to modify vqMod board with the block when I know what should be changed.
I do not understand the question but looking at your code you probably want to achieve this:
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/account/account.tpl')) {
$this->template = $this->config->get('config_template') . '/template/account/account.tpl';
} else {
$this->template = 'default/template/account/account.tpl';
}
$this->children = array(
'common/column_left',
'common/column_right',
'common/content_top',
'common/content_bottom',
'common/footer',
'common/header'
);
$this->response->setOutput($this->render());
The first if-else is checking for custom template if present or loads the default one otherwise. $this->children part is enabling sub-templates. Last line is doing the rest - filling the template with data and rendering the output. If you are developing something new in OpenCart it is always best to look into files already there not only to find out how things work but also to follow the same coding standards.

How to display a Drupal 6.20 menu in WordPress?

Is is possible to display (via php) the main menu of a Drupal 6.20 site in a WordPress theme template file located in a subdirectory on the same domain?
Right now, I'm displaying the menu by copying the static html from the Drupal site and adding it to header.php in the WordPress template in the site located in mydomain.com/blog/. But of course that's not going to work when another menu item is added to the Drupal site, or the Drupal menu is changed in any way.
So is there a Drupal php function that will pull the menu into the WP file?
Failing that, is there a way with php to parse a Drupal page for the html of the menu (yes, this would be ugly) and display it in WP?
The first part of the challenge is to output only the menu, with as little (or none) of the surrounding HTML as possible, so you have as little work to do in parsing the HTML as possible.
The second part is to take that output from Drupal and actually display it on your WordPress site.
You could add the Drupal database as a secondary database in WordPress using the a new instance of the $wpdb object, write the query to get the right content from the tables, and format the results. That could work, but might be overkill.
An alternative workable option may be to use JSON to format the output of the primary links, using the drupal_json function in Drupal, then consume the JSON feed in Wordpress.
I'm assuming:
you have admin access to login to the Drupal site, which you'll need to create nodes, and clear the theme cache
you want to output the Primary Links menu, which 90%+ of Drupal sites use. This is probably true, but it is possible your site uses custom menus. If so, this is still possible, you'd just write slightly different code in step 3.
The steps would be:
Create a Drupal node (you can call it anything, it's just a placeholder)
Get the node id of your dummy page (ie., node/234). From the node id, create a one-off page template in your Drupal site's themes folder. It should be called page-node-xxxx.tpl.php, with xxxx being your node id
Add this code to page-node-xxxx.tpl.php:
<?php
drupal_json(menu_navigation_links(variable_get('menu_primary_links_source', 'primary-links')));
?>
This will create a JSON feed of your menu items.
Clear the theme cache of your Drupal site by visiting http://yoursite.com/admin/build/themes and visit http://yoursite.com/node/xxxx to see the raw JSON feed.
You should now be able to use a jQuery method like $.getJSON or $.ajax in your Wordpress theme to consume and display the JSON feed, or possibly use json_decode and curl to output your array as HTML.
A good thing about Drupal's drupal_json function is that it already sends the correct JSON headers, so now all you have to do is write the jQuery or PHP that does what you need.
I'm assumed you are more of a Wordpress specialist and have a working knowledge of Drupal but maybe not a lot of familiarity with its inner workings. So, sorry if it seemed too basic (or not basic enough :).
The Drupal theming engine is very modular - you may be able to make an appropriate PHP call into Drupal to get just the menu rendered, then emit that HTML as a part of your WordPress page.
g_thom's answer is very good and if you wish to create a very simple module to output the main navigation you can write something like this:
<?php
function getmenus_help($path, $arg) {
// implementing the help hook ... well, not doing anything with it just now actually
}
function getmenus_all() {
$page_content = '';
$page_content = json_encode(menu_navigation_links(variable_get('menu_primary_links_source', 'primary-links')));
// fill $page_content with the menu html
print $page_content;
return NULL;
}
function getmenus_menu() {
$items = array();
$items['getmenus'] = array(
'title' => 'Get Menus',
'page callback' => 'getmenus_all',
'access arguments' => array('access getmenus'),
'type' => MENU_CALLBACK,
);
return $items;
}
// permissions
function getmenus_perm() {
return array('access getmenus');
}
In your PHP code you can then write something like:
function primary_links() {
$primary_links = file_get_contents(SITE_URL . '/getmenus');
$primary_links = json_decode($primary_links);
$primary_links = (array)$primary_links;
$i = 0;
$last = count($primary_links);
$output = '';
foreach ($primary_links as $pm) {
$href = $pm->href;
if (strpos($pm->href, 'http://') === FALSE) {
if ($pm->href == '<front>') {
$href = SITE_URL . '/';
} else {
$href = SITE_URL . '/' . $pm->href;
}
}
$output .= '
<li>
'.$pm->title.'</li>';
$i++;
}
return $output;
}
I hope this helps!
PS: Make sure you update the module's permissions to allow anonymous users to have access to the path you set in your module - otherwise you will get a 403 Permission Denied.

Categories